You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
plistlib.load()/loads() is documented to raise plistlib.InvalidFileException when a file cannot be parsed:
The parser raises InvalidFileException when the file cannot be parsed.
For the XML format, _PlistParser.parse() calls expat's ParserCreate().ParseFile() with no exception translation at all. Two classes of malformed input escape as the underlying exception instead, and neither is a ValueError (InvalidFileException's base class), so code that follows the documented contract and catches InvalidFileException (or even just ValueError) does not catch these:
XML that is not well-formed raises a raw xml.parsers.expat.ExpatError.
An <?xml ... ?> declaration naming an encoding Python's codec registry doesn't know raises a raw LookupError. This is what CIFuzz found in CIFuzz fails on the 3.13 and 3.14 branches: plistlib parse and LookupError #152211 (LookupError: unknown encoding: Latin-5_________________________); the well-formedness case above is a second, broader instance of the same missing-translation bug.
Expected in both cases: plistlib.InvalidFileException, as already happens for other malformed inputs (e.g. plistlib.loads(b"not a plist") correctly raises InvalidFileException).
Related: gh-152211 (the CIFuzz report for the LookupError case specifically; discussion there is about the fuzz-target/CI setup, not a fix to plistlib itself).
Bug description:
plistlib.load()/loads()is documented to raiseplistlib.InvalidFileExceptionwhen a file cannot be parsed:For the XML format,
_PlistParser.parse()callsexpat'sParserCreate().ParseFile()with no exception translation at all. Two classes of malformed input escape as the underlying exception instead, and neither is aValueError(InvalidFileException's base class), so code that follows the documented contract and catchesInvalidFileException(or even justValueError) does not catch these:xml.parsers.expat.ExpatError.<?xml ... ?>declaration naming an encoding Python's codec registry doesn't know raises a rawLookupError. This is what CIFuzz found in CIFuzz fails on the 3.13 and 3.14 branches: plistlib parse and LookupError #152211 (LookupError: unknown encoding: Latin-5_________________________); the well-formedness case above is a second, broader instance of the same missing-translation bug.Expected in both cases:
plistlib.InvalidFileException, as already happens for other malformed inputs (e.g.plistlib.loads(b"not a plist")correctly raisesInvalidFileException).Related: gh-152211 (the CIFuzz report for the
LookupErrorcase specifically; discussion there is about the fuzz-target/CI setup, not a fix toplistlibitself).CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs