Skip to content

fix(collection): guard INT64_MIN count in take/drop - #419

Open
belowzeroff wants to merge 1 commit into
RayforceDB:devfrom
belowzeroff:fix/take-drop-int64-min-count
Open

fix(collection): guard INT64_MIN count in take/drop#419
belowzeroff wants to merge 1 commit into
RayforceDB:devfrom
belowzeroff:fix/take-drop-int64-min-count

Conversation

@belowzeroff

Copy link
Copy Markdown
Contributor

Summary

  • reject INT64_MIN scalar take counts before negating the count magnitude
  • avoid negating INT64_MIN in drop-from-end
  • add RFL regressions for take/drop edge cases

Tests

  • make test TEST_CORES=2

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant