Skip to content

Compare hex checksums case-insensitively in Download._check_hash - #1048

Open
karthikchundi-commits wants to merge 1 commit into
mlcommons:mainfrom
karthikchundi-commits:fix/case-insensitive-hex-hash-comparison
Open

karthikchundi-commits wants to merge 1 commit into
mlcommons:mainfrom
karthikchundi-commits:fix/case-insensitive-hex-hash-comparison

Conversation

@karthikchundi-commits

Copy link
Copy Markdown

What

Download._check_hash compares a downloaded file's SHA-256/MD5 hex digest against the sha256/md5 value in the Croissant JSON-LD using a plain ==. hashlib's hexdigest() is always lowercase, but hex-encoded checksums are conventionally treated as case-insensitive by essentially every checksum tool (many emit uppercase, e.g. Windows' Get-FileHash). A dataset published with an uppercase hex checksum currently makes a correct, fully-intact download fail with a spurious "Hash of downloaded file ... is not identical with the reference" error.

Fix

Lowercase only the hex comparison. The base64 fallback comparison right below it is intentionally left untouched - base64 is genuinely case-sensitive (upper/lowercase letters encode different values), so normalizing case there would risk silently accepting a corrupted file whose base64 hash happens to differ from the expected one only in letter case.

Testing

Added test_uppercase_hex_hash_does_match, using the well-known SHA-256 of empty content (the same value the existing test_sha256_hashes_do_match already uses in lowercase), uppercased, across all three CroissantVersions.

Ran the full mlcroissant/_src/operation_graph/ test suite locally: 95 passed, 1 skipped, 3 pre-existing failures - all Windows path-separator (\ vs /) comparison issues in unrelated functions (test_get_download_filepath, test_get_fullpaths, one test_apply_transforms_fn regex case), confirmed unrelated to this change by inspection; none touch _check_hash or the hash-comparison code path.

hashlib's hexdigest() is always lowercase, but the sha256/md5 field in a
Croissant JSON-LD isn't specified as case-locked, and hex-encoded
checksums are conventionally treated as case-insensitive by every common
checksum tool. A dataset published with an uppercase hex checksum
currently fails a correct, fully-intact download with a spurious
"Hash of downloaded file is not identical" error.

Lowercase only the hex comparison, not the base64 fallback below it -
base64 is genuinely case-sensitive (upper/lowercase letters encode
different values), so normalizing case there would risk silently
accepting a corrupted file whose base64 hash happens to differ from the
expected one only in letter case.

Added a regression test using the well-known SHA-256 of empty content,
published as the existing lowercase test data uppercased.

Assisted-by: AI
Signed-off-by: Karth <karthik.chundi@gmail.com>
@karthikchundi-commits
karthikchundi-commits requested a review from a team as a code owner August 26, 2026 11:37
@github-actions

Copy link
Copy Markdown

MLCommons CLA bot:
Thank you very much for your submission; we really appreciate it. Before we can accept your contribution,
we ask that you sign the MLCommons CLA (Apache 2). Please submit your GitHub ID to our onboarding form to initiate
authorization. If you are from a MLCommons member organization, we will request that you be added to the CLA.
If you are not from a member organization, we will email you a CLA to sign. For any questions, please contact
support@mlcommons.org.
0 out of 1 committers have signed the MLCommons CLA.
❌ @karthikchundi-commits
You can retrigger this bot by commenting recheck in this Pull Request

@karthikchundi-commits

Copy link
Copy Markdown
Author

recheck

This branch has not been deployed

No deployments
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.

1 participant