plistlib leaks ExpatError/LookupError instead of InvalidFileException for malformed XML
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Bug description:
plistlib.load()/loads() is documented to raise plistlib.InvalidFileException when a file cannot be parsed:
The parser raises
InvalidFileExceptionwhen 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 rawLookupError. This is what CIFuzz found in gh-152211 (LookupError: unknown encoding: Latin-5_________________________); the well-formedness case above is a second, broader instance of the same missing-translation bug.
>>> import plistlib
>>> plistlib.loads(b"<plist><foo></bar></plist>")
Traceback (most recent call last):
...
xml.parsers.expat.ExpatError: mismatched tag: line 1, column 14
>>> plistlib.loads(b'<?xml version="1.0" encoding="BogusEncoding"?><plist></plist>')
Traceback (most recent call last):
...
LookupError: unknown encoding: BogusEncoding
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).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-155398
- gh-156177
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par plistlib._PlistParser.parse, qui est appelé par plistlib.load() et loads() et charge les deux exemples de XML malformé de l’issue. Confirmez que le XML malformé et les encodages inconnus sont convertis en plistlib.InvalidFileException, puis vérifiez que le comportement existant face aux entrées malformées reste intact.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 25/100