Skip to content

Commit

Permalink
Fix starts_with out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnherfst committed Nov 26, 2024
1 parent d9ea1d8 commit 68d3dcd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/polars-ops/src/chunked_array/strings/starts_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub(crate) fn starts_with_str(view: View, prefix: &str, buffers: &[Buffer<u8>])
} else {
let starts = view
.prefix
.to_le_bytes()
.starts_with(prefix.as_bytes().slice_unchecked(0..4));
.to_ne_bytes()
.starts_with(prefix.as_bytes().slice_unchecked(0..4.min(prefix.len())));
if starts {
return view
.get_slice_unchecked(buffers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ def _named_groups_builder(pattern: str, groups: dict[str, str]) -> str:
def test_starts_ends_with() -> None:
df = pl.DataFrame(
{
"a": ["hamburger", "nuts", "lollypop", None],
"a": ["hamburger_with_tomatoes", "nuts", "lollypop", None],
"sub": ["ham", "ts", None, "anything"],
}
)
Expand Down

0 comments on commit 68d3dcd

Please sign in to comment.