fix: handle 64-bit byte counts in MD5Update for inputs >= 4 GiB#28
Draft
fix: handle 64-bit byte counts in MD5Update for inputs >= 4 GiB#28
Conversation
The 32-bit byte counter (bytes_low/bytes_high) in MD5Update was not
correctly updated when STRLEN (len) exceeded 2^32. The old code:
ctx->bytes_low += len;
if (ctx->bytes_low < len)
ctx->bytes_high++;
On 64-bit systems, when len > 2^32, the implicit truncation of len to
U32 caused the carry detection to fail, producing incorrect digests
for inputs of 8 GiB or more.
The fix explicitly casts len to U32 for the low-word addition, detects
carry by comparing against the previous value of bytes_low, and adds
the high 32 bits of len to bytes_high when STRLEN is wider than 32 bits.
Fixes #6
(migrated from rt.cpan.org #123185)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Docker Hub has removed perl:5.8 through perl:5.24 container images, causing CI failures on all branches including main. Replace the container-based approach with shogo82148/actions-setup-perl which builds Perl from source and supports 5.8+. Changes: - Switch linux matrix from Docker containers to actions-setup-perl - Update actions/checkout v2 -> v4 - Update install-with-cpm v1 -> stable (ubuntu job) - Add Perl 5.34, 5.36, 5.38, 5.40 to test matrix - Drop Perl 5.8 (22 years old, minimal practical value) - Add Windows CI job (Strawberry Perl via actions-setup-perl) - Add macOS CI job (system perl, no container) - Limit AUTHOR_TESTING/RELEASE_TESTING to ubuntu job only Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incorrect MD5 digests for inputs >= 4 GiB on 64-bit systems. The 32-bit byte counter in
MD5Updatefailed to properly detect carry whenSTRLEN(which is 64-bit on 64-bit systems) exceeded 2^32, causing the message length encoded in the MD5 padding to be wrong.Fixes #6
Changes
MD5Update()inMD5.xsto correctly handle the 64-bit to 32-bit truncation oflenwhen updatingbytes_low/bytes_highcountert/large.tregression test that verifies byte counter correctness across the 4 GiB boundary (without requiring multi-GiB memory allocation)MD5.xsint/files.tTest plan
t/large.ttest verifies byte counter tracks correctly across the 4 GiB boundary usingcontext()to set the counter near the boundaryprove -b t/— 319 tests)Generated by Kōan /fix
Quality Report
Changes: 3 files changed, 94 insertions(+), 4 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline