Skip to content

guard against integer overflow in write()#1443

Merged
bitstorm merged 1 commit into
apache:masterfrom
jmestwa-coder:bytearrayoutputstream-overflow
Jul 10, 2026
Merged

guard against integer overflow in write()#1443
bitstorm merged 1 commit into
apache:masterfrom
jmestwa-coder:bytearrayoutputstream-overflow

Conversation

@jmestwa-coder

Copy link
Copy Markdown
Contributor

Summary

Add a guard in ByteArrayOutputStream.write(...) to prevent integer overflow when calculating the new size.

Problem

The size is tracked using an int . When total data exceeds Integer.MAX_VALUE, count + len overflows and becomes negative.Since Wicket uses multiple buffers, this can happen without hitting JVM array limits.

Impact

  • size() may return a negative value

  • toByteArray() can throw NegativeArraySizeException

  • Leads to inconsistent behavior and possible data loss

Fix

Add a simple overflow check and fail fast with IndexOutOfBoundsException.

Notes

  • No change for valid inputs

  • No API changes

  • Minimal, safe fix

@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

any update?

@bitstorm bitstorm merged commit 629c696 into apache:master Jul 10, 2026
3 checks passed
@bitstorm

Copy link
Copy Markdown
Contributor

@jmestwa-coder thank you! Sorry if I didn't see the PR back when you opened it

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants