Skip to content

fix: digest() drops final hash character when FNV tail value is zero - #37

Merged
glaslos merged 1 commit into
glaslos:mainfrom
utkonos:issue23
Apr 6, 2026
Merged

fix: digest() drops final hash character when FNV tail value is zero#37
glaslos merged 1 commit into
glaslos:mainfrom
utkonos:issue23

Conversation

@utkonos

@utkonos utkonos commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

The tail1/tail2 values in digest() were checked with != 0 to determine if they held valid data. However, 0 is a valid FNV hash output that maps to b64[0]='A'. The C reference implementation stores b64[h] in its digest array and checks != '\0', which always passes for valid hash values.

Added hasTail1/hasTail2 boolean flags to explicitly track whether tail values were set during a trigger at full digest capacity.

Validated against the C reference (ssdeep-project/ssdeep) on 103,001 test files with zero mismatches. The unpatched code produces 75 mismatches, all following the same pattern: a trailing 'A' (b64[0]) dropped from the first hash part.

Fixes #23

The tail1/tail2 values in digest() were checked with != 0 to determine
if they held valid data. However, 0 is a valid FNV hash output that
maps to b64[0]='A'. The C reference implementation stores b64[h] in
its digest array and checks != '\0', which always passes for valid
hash values.

Added hasTail1/hasTail2 boolean flags to explicitly track whether
tail values were set during a trigger at full digest capacity.

Validated against the C reference (ssdeep-project/ssdeep) on 103,001
test files with zero mismatches. The unpatched code produces 75
mismatches, all following the same pattern: a trailing 'A' (b64[0])
dropped from the first hash part.

Fixes glaslos#28
@glaslos

glaslos commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Awesome! Thank you for fixing this issue 💪

@glaslos
glaslos merged commit 54c150e into glaslos:main Apr 6, 2026
1 check 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.

Incorrect Hash Outputted on Certain Files

2 participants