Fix baseline bugs in FstHeader initialization, fuzzy search bounds, and string_view compatibility#16
Merged
Merged
Conversation
…nd string_view compatibility This commit resolves three critical bugs in the original codebase: 1. Header Mismatch: Initialized 'need_output' and 'need_state_output' in the FstHeader constructor before calling 'char_index_size()'. Previously, an uninitialized boolean caused the compiler to write a 32-byte char_index_table, while the matcher read 8 bytes due to correct flag parsing, leading to a 24-byte alignment mismatch and search failure for mapped FSTs. 2. Out-of-bounds Fuzzy Search: Added bounds checking in 'cost_insert', 'cost_delete', and 'common_string' to prevent 'std::string_view' from accessing the null terminator out of bounds, which previously triggered fatal assertions during SpellcheckTest. 3. Zero-Copy Compilation: Updated 'get_prefix_length' and 'get_common_prefix_length' to accept 'std::string_view' instead of 'const std::string&', allowing 'fst::compile' to process vectors of zero-copy string views without compilation errors.
Owner
|
@agreppin thanks for fixing bugs to make this library more robust! |
yhirose
added a commit
that referenced
this pull request
Jun 9, 2026
- EditDistanceTest.Visits_sibling_arc_after_dead_end: covers the depth-first visit early-break bug fixed in #15; minimal repro is {"rangy","rani"} with query "ani" at max_edits=1, where the buggy code returned 0 results. - MapTest.Large_output_value_round_trip: covers the vb_decode_value_reverse cast bug fixed in #15; an output value >2^28 was corrupted without the static_cast to the target type before shifting. - hardened CI job: adds a Debug build with -D_GLIBCXX_ASSERTIONS and -D_LIBCPP_HARDENING_MODE=DEBUG on ubuntu and macos. This turns the string_view out-of-bounds reads in cost_insert/cost_delete/common_string (fixed in #16) into hard test failures; they silently pass in Release builds and even under ASan/UBSan.
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.
This commit resolves three critical bugs in the original codebase: