plistlib: a <key> outside a <dict> raises IndexError instead of a proper error
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
plistlib.loads on an XML plist whose <key> element appears outside a
<dict> raises an uncaught IndexError instead of a ValueError.
_PlistParser.end_key checks self.stack[-1] without first testing whether
the stack is empty:
def end_key(self):
if self.current_key or not isinstance(self.stack[-1], dict):
raise ValueError("unexpected key at line %d" %
self.parser.CurrentLineNumber)
self.current_key = self.get_data()
When a <key> is the document's top-level element there is no enclosing
container on the stack, so self.stack[-1] raises IndexError.
Reproducer:
>>> import plistlib
>>> plistlib.loads(b"<plist><key>x</key></plist>")
Traceback (most recent call last):
...
IndexError: list index out of range
The sibling handler add_object (used by <integer>, <string>, etc.)
already guards the empty-stack case with elif not self.stack:, so scalar
elements at the top level are handled cleanly. A <key> outside a <dict>
should likewise raise a ValueError, consistent with the other malformed
inputs the parser rejects.
The binary plist format does not use this code path and is unaffected.
Versions
3.15 (main); the same code is present on 3.13 and 3.14.
Linked PRs
- gh-152960
- gh-152970
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in plistlib, in _PlistParser.end_key, e confronta la gestione dello stack con add_object. Riproduci il caso di primo livello con plistlib.loads, quindi verifica che un input plist XML malformato sollevi ValueError anziché IndexError; le PR collegate gh-152960 e gh-152970 indicano che il lavoro è già in corso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100