Commit 0d22cb4
Raise OverflowError on out-of-range c_int/c_byte kernel arguments (#2402)
* Raise OverflowError on out-of-range c_int/c_byte kernel arguments
An out-of-range Python int passed as a c_int/c_byte kernel argument was
silently narrowed (e.g. 2**32+5 -> 5). The feeders now range-check via
PyLong_AsLongAndOverflow + an explicit 32-bit/8-bit bounds check and raise
OverflowError; feed() is declared 'except? -1' so Cython propagates the
exception instead of swallowing it. Adds a GPU regression test.
Addresses Glasswing finding V9.1; behavior reviewed and shaped by @leofang
(single code path via PyLong_AsLongAndOverflow).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* param_packer: clarify why c_int/c_byte bound to int range, not long
A reviewer asked why the manual check uses INT_MIN/INT_MAX rather than the
function's long-based overflow flag. Add a comment: the target slot is 32-bit
(8-bit for c_byte), and long is 64-bit on LP64, so overflow alone misses
2**31..2**63 -- the explicit int-range check catches those. Comment-only.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* param_packer: use PyLong_AsInt for c_int range check (backport for <3.13)
Address review feedback on #2402: replace the hand-rolled c_int bounds
check with CPython's PyLong_AsInt, which does exactly the INT_MIN/INT_MAX
range check we want and raises OverflowError itself. PyLong_AsInt only
became public in Python 3.13, so add a file-local, version-gated backport
(a copy of the CPython implementation, made `static` because this header
is compiled into every extension module that includes it).
The c_byte feeder has no CPython equivalent, so it keeps the explicit
PyLong_AsLongAndOverflow bounds check; its comment is now self-contained
rather than referencing the (now-changed) c_int feeder.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent e51fb7f commit 0d22cb4
3 files changed
Lines changed: 78 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
10 | 32 | | |
11 | 33 | | |
12 | 34 | | |
| |||
69 | 91 | | |
70 | 92 | | |
71 | 93 | | |
72 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
73 | 101 | | |
74 | 102 | | |
75 | 103 | | |
| |||
89 | 117 | | |
90 | 118 | | |
91 | 119 | | |
92 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
93 | 137 | | |
94 | 138 | | |
95 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
0 commit comments