IntelPython / dpctl

Python SYCL bindings and SYCL-based Python Array API library
https://intelpython.github.io/dpctl/
Apache License 2.0
102 stars 29 forks source link

Fix undefined behavior in integer advanced indexing and indexing functions #1894

Closed ndgrigorian closed 2 weeks ago

ndgrigorian commented 2 weeks ago

This PR proposes a solution to undefined behavior that could occur in some edge cases with integer advanced indexing, where indices OOB for ssize_t (aka std::ptrdiff_t) would be cast directly to ssize_t and overflow or underflow.

As ssize_t/std::ptrdiff_t is defined to be a signed type with the same size as size_t, this means that on 32-bit systems, overflow/underflow could occur for even smaller values.

This PR also re-organizes integer_advanced_indexing.hpp by reducing namespace clutter, and moves the rewritten ClipIndex and WrapIndex structs into a separate header file. This enables them to be re-used more easily in extensions.

github-actions[bot] commented 2 weeks ago

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. :crossed_fingers:

github-actions[bot] commented 2 weeks ago

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_209 ran successfully. Passed: 894 Failed: 1 Skipped: 119

coveralls commented 2 weeks ago

Coverage Status

coverage: 87.705%. remained the same when pulling ba0bfd90bd06ee3d9de568bc415efa9f7b950743 on fix-indexing-oob-indices into dd2812f4d5d06c565a1258af94a1378ba1759c1e on master.

github-actions[bot] commented 2 weeks ago

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_212 ran successfully. Passed: 894 Failed: 1 Skipped: 119