Skip to content

fix: reject a malformed inner checksum instead of crashing - #264

Merged
ericmj merged 2 commits into
hexpm:mainfrom
charmful0x:validate-inner-checksum
Nov 26, 2026
Merged

ericmj merged 2 commits into
hexpm:mainfrom
charmful0x:validate-inner-checksum

Conversation

@charmful0x

Copy link
Copy Markdown
Contributor

hex_tarball:unpack/2 raises function_clause instead of returning {error, _} when the inner CHECKSUM holds a non-hex byte: check_inner_checksum/1 calls decode_base16/1 before validating, and unhex/1 has no catch-all clause

repro: a valid tarball with CHECKSUM = <<"zz">> crashes unpack/2 on main

Fixed by validating the CHECKSUM is 64 hex chars before decoding so a bad one now return
{error, {tarball, invalid_inner_checksum}} -- valid tarballs are unaffected and i added a case to unpack_error_handling_test

note: unpack/2 is documented as {ok,_}|{error,_}, so the raise defeats error handling in consumers, e.g. mix deps.get aborts uncaught and the hex.pm server 500s on a malformed uploaded tarball, rebar3 only avoids it via a broad outer catch

@ericmj
ericmj merged commit 788cdc6 into hexpm:main Nov 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants