Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

FastByteArrayOutputStream input stream rejects valid skip(long) arguments

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

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

@hickey-ai がすでに取り組んでいます。

2026年10月17日 から。

  • #37492 @SwatiKumari250 による — マージされずにクローズ
  • #37497 @erfannvb による — マージされずにクローズ

評価

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

調査の方向性

バグは spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java の入力ストリームの skip(long) メソッドにあります。このメソッドは、残りのバイト数を確認する前に、負の値や大きすぎる値を拒否しています。issue の Repro.java をコンパイルして実行し、2 つの IllegalArgumentException のケースを確認してください。skip(-1) が 0 を返し、skip(Integer.MAX_VALUE + 1) が残りのバイト数を返せば完了です。既存のテストがすべて引き続き通ることも条件です。

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

説明

status: waiting-for-triage
Affected versions

Verified with the published spring-core 7.0.9 and 6.2.19 artifacts on JDK 21. The same result was reproduced with the affected classes compiled from main at 85a532dce455655aec8fd5a301b37c6c5ceda5bb, with the remaining dependencies supplied by spring-core 7.0.9. This was a focused reproduction, not a full Gradle build.

Problem

The input stream returned by FastByteArrayOutputStream.getInputStream() throws IllegalArgumentException from skip(long) for negative amounts and for amounts larger than Integer.MAX_VALUE.

The InputStream contract says negative amounts skip no bytes and return 0. A large positive amount should skip the available bytes, even if fewer than requested are available. This can break generic stream code that uses a long skip amount independent of the backing stream's capacity.

The reproduction below buffers only three bytes; it does not require a large allocation.

Minimal reproduction

Save as Repro.java:

import java.io.ByteArrayInputStream;
import org.springframework.util.FastByteArrayOutputStream;

public class Repro {
    public static void main(String[] args) throws Exception {
        byte[] bytes = {1, 2, 3};
        var output = new FastByteArrayOutputStream();
        output.write(bytes);
        for (long amount : new long[] {-1, (long) Integer.MAX_VALUE + 1}) {
            System.out.println("JDK: " + new ByteArrayInputStream(bytes).skip(amount));
            try {
                System.out.println("Spring: " + output.getInputStream().skip(amount));
            } catch (IllegalArgumentException ex) {
                System.out.println("Spring: " + ex);
            }
        }
    }
}

Run on Java 17 or later:

curl -fLO https://repo.maven.apache.org/maven2/org/springframework/spring-core/7.0.9/spring-core-7.0.9.jar
java -cp spring-core-7.0.9.jar Repro.java

Actual output:

JDK: 0
Spring: java.lang.IllegalArgumentException: n must be 0 or greater: -1
JDK: 3
Spring: java.lang.IllegalArgumentException: n exceeds maximum (2147483647): 2147483648

Expected: the Spring results should also be 0 and 3, respectively. A positive request larger than the stream's remaining size should simply consume the remaining bytes.

Cause

FastByteArrayInputStream.skip rejects those values before examining the available bytes. The stream's int-sized internal buffers do not require rejection of long requests; the request can be bounded by the remaining byte count before conversion.

See the Java InputStream.skip contract.

Related reports checked

I searched issues and pull requests for FastByteArrayOutputStream skip, FastByteArrayInputStream, and skip Integer.MAX_VALUE. The older reports found (#18431, #18783, #18809, #22024) concern read/EOF behavior, not the skip argument handling above. I did not find a direct duplicate.

主要言語
Java
スター
60.3k
フォーク
38.7k
平均マージ
1日 8時間
マージ済み PR(30日)
36

環境構築

はじめの一歩

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

spring-projects/spring-framework のほかの issue

spring-projects/spring-framework の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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