xml.sax expatreader: entity stack not cleaned up after error in external_entity_ref()
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
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.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先閱讀 Lib/xml/sax/expatreader.py 中的 ExpatParser.external_entity_ref() 以及相關的 gh-148427 / PR #148435 上下文。當外部實體解析期間發生例外不再使 self._parser、self._source 或 _entity_stack 留在所述的損壞狀態時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 74/100