[New-bugs-announce] [issue16741] `int()`, `float()`, etc think python strings are null-terminated

ganges master report at bugs.python.org
Fri Dec 21 00:37:21 CET 2012


New submission from ganges master:

I'm not sure if it's a bug or just an inconvenience, but when a string containing \x00 is passed to int/float/etc, they return a misleading exception:

    >>> int("abc")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'abc'
    >>> int("\x00abc")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: ''
    >>> float("\x00abc")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float:

I noticed the code does actually try to handle it:
http://hg.python.org/cpython/file/39803c20c9bf/Objects/intobject.c#l1066

but still, the reported error is very misleading.

----------
components: Interpreter Core
messages: 177863
nosy: gangesmaster
priority: normal
severity: normal
status: open
title: `int()`, `float()`, etc think python strings are null-terminated
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16741>
_______________________________________


More information about the New-bugs-announce mailing list