fix(collection): guard INT64_MIN count in take/drop - #419
Open
belowzeroff wants to merge 1 commit into
Open
Conversation
take and drop turn their raw i64 count into a magnitude with `n < 0 ? -n : n`, so a count of INT64_MIN (0Nl, or the literal -9223372036854775808) hit `-INT64_MIN` — signed-integer-overflow UB (UBSan: src/ops/collection.c). It fired in every scalar-count take branch (vector, string, char, scalar, list) and in ray_drop_fn. take: reject an INT64_MIN count once, up front, before dispatching to the per-shape branches — its magnitude is unrepresentable as int64 and could never be allocated (a range error, which is what the downstream negative-capacity check already produced for the vector path, minus the UB). drop: a drop-from-end of that magnitude removes the whole collection (|n| >= len), so treat it as cut == len (empty result) — matching (drop x -N) for any N >= len. Normal positive/negative takes and drops are unchanged, and the table/dict paths recurse through these kernels. Adds regressions to collection/take.rfl (all take shapes) and collection/drop_cut_rotate_cross.rfl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tests