Skip to content

gh-152959: Fix IndexError when <key> appears outside <dict> in plistlib#152970

Open
Wojusensei wants to merge 2 commits into
python:mainfrom
Wojusensei:main
Open

gh-152959: Fix IndexError when <key> appears outside <dict> in plistlib#152970
Wojusensei wants to merge 2 commits into
python:mainfrom
Wojusensei:main

Conversation

@Wojusensei

@Wojusensei Wojusensei commented Jul 3, 2026

Copy link
Copy Markdown

Closes #152959

when parsing an XML plist file, if a <key> element appears outside of a <dict> container, the parser currently raises an IndexError because the stack is empty. This error is confusing and doesn't help users understand the real issue

this pr adds a check at the start of end_key() to verify that the stack is not empty. if it is empty, we raise InvalidFileException with a clear message that includes the line number, so users immediately know the plist file is malformed

4 example the following invalid plist now produces a meaningful error instead of an IndexError:

foo bar

@bedevere-app

bedevere-app Bot commented Jul 3, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@Wojusensei Wojusensei changed the title bpo-152959: Fix IndexError when <key> appears outside <dict> in plistlib gh-152959: Fix IndexError when <key> appears outside <dict> in plistlib Jul 3, 2026
@Wojusensei

Copy link
Copy Markdown
Author

can someone plz add the skip news label?
this is a small bug fix that doesnt need a separate NEWS entry :)

@bedevere-app

bedevere-app Bot commented Jul 4, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

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.

plistlib: a <key> outside a <dict> raises IndexError instead of a proper error

1 participant