Skip to content

Stop a short imported hash crashing every Search - #153

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/151-short-hash
Sep 26, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/151-short-hash

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #151

Summary

Search printed desc.Hash[..12], and Import only rejected empty hashes. Once an entry with a hash like "abc123" was imported, every search that matched it threw ArgumentOutOfRangeException, and the only way out was editing the settings file by hand.

  • ImageHasher.IsValidHash accepts only 64 hex characters, the SHA-256 form ComputeHash produces.
  • Import.MergeEntries skips invalid-hash entries, counts them as skipped, and names each one on the console.
  • Search prints ImageHasher.ShortHash(hash), which never slices past the end. Entries already stored therefore stop crashing too.
  • MergeEntries is now internal so it can be tested.

Test

New SearchTests:

  • SearchPrintsEntryWhoseHashIsShorterThanTwelveCharacters runs Search over a stored abc123 entry.
  • MergeEntriesSkipsEntriesWhoseHashIsNotSha256Hex checks that a short hash and a non-hex hash are skipped and a valid one is imported.
  • IsValidHashAcceptsOnlySha256HexStrings covers the validator's boundaries.

With the Search and Import changes reverted, the first two tests fail (one with the reported ArgumentOutOfRangeException). With the changes, the full suite passes 40/40.

🤖 Generated with Claude Code

https://claude.ai/code/session_0113g7mUxeizhTrH6na279Ez


Generated by Claude Code

Search printed desc.Hash[..12], and Import only rejected empty hashes, so an
imported entry with a hash like "abc123" made every matching search throw
ArgumentOutOfRangeException until the settings file was edited by hand.

Import now skips any entry whose hash isn't 64 hex characters and says which
one it skipped, and Search truncates the hash defensively for entries already
stored.

Fixes #151

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0113g7mUxeizhTrH6na279Ez
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 0421d99 into main Sep 26, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/151-short-hash branch September 26, 2026 09:54
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.

Search crashes with ArgumentOutOfRangeException on any imported entry whose hash is shorter than 12 characters

2 participants