Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct the unsoundness slice range of arr.min/max #15654

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/polars-ops/src/chunked_array/array/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ where
(0..values.len())
.step_by(width)
.map(|start| {
let sliced = unsafe { values.clone().sliced_unchecked(start, start + width) };
// SAFETY: This value array from a FixedSizeListArray,
// we can ensure that `start + width` will not out out range
let sliced = unsafe { values.clone().sliced_unchecked(start, width) };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of scary 😨 We didn't find it until today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ai.. :/

arr_agg(&sliced)
})
.collect_arr()
Expand Down
4 changes: 4 additions & 0 deletions py-polars/tests/unit/namespaces/array/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def test_arr_min_max() -> None:
assert s.arr.max().to_list() == [2, 4]
assert s.arr.min().to_list() == [1, 3]

s_with_null = pl.Series("a", [[None, 2], None, [3, 4]], dtype=pl.Array(pl.Int64, 2))
assert s_with_null.arr.max().to_list() == [2, None, 4]
assert s_with_null.arr.min().to_list() == [2, None, 3]


def test_array_min_max_dtype_12123() -> None:
df = pl.LazyFrame(
Expand Down
Loading