fix: sizeof(pointer) bug in addfile and UB in context() shifts#33
Draft
fix: sizeof(pointer) bug in addfile and UB in context() shifts#33
Conversation
Two bugs fixed in MD5.xs: 1. addfile() used sizeof(buffer) for PerlIO_read length, but when USE_HEAP_INSTEAD_OF_STACK is defined, buffer is a pointer — so sizeof gives 4 or 8 instead of 4096, degrading read performance ~500-1000x. Replaced with a BUFFER_SIZE constant. 2. context() restore used bare byte shifts like buf[3]<<24 without casting to U32 first. When the byte has bit 7 set, this shifts into the sign bit of a signed int — undefined behavior per C standard. Added (U32) casts to match the existing s2u() macro pattern used elsewhere in the file. 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.
What
Fixes two latent bugs in MD5.xs — a sizeof misuse and undefined behavior in byte shifts.
Why
addfile()usessizeof(buffer)for the read loop length. WhenUSE_HEAP_INSTEAD_OF_STACKis defined,bufferis a pointer, sosizeofyields 4 or 8 instead of 4096 — the read loop would degrade to reading a few bytes at a time.context()restore reconstructs U32 state values with bare shifts likebuf[3]<<24. Theunsigned charpromotes to signedint, so when bit 7 is set, this shifts into the sign bit — undefined behavior per C standard. Thes2u()macro on line 111 already handles this correctly with(U32)casts.How
BUFFER_SIZEconstant (4096) used in both the stack array declaration and the heap allocation + read call.(U32)casts to all byte shifts incontext()restore, matching the existings2u()pattern.Testing
All 316 tests pass. Updated hardcoded MD5 hash in
t/files.t.🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 9 insertions(+), 8 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline