Skip to content

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

Open
tonghuaroot wants to merge 3 commits into
python:mainfrom
tonghuaroot:gh-152959-plistlib-key
Open

tonghuaroot wants to merge 3 commits 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.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

Comment thread Lib/test/test_plistlib.py Resolved
@tonghuaroot

Copy link
Copy Markdown
Contributor Author

Done in 321ff21: moved test_invalidkey next to test_invalidarray.

Comment thread Lib/test/test_plistlib.py Resolved
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Nov 22, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge stale Stale PR or inactive for long period of time. type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants