B2InputStreamExcerpt casts remaining length to int, so parts over 2 GiB fail to read

オープン 初心者向け
#242 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
backend

調査の方向性

バグは core/src/main/java/com/backblaze/b2/util/B2InputStreamExcerpt.java の getRemaining にあり、long の差分を int にキャストしています。このメソッドと、69行目、85行目、96行目(read、skip、available)の呼び出し元を読んでください。3 GiB の抜粋を持つストリームをラップし、小さなバッファで read を呼び出す単体テストで、負の長さが再現されるはずです。長さが Integer.MAX_VALUE に制限され、そのテストが通れば完了です。

索引モデルが issue の本文から書いたものです。

説明

What happens

getRemaining() returns (int) (pastEnd - iPosition). For an excerpt longer than Integer.MAX_VALUE bytes, the cast wraps to a negative number, and read, skip and available (which use it with Math.min) then pass a negative length down and fail. This affects only parts larger than 2 GiB.

Where

core/src/main/java/com/backblaze/b2/util/B2InputStreamExcerpt.java:146 (getRemaining), used at :69, :85 and :96.

Why it matters

Impact: Availability (an upload of such a part fails), loud. Severity: High, because it only happens for a part over 2 GiB, which needs a custom part size because the default part sizes come from the server's recommended size (about 100 MB), and there is no workaround besides smaller parts.

How to check

Found by reading the code, not reproduced. Read getRemaining and its callers. A unit test could wrap a stream in B2InputStreamExcerpt with a start of 0 and a length of 3 GiB and call read(buf, 0, 10). Clamping with (int) Math.min(Integer.MAX_VALUE, pastEnd - iPosition) would avoid the overflow.

Version

Seen at v6.5.0. Present on the default branch: present.

主要言語
Java
スター
103
フォーク
23
平均マージ
5日 8時間
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Backblaze/b2-sdk-java のほかの issue

Backblaze/b2-sdk-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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