Skip to content

Fix baseline bugs in FstHeader initialization, fuzzy search bounds, and string_view compatibility#16

Merged
yhirose merged 1 commit into
yhirose:masterfrom
agreppin:devel
Jun 9, 2026
Merged

Fix baseline bugs in FstHeader initialization, fuzzy search bounds, and string_view compatibility#16
yhirose merged 1 commit into
yhirose:masterfrom
agreppin:devel

Conversation

@agreppin

@agreppin agreppin commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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.

…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.
@yhirose
yhirose merged commit 1a7acf6 into yhirose:master Jun 9, 2026
0 of 3 checks passed
@yhirose

yhirose commented Jun 9, 2026

Copy link
Copy Markdown
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.
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.

2 participants