Skip to content

Fix: Return no match for forward searches past the string end - #348

Merged
ashvardanian merged 2 commits into
ashvardanian:main-devfrom
grouville:fix-forward-search-bounds
Oct 24, 2026
Merged

ashvardanian merged 2 commits into
ashvardanian:main-devfrom
grouville:fix-forward-search-bounds

Conversation

@grouville

@grouville grouville commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Make forward searches return npos (no match) when their starting position is past the end of the text, as requested in #275. These inputs previously fell outside the documented contract and could reach unchecked pointer calculations.

For example, searching "abc" from position 4 now returns no match, including when the search string is empty. Searches starting exactly at the end keep their existing behavior.

Add three checks in the shared search functions, update their documentation, and extend the existing tests for empty strings, ordinary strings, and extreme starting positions.

The branch is refreshed on main-dev. A separate CI commit pins Wasmtime to v49.0.3: the installer's latest-release lookup returned an invalid version in the first refreshed run. Installation is now checked before running the WebAssembly tests.

C++11 and C++20 search tests pass with address, undefined-behavior, and leak sanitizers. The core Python suite also passes locally with memory diagnostics enabled: 10,622 passed and 51 optional checks skipped. All 62 GitHub checks pass on the refreshed main-dev branch.

@grouville
grouville force-pushed the fix-forward-search-bounds branch from 3e1a636 to a61c56c Compare October 8, 2026 09:05
@grouville grouville changed the title Fix: Return npos for forward searches beyond the view Fix: Return no match for forward searches past the string end Oct 8, 2026
@grouville
grouville changed the base branch from main to main-dev October 19, 2026 18:37
@grouville
grouville force-pushed the fix-forward-search-bounds branch from a61c56c to eb3190b Compare October 19, 2026 18:40
@ashvardanian
ashvardanian force-pushed the fix-forward-search-bounds branch from 9f0ff10 to 10aaf21 Compare October 24, 2026 22:39
A starting position past the end of a string reached unchecked pointer
arithmetic in forward searches. They now return `npos` first, including
for an empty needle, as `std::string::find` does, and the string and view
methods document that bound.
The installer's latest-release lookup produced "{" as the version, so
no runner was installed while the step still passed, and the failure
only surfaced once Cargo ran the tests. Install v49.0.3 explicitly and
check the executable right away, so a failed download fails the step.
@ashvardanian
ashvardanian force-pushed the fix-forward-search-bounds branch from 10aaf21 to 96413cf Compare October 24, 2026 22:48
@ashvardanian
ashvardanian merged commit 52af186 into ashvardanian:main-dev Oct 24, 2026
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