Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

DecodeBytes decodes in place and overwrites the caller's ciphertext (non-GCM modes)

Offen Anfängerfreundlich
#110 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
68/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv

Rechercherichtung

Beginne mit TDECFormattedCipher.DecodeBytes, wo Result := Source dazu führt, dass beide Arrays denselben Speicher teilen. Nur der cmGCM-Zweig ruft SetLength auf, daher muss die Eingabe vor Decode in allen Modi nach Result kopiert werden. Die Nebenkorrektur betrifft TestTFormat_UU.TestIsValidTypeless, wo @SrcBuf durch @SrcBuf[0] ersetzt werden sollte. Fertig ist, wenn das Eingabearray des Aufrufers nach dem Dekodieren in allen Modi unverändert ist und die Tests unter Win64 bestehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

TDECFormattedCipher.DecodeBytes overwrites the caller's input array for every mode except GCM.

Cause

DecodeBytes starts with Result := Source. For dynamic arrays this only copies the reference, so Result and Source point to the same memory. Only for cmGCM is SetLength(Result, Length(Source)) called, which creates a separate copy. For all other modes Decode(Source[0], Result[0], ...) writes the plaintext straight into the caller's array.

Effect

After Plain := Cipher.DecodeBytes(CipherText), CipherText contains the plaintext too. Code that decodes the same buffer twice, or keeps the ciphertext for later use (logging, retry, comparing), silently works on wrong data.

Repro

Cipher := TCipher_Twofish.Create;
Cipher.Mode := cmCBCx;
Cipher.Init(Key, IV, $FF);
Original := Copy(Source);
Plain := Cipher.DecodeBytes(Source);
// Source is now equal to Plain instead of Original

I came across this in the ChaCha20 speed tests on development_chacha20poly1305, which decode the same buffer once per CPU mode. Every decode after the first one failed.

Side note

TestTFormat_UU.TestIsValidTypeless fails now and then on Win64. It uses p := @SrcBuf, which points at the array variable instead of the data, so IsValid checks the bytes of a heap pointer. It should be @SrcBuf[0]. I fix that in the same PR.

Vorherrschende Sprache
HTML
Sterne
286
Forks
78
Ø Merge
1 T. 4 Std.
Gemergte PRs (30 T.)
4

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus MHumm/DelphiEncryptionCompendium

Alle Issues in MHumm/DelphiEncryptionCompendium

Ähnliche Issues

Weitere Issues zu Cryptography

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.