classification
Title: bytearray.__mod__() truncates on first \x00
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: ethan.furman, freakboy3742, python-dev, sanjioh, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2016-12-26 09:52 by sanjioh, last changed 2016-12-28 07:59 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
bytearray_format_nul.patch serhiy.storchaka, 2016-12-26 10:31 review
Messages (4)
msg284018 - (view) Author: Fabio Sangiovanni (sanjioh) * Date: 2016-12-26 09:52
Originally posted by Russell Keith-Magee on Twitter:
https://twitter.com/freakboy3742/status/812609675283681280

Reproduced successfully on Python 3.5.2

>>> x = bytearray(1)
>>> y = {}
>>> x % y
Python3.5: bytearray(b'')
Python3.6: bytearray(b'\x00')

also:
>>> bytearray([0,1]) % {} # same with [], (), range(42)
bytearray(b'')
>>> bytearray([1,0]) % {}
bytearray(b'\x01')
msg284020 - (view) Author: Russell Keith-Magee (freakboy3742) * Date: 2016-12-26 10:00
Since I was named dropped; it's worth pointing out that this has evidently been fixed - intentionally or otherwise - in 3.6.

It wasn't an issue in 3.4 and earlier because __mod__ wasn't implemented for bytestrings.
msg284021 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-26 10:31
Indeed, there is an inconsistency between bytes and bytearray in 3.5:

>>> b'a\0b' % ()
b'a\x00b'
>>> bytearray(b'a\0b') % ()
bytearray(b'a')

It was unintentionally fixed in issue25399.

Proposed patch fixes the issue.
msg284160 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-28 07:57
New changeset 277b36596a54 by Serhiy Storchaka in branch '3.5':
Issue #29073: bytearray formatting no longer truncates on first null byte.
https://hg.python.org/cpython/rev/277b36596a54

New changeset 9b77e3a586b0 by Serhiy Storchaka in branch '3.6':
Issue #29073: Added a test for bytearray formatting with null byte.
https://hg.python.org/cpython/rev/9b77e3a586b0

New changeset 82bfdf599e24 by Serhiy Storchaka in branch 'default':
Issue #29073: Added a test for bytearray formatting with null byte.
https://hg.python.org/cpython/rev/82bfdf599e24
History
Date User Action Args
2016-12-28 07:59:58serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-12-28 07:57:29python-devsetnosy: + python-dev
messages: + msg284160
2016-12-28 07:47:17serhiy.storchakasetassignee: serhiy.storchaka
2016-12-26 10:31:23serhiy.storchakasetfiles: + bytearray_format_nul.patch

nosy: + vstinner, ethan.furman, serhiy.storchaka
messages: + msg284021

keywords: + patch
stage: patch review
2016-12-26 10:00:29freakboy3742setnosy: + freakboy3742
messages: + msg284020
2016-12-26 09:52:44sanjiohcreate