-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
BUG: add bounds-checking to in-place string multiply #29060
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
Changes from 2 commits
db87970
032c8cb
1903aa5
24643be
03fa929
3272c48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* Multiplication between a string and integer now raises OverflowError instead | ||
of MemoryError if the result of the multiplication would create a string that | ||
is too large to be represented. This follows Python's behavior. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,9 +137,9 @@ static int multiply_loop_core( | |
size_t newsize; | ||
int overflowed = npy_mul_with_overflow_size_t( | ||
&newsize, cursize, factor); | ||
if (overflowed) { | ||
npy_gil_error(PyExc_MemoryError, | ||
"Failed to allocate string in string multiply"); | ||
if (overflowed || newsize > PY_SSIZE_T_MAX) { | ||
npy_gil_error(PyExc_OverflowError, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, how are these things handled in free threaded Python? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think free-threading changes anything in this code path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To say another way: we could probably rename |
||
"Overflow encountered in string multiply"); | ||
goto fail; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one isn't technically an error return, but a "has overflown" return... Maybe the test should run into the overflow path, but
newlen > PY_SSIZE_T_MAX
also kicks in due to fun overflows?Overflow error or memory error is both fine to me (for this branch I would also be OK with just using the
width < newlen
path).