xml.sax expatreader: entity stack not cleaned up after error in external_entity_ref()
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Follow-up from gh-148427 / PR #148435.
In ExpatParser.external_entity_ref() (Lib/xml/sax/expatreader.py), when an exception occurs during external entity parsing, the _entity_stack cleanup (restoring self._parser and self._source) is skipped because except Exception: return 0 exits the method before reaching lines 430–431:
try:
xmlreader.IncrementalParser.parse(self, source)
except Exception:
return 0 # exits here, cleanup below never runs
(self._parser, self._source) = self._entity_stack[-1] # skipped
del self._entity_stack[-1] # skipped
return 1
After an error, self._parser still points to the sub-parser for the external entity, self._source points to the entity's input source, and the original parser/source pair is stuck in _entity_stack.
In practice this probably doesn't matter much since the parser is usually abandoned after a SAXParseException, but it's still a state corruption if someone tries to reuse the parser or inspect its state after catching the exception.
A finally clause would fix this, but that was intentionally kept out of gh-148427 to keep the scope minimal.
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 damit, ExpatParser.external_entity_ref() in Lib/xml/sax/expatreader.py sowie den zugehörigen Kontext von gh-148427 / PR #148435 zu lesen. Als erledigt gilt die Aufgabe, wenn eine Ausnahme während der Verarbeitung externer Entitäten nicht mehr dazu führt, dass self._parser, self._source oder _entity_stack in dem beschriebenen beschädigten Zustand verbleiben.
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
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 74/100