Skip to content

Fix minor UB flagged by miri#215

Open
Shnatsel wants to merge 2 commits into
BurntSushi:masterfrom
Shnatsel:pair-sse2-ub
Open

Fix minor UB flagged by miri#215
Shnatsel wants to merge 2 commits into
BurntSushi:masterfrom
Shnatsel:pair-sse2-ub

Conversation

@Shnatsel
Copy link
Copy Markdown

@Shnatsel Shnatsel commented May 1, 2026

Fixed UB in the generic packed-pair finder when the safe Finder::find API is called with a search-time needle longer than the haystack.

Although callers are documented to pass the same needle used at construction time, this is still a safe API. A mismatched longer needle could make find_in_chunk evaluate end.sub(needle.len()), creating a pointer before the start of the haystack allocation. That pointer was only used for comparison, not dereferenced, so ASan does not catch it, but Miri reports it as UB.

The fix checks the remaining byte length from the candidate pointer to end before forming any pointer derived from end. If the search-time needle cannot fit, the function now returns None without invalid pointer arithmetic. This is verified with a Miri regression test.

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.

1 participant