Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#110 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva

Direzione di ricerca

Inizia da TDECFormattedCipher.DecodeBytes, dove Result := Source fa sì che entrambi gli array condividano la memoria. Solo il ramo cmGCM chiama SetLength, quindi copia l'input in Result prima di Decode per tutte le modalità. La correzione collaterale riguarda TestTFormat_UU.TestIsValidTypeless, dove @SrcBuf deve diventare @SrcBuf[0]. È completata quando l'array di input del chiamante resta invariato dopo la decodifica in tutte le modalità e i test passano su Win64.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
HTML
Stelle
286
Fork
78
Merge medio
1g 4h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MHumm/DelphiEncryptionCompendium

Tutte le issue di MHumm/DelphiEncryptionCompendium

Issue simili

Altre issue su Cryptography

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.