Skip to content

guard against integer overflow in write()#1443

Open
jmestwa-coder wants to merge 1 commit intoapache:masterfrom
jmestwa-coder:bytearrayoutputstream-overflow
Open

guard against integer overflow in write()#1443
jmestwa-coder wants to merge 1 commit intoapache:masterfrom
jmestwa-coder:bytearrayoutputstream-overflow

Conversation

@jmestwa-coder
Copy link
Copy Markdown

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

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.

1 participant