Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ 初心者向け
#110 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発

調査の方向性

TDECFormattedCipher.DecodeBytes から始めてください。ここでは Result := Source により両方の配列がメモリを共有しています。SetLength を呼んでいるのは cmGCM の分岐だけなので、すべてのモードで Decode の前に入力を Result にコピーしてください。副次的な修正は TestTFormat_UU.TestIsValidTypeless にあり、@SrcBuf を @SrcBuf[0] に変更する必要があります。すべてのモードでデコード後も呼び出し元の入力配列が変わらず、テストが Win64 で成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
HTML
スター
286
フォーク
78
平均マージ
1日 23分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MHumm/DelphiEncryptionCompendium のほかの issue

MHumm/DelphiEncryptionCompendium の issue をすべて見る

似ている issue

Cryptography の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。