xml.sax expatreader: entity stack not cleaned up after error in external_entity_ref()
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece lendo ExpatParser.external_entity_ref() em Lib/xml/sax/expatreader.py e o contexto relacionado de gh-148427 / PR #148435. Considera-se concluído quando uma exceção durante a análise de entidades externas não deixa mais self._parser, self._source ou _entity_stack no estado corrompido descrito.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Pouca atividade
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 74/100