-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
GH-107450: fix unexpected OverflowError in testMemoryErrorBigSource #110801
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
Conversation
FYI @lysnikolaou already opened #110768 to fix this :) |
Done, and sorry for not noticing the already open issue 😅 |
Since I can just rebase or merge main easily, we can still add the improvements. |
Ugh, the merge shows the extra changes from main on the Github UI. Next time I'll just rebase and force-push, which should be less confusing 🙃 |
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.
A couple of comments. Could you maybe merge upstream/main
here so that the diff is okay?
Lib/test/test_exceptions.py
Outdated
# the padding length needs to be more than INT_MAX, but we can't | ||
# multiple a sequence by a number that doesn't fit Py_ssize_t, | ||
# otherwise we will get an OverflowError (see PySequence_Repeat) | ||
padding = ' ' * ((ctypes.sizeof(ctypes.c_int) + 1) / 8) |
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 don't think this tests the correct thing. The buffer is way too small to overflow, probably a typo?
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.
Yep, I forgot it returns the number of bytes 😅
Lib/test/test_exceptions.py
Outdated
@unittest.skipIf(ctypes.sizeof(ctypes.c_ssize_t) > ctypes.sizeof(ctypes.c_int), | ||
"Py_ssize_t is bigger than INT_MAX, so this is unreachable") |
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.
This should probably the other way around. If sizeof(ssize_t) <= sizeof(int)
the cast is always safe, right?
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.
Yeah 🙃
Lib/test/test_exceptions.py
Outdated
@unittest.skipIf(ctypes.sizeof(ctypes.c_ssize_t) > ctypes.sizeof(ctypes.c_int), | ||
"Py_ssize_t is bigger than INT_MAX, so this is unreachable") | ||
@unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t), | ||
"INT_MAX is bigger than Py_ssize_t, so this is unreachable") | ||
@support.requires_resource('cpu') | ||
@support.bigmemtest(support._2G, memuse=1.5) | ||
def testMemoryErrorBigSource(self): |
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.
This probably needs another merge, since a _size
argument has been added. Also, it might be good to request the size of the buffer we want and then use that. Something like:
@support.bigmemtest(2 ** (ctypes.sizeof(ctypes.c_int) * 8), memuse=1)
def testMemoryErrorBigSource(self, size):
padding = ' ' * (size // 8)
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.
Done.
@lysnikolaou is everything addressed, or is there still anything missing? |
There is something wrong with the commits in this PR because there are plenty of unrelated changes |
…urce Signed-off-by: Filipe Laíns <[email protected]> add the suggested test markers Signed-off-by: Filipe Laíns <[email protected]> fix incorrect logic Signed-off-by: Filipe Laíns <[email protected]> add _size arg that got lost in the merge Signed-off-by: Filipe Laíns <[email protected]>
I think it's just the Github UI showing all the changes from the merge commits, instead of showing the difference with |
@FFY00 Thanks for taking time to work on this. Turns out the fix was a bit more complex than expacted, both for the test (which makes the buildbot fail) and for the underlying issue. I've opened #110832 which fixes both issues, so I'd suggest to close this and have you as a co-author there. Are you okay with that? |
1 similar comment
@FFY00 Thanks for taking time to work on this. Turns out the fix was a bit more complex than expacted, both for the test (which makes the buildbot fail) and for the underlying issue. I've opened #110832 which fixes both issues, so I'd suggest to close this and have you as a co-author there. Are you okay with that? |
Sounds good 👍 |
test_exceptions.ExceptionTests.testMemoryErrorBigSource
fails on certain platforms #110800