Issue 17353: Plistlib outputs empty data tags when deeply nested (original) (raw)

Issue17353

Created on 2013-03-04 20:33 by jfortier, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
deeply-nested-plist.py ronaldoussoren,2013-04-15 12:45
issue-17353.txt ronaldoussoren,2013-04-15 12:46 review
issue-17353-tests.txt mmilkin,2013-04-17 00:37 review
Messages (13)
msg183496 - (view) Author: Jacques Fortier (jfortier) Date: 2013-03-04 20:33
To reproduce: import plistlib print plistlib.writePlistToString([[[[[[[[[{'test': plistlib.Data('aaaaaa')}]]]]]]]]]) Compare to: print plistlib.writePlistToString([[[[[[[[{'test': Data('aaaaaa')}]]]]]]]]) It looks like the max line length calculation in the Data class is causing the output to be empty once you get nested far enough.
msg183497 - (view) Author: Jacques Fortier (jfortier) Date: 2013-03-04 20:36
My second print should have been: print plistlib.writePlistToString([[[[[[[[{'test': plistlib.Data('aaaaaa')}]]]]]]]])
msg183509 - (view) Author: Jacques Fortier (jfortier) Date: 2013-03-05 05:15
Quick source inspection suggests this is present in the latest version.
msg183525 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-03-05 13:34
We should limit the indentation to be less than the maximal line length.
msg186929 - (view) Author: Mike Milkin (mmilkin) * Date: 2013-04-14 17:07
Looks like plistlib.writePlistToString is no loger in the plistlib.
msg186941 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-14 18:06
On 3.x it's called writePlistToBytes, and it seems to have the same issue.
msg186944 - (view) Author: Mike Milkin (mmilkin) * Date: 2013-04-14 18:57
Yep you are correct. >>> plistlib.readPlistFromBytes(plistlib.writePlistToBytes([[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]])) [[[[[[[[{'test': Data(b'aaaaaa')}]]]]]]]] >>> plistlib.readPlistFromBytes(plistlib.writePlistToBytes([[[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]]])) [[[[[[[[[{'test': Data(b'')}]]]]]]]]] I presume we want to raise a ValueError if the indentation is more than the maximal line length.
msg186967 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-15 03:26
If possible it would be better to still generate a valid output, possibly by limiting the indentation or removing it after a certain point. However I don't know if there are any restrictions that should be followed while generating a plist (What happens if the line is too long? Is the indentation required?).
msg186981 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-15 12:45
I agree that plistlib shouldn't raise an exception for data that can represented as a valid plist file. I've checked that the Cocoa class for generating plist files will happily create a plist file when the data is nested 100 levels deep. In that case NSData values generate lines of 12 characters long. An unrelated issue: PlistWriter.writeValue should treat bytes instances the same as Data instances in Python 3. That would be a (small) feature enhencement, and hence can only be done for Python 3.4.
msg186982 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-15 12:46
The attach patch should fix the issue (but there needs to be a unittest as well).
msg187127 - (view) Author: Mike Milkin (mmilkin) * Date: 2013-04-17 00:37
Adding tests.
msg187153 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-17 10:45
The tests look good, thanks for writing them.
msg187629 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-23 11:50
New changeset a389700fbc74 by Ronald Oussoren in branch '2.7': Ensure that plistlib doesn't corrupt deeply nested datastructures http://hg.python.org/cpython/rev/a389700fbc74 New changeset 6a8cb4875ac6 by Ronald Oussoren in branch '3.3': Ensure that plistlib doesn't corrupt deeply nested datastructures http://hg.python.org/cpython/rev/6a8cb4875ac6 New changeset e0c0bcd60033 by Ronald Oussoren in branch 'default': (3.3->default) Ensure that plistlib doesn't corrupt deeply nested datastructures http://hg.python.org/cpython/rev/e0c0bcd60033
History
Date User Action Args
2022-04-11 14:57:42 admin set github: 61555
2013-04-23 11:51:27 ronaldoussoren set status: open -> closedresolution: fixed
2013-04-23 11:50:53 python-dev set nosy: + python-devmessages: +
2013-04-17 10:45:22 ronaldoussoren set messages: +
2013-04-17 00:37:02 mmilkin set files: + issue-17353-tests.txtmessages: +
2013-04-15 12:46:24 ronaldoussoren set files: + issue-17353.txtmessages: +
2013-04-15 12:45:19 ronaldoussoren set files: + deeply-nested-plist.pymessages: +
2013-04-15 03:26:44 ezio.melotti set messages: +
2013-04-14 18:57:31 mmilkin set messages: +
2013-04-14 18:06:12 ezio.melotti set messages: + versions: - Python 3.2
2013-04-14 17:07:13 mmilkin set nosy: + mmilkinmessages: +
2013-03-11 20:05:22 ezio.melotti set keywords: + easynosy: + ezio.melotti
2013-03-05 13:34:04 serhiy.storchaka set assignee: ronaldoussorentype: behaviorcomponents: + macOSversions: + Python 3.2, Python 3.3, - Python 3.5nosy: + serhiy.storchaka, ronaldoussorenmessages: + stage: needs patch
2013-03-05 05:15:17 jfortier set messages: + versions: + Python 3.4, Python 3.5
2013-03-04 20:36:20 jfortier set messages: +
2013-03-04 20:33:35 jfortier create