[New-bugs-announce] [issue25678] int() from a buffer reads past the buffer boundaries
report at bugs.python.org
Fri Nov 20 03:40:40 EST 2015
New submission from Sven Berkvens-Matthijsse:
Calling int() or long() on a buffer() object in Python 2.7 does not do the right thing. The following code snippet:
buf = buffer("123test", 1, 2)
does not do what I would expect (that it print "23" twice). Instead, it prints "23" once and then throws an exception:
ValueError: invalid literal for int() with base 10: '23test'
This is caused by Objects/abstract.c function int_from_string(), which gets passed the length of the string but does not actually use that information to limit what part is parsed from the string. It only uses it to check for embedded NUL bytes. The real culprit is probably PyInt_FromString() which does not take a length indicator.
components: Interpreter Core
title: int() from a buffer reads past the buffer boundaries
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce