Skip to content

gh-152959: Raise ValueError for a <key> outside a <dict> in plistlib#152960

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-152959-plistlib-key
Open

gh-152959: Raise ValueError for a <key> outside a <dict> in plistlib#152960
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-152959-plistlib-key

Conversation

@tonghuaroot

Copy link
Copy Markdown
Contributor

_PlistParser.end_key in Lib/plistlib.py evaluated self.stack[-1] before
checking whether the stack was empty, so a <key> element outside a <dict>
(for example at the document root) leaked an IndexError from
plistlib.loads instead of a ValueError. The guard now short-circuits on an
empty stack, raising ValueError consistently with the sibling <integer>
and <real> elements (which go through add_object, already guarded). The
binary plist format decodes with struct.unpack and is unaffected.

…stlib

_PlistParser.end_key evaluated self.stack[-1] before checking whether the
stack was empty, so a <key> element outside a <dict> (for example at the
document root) leaked an IndexError instead of a ValueError. Guard the
empty-stack case, matching the sibling add_object handler. The binary plist
format does not use this path and is unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant