Skip to content

HADOOP-18896. NegativeArraySizeException thrown in FSOutputSummer.jav…#8622

Open
anshuksi282-ksolves wants to merge 2 commits into
apache:trunkfrom
anshuksi282-ksolves:HADOOP-18896
Open

HADOOP-18896. NegativeArraySizeException thrown in FSOutputSummer.jav…#8622
anshuksi282-ksolves wants to merge 2 commits into
apache:trunkfrom
anshuksi282-ksolves:HADOOP-18896

Conversation

@anshuksi282-ksolves

Copy link
Copy Markdown

Description of PR

This PR fixes HADOOP-18896.

The buffer size in FSOutputSummer is computed as sum.getBytesPerChecksum() * BUFFER_NUM_CHUNKS. When
file.bytes-per-checksum is configured to a very large value (e.g. 238609295), this multiplication overflows a signed 32-bit int and wraps around to a negative number, causing a NegativeArraySizeException when allocating the internal buffer array.

This PR adds a Preconditions.checkArgument check in the FSOutputSummer constructor to validate that the computed buffer size is positive, failing fast with a clear IllegalArgumentException instead of an obscure NegativeArraySizeException.

This continues the work started in #6064 by @teamconfx, which went stale. This PR additionally adds a unit test, as the original PR's test4tests check had failed for not including one.

How was this patch tested?

  • Added a new test class TestFSOutputSummer in hadoop-common with testLargeBytesPerChecksumOverflow, using a minimal concrete subclass of FSOutputSummer to verify the constructor fails with IllegalArgumentException (rather than NegativeArraySizeException) when bytesPerChecksum * BUFFER_NUM_CHUNKS overflows.
  • Verified the test fails with the original NegativeArraySizeException when the fix is reverted, and passes with the fix applied.
  • mvn -pl hadoop-common-project/hadoop-common test -Dtest=TestFSOutputSummer passes.

Note: the JIRA's original reproduction steps reference an HDFS test (TestDecommissionWithStriped), but since the buffer overflow bug lives entirely in hadoop-common's FSOutputSummer class, this PR adds a focused unit test in hadoop-common instead, avoiding an unnecessary cross-module HDFS test dependency.

AI Tooling

Contains content generated by Claude (Anthropic). Used to help investigate the root cause, draft the fix, and write/verify the accompanying unit test.

@anshuksi282-ksolves

Copy link
Copy Markdown
Author

Hi all,
Requesting a review whenever you get a chance. This PR picks up HADOOP-18896 from where #6064 (@teamconfx) left off — it went stale without a unit test. I've added a unit test (TestFSOutputSummer#testLargeBytesPerChecksumOverflow) that reproduces the original NegativeArraySizeException without the fix, and verifies the fix resolves it with a clean IllegalArgumentException instead.

I'm new to contributing to Hadoop, so please let me know if any changes are needed. Thanks in advance!

cc: @ayushtkn @dineshchitlangia @brahmareddybattula @pjfanning @slfan1989

protected FSOutputSummer(DataChecksum sum) {
this.sum = sum;
Preconditions.checkArgument(
sum.getBytesPerChecksum() * BUFFER_NUM_CHUNKS > 0,

@pjfanning pjfanning Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do something like:

int bufArraySize;
try {
  bufArraySize = Math.multiplyExact(sum.getBytesPerChecksum(), BUFFER_NUM_CHUNKS);
} catch (ArithmeticException ae) {
  throw new IllegalArgumentException("The calculated buffer array size for FSOutputSummer is too large", ae);
}
if (bufArraySize < 0) {
  throw new IllegalArgumentException("The calculated buffer array size for FSOutputSummer is negative");
}
this.buf = new byte[bufArraySize];

I would suggest that you also check the array size in a similar way for this.checksum.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @pjfanning!
Updated to use Math.multiplyExact for both buf and checksum buffer size checks, as suggested.

I did try adding a dedicated test for the checksum buffer overflow path, but getChecksumSize() returns a fixed value from DataChecksum.Type (e.g. 4 for CRC32), so it can never actually be large enough to overflow — that path isn't reachable in practice, just defensive. So I've kept the existing unit test covering the buf overflow case, and re-ran TestFSOutputSummer, TestChecksumFileSystem, and TestChecksumFs to confirm no regressions.

@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 9m 8s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 27m 1s trunk passed
+1 💚 compile 8m 40s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 compile 8m 55s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 checkstyle 0m 49s trunk passed
+1 💚 mvnsite 1m 11s trunk passed
+1 💚 javadoc 0m 55s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 49s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 spotbugs 1m 45s trunk passed
+1 💚 shadedclient 18m 11s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 40s the patch passed
+1 💚 compile 8m 31s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javac 8m 31s the patch passed
+1 💚 compile 9m 45s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 javac 9m 45s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 47s the patch passed
+1 💚 mvnsite 1m 17s the patch passed
+1 💚 javadoc 0m 46s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 43s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 spotbugs 1m 57s the patch passed
+1 💚 shadedclient 18m 13s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 18m 20s hadoop-common in the patch passed.
+1 💚 asflicense 0m 40s The patch does not generate ASF License warnings.
139m 56s
Subsystem Report/Notes
Docker ClientAPI=1.55 ServerAPI=1.55 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8622/1/artifact/out/Dockerfile
GITHUB PR #8622
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 5ab2ba19cd5b 5.15.0-181-generic #191-Ubuntu SMP Fri May 22 19:09:02 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 5985a43
Default Java Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.11+10-1-24.04.2-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8622/1/testReport/
Max. process+thread count 1264 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8622/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 24s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 28m 42s trunk passed
+1 💚 compile 9m 41s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 compile 9m 53s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 checkstyle 0m 52s trunk passed
+1 💚 mvnsite 1m 5s trunk passed
+1 💚 javadoc 0m 47s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 47s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 spotbugs 1m 40s trunk passed
+1 💚 shadedclient 18m 38s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 44s the patch passed
+1 💚 compile 9m 48s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javac 9m 48s the patch passed
+1 💚 compile 8m 49s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 javac 8m 49s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 49s the patch passed
+1 💚 mvnsite 1m 9s the patch passed
+1 💚 javadoc 0m 54s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 52s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 spotbugs 1m 53s the patch passed
+1 💚 shadedclient 16m 45s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 18m 44s hadoop-common in the patch passed.
+1 💚 asflicense 0m 48s The patch does not generate ASF License warnings.
135m 26s
Subsystem Report/Notes
Docker ClientAPI=1.55 ServerAPI=1.55 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8622/2/artifact/out/Dockerfile
GITHUB PR #8622
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 13c8d3582b82 5.15.0-181-generic #191-Ubuntu SMP Fri May 22 19:09:02 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 60af129
Default Java Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.11+10-1-24.04.2-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8622/2/testReport/
Max. process+thread count 3155 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8622/2/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants