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.

classification
Title: PyUnicode_FSDecoder() accepts arbitrary iterable
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: 26800 Superseder:
Assigned To: serhiy.storchaka Nosy List: martin.panter, pitrou, pjenvey, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2016-04-14 08:06 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
PyUnicode_FSDecoder-no-list.patch serhiy.storchaka, 2016-06-11 14:38 review
PyUnicode_FSDecoder-deprecate-buffer.patch serhiy.storchaka, 2016-06-18 11:45 review
Messages (9)
msg263378 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-14 08:06
PyUnicode_FSDecoder() accepts not only str and bytes or bytes-like object, but arbitrary iterable, e.g. list.

Example:

>>> compile('', [116, 101, 115, 116], 'exec')
<code object <module> at 0xb6fb1340, file "test", line 1>

I think accepting arbitrary iterables is unintentional and weird behavior.
msg263388 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2016-04-14 09:16
I agree this doens't make sense.
msg263394 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-04-14 09:59
I agree it is a bit strange. It looks like it is a victim of PyBytes_FromObject() doing more than it says; its documentation only mentions the buffer protocol, not accepting iterables.
msg263396 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-14 10:51
PyUnicode_FSDecoder() is used in following functions in the stdlib:

compile()
symtable.symtable()
parser.compile()
parser.compilest()
zipimporter.zipimporter()
_imp.load_dynamic() (before 3.5)

This is behavior of PyUnicode_FSDecoder() from the start (issue9542). All above functions accepted only str in 3.1, thus accepting bytes object and others was new feature.

None tests are failed if reject non-str and non-bytes argument in PyUnicode_FSDecoder(). But none tests are failed even if disable support of bytes argument (there is a lack of tests for bytes path).

What should we do?

1. Add a warning when the argument neither str nor supporting the buffer protocol.

2. Drop support of non-str and not supporting the buffer protocol arguments without a warning.

3. Drop support of non-str and not supporting the buffer protocol arguments without a warning, and add a warning when the argument neither str nor bytes.

4. Drop support of non-str and non-bytes arguments without a warning.
msg263695 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2016-04-18 21:36
See issue26800 for reasoning to go with #4
msg268213 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-11 14:38
Proposed patch makes PyUnicode_FSDecoder() rejecting arbitrary iterables.
msg268795 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-18 10:56
New changeset 2e48c2c4c733 by Serhiy Storchaka in branch '3.5':
Issue #26754: PyUnicode_FSDecoder() accepted a filename argument encoded as
https://hg.python.org/cpython/rev/2e48c2c4c733

New changeset e18ac7370113 by Serhiy Storchaka in branch 'default':
Issue #26754: PyUnicode_FSDecoder() accepted a filename argument encoded as
https://hg.python.org/cpython/rev/e18ac7370113
msg268798 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-18 11:45
Following patch deprecates the support of bytes-like objects (except bytes itself) in PyUnicode_FSDecoder() for consistency with issue26800.
msg272107 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-06 20:29
New changeset 818f22f9ab02 by Serhiy Storchaka in branch 'default':
Issue #26754: Undocumented support of general bytes-like objects
https://hg.python.org/cpython/rev/818f22f9ab02
History
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70941
2016-08-14 06:30:31serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-08-06 20:29:49python-devsetmessages: + msg272107
2016-06-18 11:45:35serhiy.storchakasetfiles: + PyUnicode_FSDecoder-deprecate-buffer.patch

dependencies: + Don't accept bytearray as filenames part 2
messages: + msg268798
versions: - Python 3.5
2016-06-18 10:56:41python-devsetnosy: + python-dev
messages: + msg268795
2016-06-11 14:38:32serhiy.storchakasetfiles: + PyUnicode_FSDecoder-no-list.patch
versions: + Python 3.5
messages: + msg268213

assignee: serhiy.storchaka
keywords: + patch
stage: patch review
2016-04-18 21:36:11pjenveysetnosy: + pjenvey
messages: + msg263695
2016-04-14 10:51:13serhiy.storchakasetnosy: + vstinner
messages: + msg263396
2016-04-14 09:59:54martin.pantersetnosy: + martin.panter
messages: + msg263394
2016-04-14 09:16:05pitrousetnosy: + pitrou
messages: + msg263388
2016-04-14 08:06:10serhiy.storchakacreate