DecodeBytes decodes in place and overwrites the caller's ciphertext (non-GCM modes)
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- cryptography, testing
调研方向
从 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MHumm/DelphiEncryptionCompendium 的其他 Issue
-
CRC64 - PKI Addition可能重新可做 @MHumm 于 149 天前认领,目前没有进行中的 PR。 未关闭enhancement help wanted
MHumm/DelphiEncryptionCompendium#93 · 1 条评论 · 已指派 1 人 ·
-
Missing PUInt8Array type in the GetIt version.可能重新可做 @MHumm 于 160 天前认领,目前没有进行中的 PR。 未关闭bug delphi
MHumm/DelphiEncryptionCompendium#92 · 2 条评论 · 已指派 1 人 ·
-
Help with demo未关闭question
难度 4/5 1-2 天 新手友好度 25/100
MHumm/DelphiEncryptionCompendium#91 · 6 条评论 ·
-
Chacha20 Poly1305可能重新可做 @MHumm 于 459 天前认领,目前没有进行中的 PR。 未关闭enhancement
MHumm/DelphiEncryptionCompendium#89 · 1 条评论 · 已指派 1 人 ·
-
Confused by NEXTGEN directive可能重新可做 @MHumm 于 531 天前认领,目前没有进行中的 PR。 未关闭bug
MHumm/DelphiEncryptionCompendium#88 · 8 条评论 · 已指派 1 人 ·
查看 MHumm/DelphiEncryptionCompendium 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
btclib-org/btclib-secp256k1#1208 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
-
verify_input accepts a negative input index and raises IndexError past the end可能已有人在做 @aryansinha1908 于 1 天前认领。 未关闭good first issue
难度 2/5 1-3 小时 新手友好度 85/100
btclib-org/btclib#2672 · 1 条评论 ·
维护者通常 1 天内回复
-
Client customer-reported KeyVault needs-team-attention question Service Attention
难度 2/5 1-3 小时 新手友好度 62/100
Azure/azure-sdk-for-net#63861 · 3 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
raspberrypi/picotool#365 · 1 条评论 ·