You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser::slice and Parser::slice_from can trigger UB in safe Rust via unchecked slicing #459
Safe callers can trigger undefined behavior without unsafe:
Passing an inverted range p1..p0 where p1 > p0 (both is_char_boundary assertions still pass in debug builds, and end - start underflows in get_unchecked).
Calling parser.reset(&saved_state) to rewind the parser position and then calling parser.slice_from(later_pos).
Passing a SourcePosition obtained from another Parser with a longer input string in release builds where debug_assert! is disabled.
Replacing unsafe { self.input.get_unchecked(range.start.0..range.end.0) } with &self.input[range.start.0..range.end.0] avoids the soundness issue.
Patch welcome, though I think at least for the internal callers we want to avoid the overhead of checking codepoint boundaries etc, see d320a8e which introduced the unsafe.
I guess when I wrote that I didn't realize they were exposed via Parser (I made them pub(crate)).
Calling parser.reset(&saved_state) to rewind the parser position and then calling parser.slice_from(later_pos).
Activity
emilio commentedon Oct 17, 2026
Patch welcome, though I think at least for the internal callers we want to avoid the overhead of checking codepoint boundaries etc, see d320a8e which introduced the
unsafe.I guess when I wrote that I didn't realize they were exposed via
Parser(I made thempub(crate)).Can you elaborate why this one is an issue tho?