-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Integer overflow in case_operation #66833
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
Comments
Crashes python 3.4.1. # Objects\unicodeobject.c |
New changeset 449b1f427cc7 by Benjamin Peterson in branch '3.3': New changeset 570e70252d5d by Benjamin Peterson in branch '3.4': New changeset c2980ec10a4c by Benjamin Peterson in branch 'default': |
Benjamin, could you please first propose a patch for review instead of commiting directly your change? Especially for security related changes. + if (length > PY_SSIZE_T_MAX / 3 || PyMem_MALLOC() returns NULL if the length is larger than PY_SSIZE_T_MAX, so the overflow check doesn't look correct. The overflow check can be replaced with:
|
Other changesets related to this issue: changeset: 93071:6a91e616485a (followed by merged into 3.4 and 3.5) |
Cool, I forgot about that. On Wed, Oct 15, 2014, at 12:11, STINNER Victor wrote:
|
New changeset f963cc1f96cf by Benjamin Peterson in branch '3.3': New changeset 8195d48a5c43 by Benjamin Peterson in branch 'default': |
I think this is a place where _PyUnicodeWriter would be appropriate (of course this is different issue). |
The test should be decorated with the bigmemtest decorator. And I think that condition sys.maxsize < 2**32 would be more robust. |
It's only 341 MB. On Wed, Oct 15, 2014, at 13:29, Serhiy Storchaka wrote:
|
And this test is CPython only. It relies on specific implementation detail. After changing current implementation (which inefficiently uses memory) this test will be dropped. |
New changeset 33290d0dd946 by Benjamin Peterson in branch '3.4': New changeset ffabb674140c by Benjamin Peterson in branch 'default': |
Since the memory requirement is less than 500MB, I don't think it needs a bigmemtest decorator. |
It's 2**32//12*2 ~ 683 MiB for original string (but I'm not sure that non- |
It's Latin 1, so the chars only use one byte: >>> sys.getsizeof("üü") - sys.getsizeof("ü")
1 On Wed, Oct 15, 2014, at 13:46, Serhiy Storchaka wrote:
|
More explicitly: >>> sys.getsizeof("ü"*(2**32//12 + 1))//1024//1024
341 |
Summary of commits: |
http://buildbot.python.org/all/builders/PPC64%20AIX%203.x/builds/3466/steps/test/logs/stdio Traceback (most recent call last):
File "/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/test/test_unicode.py", line 852, in test_case_operation_overflow
self.assertRaises(OverflowError, ("�"*(2**32//12 + 1)).upper)
MemoryError |
Hum, even with the PEP-393, this string is still large: 682 MB. $ python3
Python 3.4.1 (default, Nov 3 2014, 14:38:10)
>>> sys.getsizeof("�"*(2**32//12 + 1)) / 1024.**2
682.6667385101318 I guess that Serhiy suggests to put a @bigmemtest decorator on test_case_operation_overflow(). The test expects that large_string.upper() raises immediatly an OverflowError, so I understand that a new string is not created. Hum, it's strange to have an OverflowError here. Integer overflow on memory allocation usually raises MemoryError, not OverflowError. It looks like unicodeobject.c is not consistent here. |
It's strange to have "�" here. Should be "ü". |
Oh right, I saw "�" in the bug tracker and in the buildbot output. But |
Perhaps adding bigmemtest is not worth if memory requirements are less than 1 GiB. But I would separate the creating of long tested string and the calling of case converting method, so we will sure what operation is failed. Proposed patch skips the test if can't create needed string and clean locals, so failing test_case_operation_overflow no longer causes multiple MemoryErrors in following tests. |
What is the current limit if you don't pass -M option to regrtest? In @bigimemtest, I see "maxsize = 5147". Is it a number of bytes? 5 kB of memory? IMO it's interested to use @bigmemtest if a test uses 100 MB of memory or more, but regrtest should use tests using less than 500 MB by default (or maybe less than 1 GB by default). |
bigimem tests are ran with dummy size = 5147 if dry_run = True (default) and skipped if dry_run = False. Almost always you need dry_run = False. The -M option doesn't work with less than 1 GiB. In this case likely the buildbot had enough memory at the start, but then some memory leaked in tests (perhaps mainly in tracebacks of failed tests). |
New changeset 5fae49ef94fd by Serhiy Storchaka in branch '3.4': New changeset 6b00bee218ff by Serhiy Storchaka in branch '3.5': New changeset b1c5949a3af4 by Serhiy Storchaka in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: