xml.sax expatreader: entity stack not cleaned up after error in external_entity_ref()
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
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.
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 lire ExpatParser.external_entity_ref() dans Lib/xml/sax/expatreader.py ainsi que le contexte associé à gh-148427 / PR #148435. C'est terminé lorsqu'une exception lors de l'analyse d'entités externes ne laisse plus self._parser, self._source ou _entity_stack dans l'état corrompu décrit.
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é
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 74/100