classification
Title: PyBytes_FromFormatV("%c") and PyString_FromFormatV("%c") don't check for character min/max value
Type: behavior Stage: commit review
Components: Interpreter Core Versions: Python 3.4, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: haypo Nosy List: haypo, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-12-13 00:29 by haypo, last changed 2013-12-13 14:01 by haypo. This issue is now closed.

Files
File name Uploaded Description Edit
bytes_fromformat_c.patch haypo, 2013-12-13 00:30 review
bytes_fromformat_c-2.patch haypo, 2013-12-13 09:38 review
Messages (6)
msg205996 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-12-13 00:29
PyBytes_FromFormatV("%c") and PyString_FromFormatV("%c") overflow if the parameter is not in range [0; 255].

If nobody complained before, it's maybe not worth to fix the bug in Python 2.7 or 3.3.
msg205997 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-12-13 00:30
Here is a patch for Python 3.4.
msg206033 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-12-13 09:38
Updated patch for Serhiy's remark (replace ValueError with OverflowError).
msg206035 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-12-13 09:49
LGTM.
msg206062 - (view) Author: Roundup Robot (python-dev) Date: 2013-12-13 11:47
New changeset 68e0dbc492de by Victor Stinner in branch '3.3':
Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if "%c"
http://hg.python.org/cpython/rev/68e0dbc492de

New changeset 969e38b2f336 by Victor Stinner in branch 'default':
(Merge 3.3) Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if
http://hg.python.org/cpython/rev/969e38b2f336
msg206085 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-12-13 14:01
It was easy to fix the issue on Python 3.3 (there are already unit tests on PyBytes_FromFormatV).

I prefer to leave Python 2.7 with it's current behaviour because applications running on Python 2.7 may be old and might be rely on the integer overflow. PyString is the native "string" type, so it is usually used. Whereas in Python 3, bytes is not the native type. I chose to fix Python 3.3 because it's a recent release and I believe that applications are more recent and if they rely on the bug, they can more easily fixed.

(Ok, I bet that in practice, nobody cares of non-ASCII characters in PyBytes_FromFormatV() because PyBytes_FromFormatV() is probably not used in the wild.)

So let close this minor issue.
History
Date User Action Args
2013-12-13 14:01:46hayposetstatus: open -> closed
resolution: fixed
messages: + msg206085
2013-12-13 11:47:51python-devsetnosy: + python-dev
messages: + msg206062
2013-12-13 09:49:55serhiy.storchakasetversions: + Python 2.7, Python 3.3, Python 3.4
messages: + msg206035

assignee: haypo
type: behavior
stage: commit review
2013-12-13 09:38:38hayposetfiles: + bytes_fromformat_c-2.patch

messages: + msg206033
2013-12-13 00:30:45hayposetfiles: + bytes_fromformat_c.patch

nosy: + serhiy.storchaka
messages: + msg205997

keywords: + patch
2013-12-13 00:29:48haypocreate