plistlib: a <key> outside a <dict> raises IndexError instead of a proper error
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in plistlib bei _PlistParser.end_key und vergleiche die Stack-Behandlung mit add_object. Reproduziere den -Fall auf oberster Ebene mit plistlib.loads und überprüfe anschließend, dass eine fehlerhafte XML-Plist-Eingabe statt IndexError ValueError auslöst; die verknüpften PRs gh-152960 und gh-152970 zeigen, dass die Arbeit bereits im Gange ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100