Skip to content

Commit

Permalink
refactor(rust): Fix fencepost debug assertion in splitfields
Browse files Browse the repository at this point in the history
For some slice `v` of length `n`, it is UB to call `get_unchecked`
with a range starting at `n+1`. Previously, we asserted that `pos <=
n`, which is the requirement for `v.get_unchecked(..pos)`, but not
`v.get_unchecked(pos+1..)` which has the tighter requirement `pos <
n`.
  • Loading branch information
wence- committed Aug 28, 2024
1 parent 0cbbfcd commit 17ac49a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-io/src/csv/read/splitfields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod inner {
};

unsafe {
debug_assert!(pos <= self.v.len());
debug_assert!(pos < self.v.len());
// SAFETY:
// we are in bounds
let ret = Some((self.v.get_unchecked(..pos), needs_escaping));
Expand Down

0 comments on commit 17ac49a

Please sign in to comment.