[New-bugs-announce] [issue27870] Left shift of zero allocates memory

Alex Groce report at bugs.python.org
Fri Aug 26 15:12:23 EDT 2016


New submission from Alex Groce:

Using a random testing system to compare Python long behavior to GMP (via gmpy2), I notice that in a low-memory situation (created by allocating many large integers in both Python and GMP), a left-shift of 0 by large number of bytes:

- returns 0 via gmpy2
- causes a memory error in Python, e.g.:

...
val4 = val3 << val4
val3: 0 (GMP) 0 (Python)
val4: 1459166279268040830 (GMP) 1459166279268040830 (Python)
[operation successful via GMP]
Python(4463,0x7fff7152c300) malloc: *** mach_vm_map(size=194555503902408704) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug


Auto-generated test is attached, though probably not needed to understand the issue.  File is not minimized, since I suspect most of the code is just to choke memory, and you probably need the right memory config to replay, but it shows the basic idea.

For more info, see https://github.com/agroce/tstl/tree/master/examples/gmpy2

----------
files: leftshiftalloc.py
messages: 273717
nosy: Alex Groce
priority: normal
severity: normal
status: open
title: Left shift of zero allocates memory
type: resource usage
versions: Python 2.7
Added file: https://bugs.python.org/file44236/leftshiftalloc.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27870>
_______________________________________


More information about the New-bugs-announce mailing list