python / python/cpython

Guard against negative offset/length values in tarfile's GNU sparse extraction

オープン
#137,396 コメント 11 件 リアクション 0 件 担当者 2 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:
for i in range(21):
    try:
        offset = nti(buf[pos:pos + 12])
        numbytes = nti(buf[pos + 12:pos + 24])
    except ValueError:
        break
    if offset and numbytes:
        structs.append((offset, numbytes))
    pos += 24

https://github.com/python/cpython/blob/7040aa54f14676938970e10c5f74ea93cd56aa38/Lib/tarfile.py#L1441

  • There is no check that offset or numbytes are non-negative.
  • The check if offset and numbytes: only skips zero, not negative numbers.
validation should be added:
if offset >= 0 and numbytes >= 0:
    structs.append((offset, numbytes))
  • This will prevent the addition of invalid sparse mappings, mitigating the risk.
CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs
  • gh-137805
  • gh-138726

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。