Stop a short imported hash crashing every Search - #153
Merged
Merged
Conversation
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
This was referenced Sep 26, 2026
|
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 #151
Summary
Searchprinteddesc.Hash[..12], andImportonly rejected empty hashes. Once an entry with a hash like"abc123"was imported, every search that matched it threwArgumentOutOfRangeException, and the only way out was editing the settings file by hand.ImageHasher.IsValidHashaccepts only 64 hex characters, the SHA-256 formComputeHashproduces.Import.MergeEntriesskips invalid-hash entries, counts them as skipped, and names each one on the console.SearchprintsImageHasher.ShortHash(hash), which never slices past the end. Entries already stored therefore stop crashing too.MergeEntriesis nowinternalso it can be tested.Test
New
SearchTests:SearchPrintsEntryWhoseHashIsShorterThanTwelveCharactersrunsSearchover a storedabc123entry.MergeEntriesSkipsEntriesWhoseHashIsNotSha256Hexchecks that a short hash and a non-hex hash are skipped and a valid one is imported.IsValidHashAcceptsOnlySha256HexStringscovers 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