Accumulate SHA-1 digest across all class entries for the bytecode hash (#133) - #147
Open
elharo wants to merge 4 commits into
Open
Accumulate SHA-1 digest across all class entries for the bytecode hash (#133)#147elharo wants to merge 4 commits into
elharo wants to merge 4 commits into
Conversation
Previously the digest was overwritten on each loop iteration, so the computed hash only covered the last class entry in the JAR. Two JARs with completely different class sets could therefore produce the same bytecode hash when their last-sorted class entry was identical. The digest is now updated incrementally across every class entry (in the stable, name-sorted order), so the hash covers the full class data.
ppkarwasz
reviewed
Aug 4, 2026
Co-authored-by: Piotr P. Karwasz <piotr@github.copernik.eu>
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.
Fixes #133
Problem
JarBytecodeHashAnalyzer.computeHash()overwroteresulton each loop iteration, so the computed bytecode hash only covered the last class entry in the JAR:As a result, two JARs with completely different class sets could produce the same
bytecodeHashwhenever their last-sorted class entry was identical, contradicting the analyzer's contract of detecting an exact copy of the file's class data.Fix
The SHA-1 digest is now updated incrementally across every class entry (in the stable, name-sorted order produced by
JarAnalyzer), and the final digest is hex-encoded once after the loop.Tests
Added
JarBytecodeHashAnalyzerTestwith two tests, both verified to fail before the fix and pass after:computeHashCoversAllClassEntries: the hash ofcodec.jar(14 classes) equals the SHA-1 of the concatenated class bytes.distinctClassSetsProduceDistinctHashes: two JARs sharing only the last-sorted class entry produce different hashes (they previously hashed identically).