This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vstinner Nosy List: python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2013-12-13 00:29 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
bytes_fromformat_c.patch vstinner, 2013-12-13 00:30 review
bytes_fromformat_c-2.patch vstinner, 2013-12-13 09:38 review
Messages (6)
msg205996 - (view) Author: STINNER Victor (vstinner) * (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 (vstinner) * (Python committer) Date: 2013-12-13 00:30
Here is a patch for Python 3.4.
msg206033 - (view) Author: STINNER Victor (vstinner) * (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
msg206062 - (view) Author: Roundup Robot (python-dev) (Python triager) 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"

New changeset 969e38b2f336 by Victor Stinner in branch 'default':
(Merge 3.3) Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if
msg206085 - (view) Author: STINNER Victor (vstinner) * (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.
Date User Action Args
2022-04-11 14:57:55adminsetgithub: 64168
2013-12-13 14:01:46vstinnersetstatus: 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: vstinner
type: behavior
stage: commit review
2013-12-13 09:38:38vstinnersetfiles: + bytes_fromformat_c-2.patch

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

nosy: + serhiy.storchaka
messages: + msg205997

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