plistlib: a <key> outside a <dict> raises IndexError instead of a proper error
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
plistlib の _PlistParser.end_key から始め、stack の処理を add_object と比較します。plistlib.loads でトップレベルの ケースを再現し、その後、不正な XML plist 入力が IndexError ではなく ValueError を発生させることを確認します。関連する PR gh-152960 と gh-152970 は、作業がすでに進行中であることを示しています。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100