Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#110 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

从 TDECFormattedCipher.DecodeBytes 开始,其中 Result := Source 使两个数组共享内存。只有 cmGCM 分支调用了 SetLength,因此需要在所有模式下,于 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 天 4 小时
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MHumm/DelphiEncryptionCompendium 的其他 Issue

查看 MHumm/DelphiEncryptionCompendium 的全部 Issue

相似的 Issue

更多 Cryptography Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。