Fix overflow in UnsafeByteArrayInputStream.skip for large counts by hickey-ai · Pull Request #16523 · apache/dubbo · GitHub
Skip to content

Fix overflow in UnsafeByteArrayInputStream.skip for large counts - #16523

Open
hickey-ai wants to merge 2 commits into
apache:3.3from
hickey-ai:codex/fix-byte-array-skip-overflow
Open

hickey-ai wants to merge 2 commits into
apache:3.3from
hickey-ai:codex/fix-byte-array-skip-overflow

Conversation

@hickey-ai

Copy link
Copy Markdown
Contributor

What is the purpose of the change?

Fixes #16520

UnsafeByteArrayInputStream.skip(long) can overflow its mPosition + len bounds check for a large positive count after the cursor has advanced. For example, after reading one byte of a slice, skip(Long.MAX_VALUE) reports Long.MAX_VALUE rather than the remaining byte count and can move the cursor backwards. The same request at EOF can make already-consumed bytes readable again.

Compare the requested count with the remaining bytes before updating the cursor. This keeps skipping bounded to the current slice and preserves zero/negative skips, EOF, and mark/reset behavior.

Regression coverage includes Long.MAX_VALUE, Long.MAX_VALUE - 1, a large non-overflowing control, a nonzero slice offset, EOF, mark/reset, and nonpositive counts. Three regression invocations fail against the unmodified source and pass with the fix.

Validation on OpenJDK 21 (the project compiles with release 8): all 13 UnsafeByteArrayInputStreamTest invocations and all 48 I/O-package tests pass, with no failures, errors or skips. The Maven lifecycle Spotless check and git diff --check pass. This is focused module verification; full-repository and production-network testing were not run.

Validation checklist

  • Linked reproducible GitHub issue.
  • Description explains the trigger, expected behavior and minimal fix.
  • Regression tests executed locally; failures reproduced before the change.
  • GitHub Actions: pending the newly submitted PR.

Investigation and patch preparation were AI-assisted; the stated local tests were actually executed.

@codecov-commenter

codecov-commenter commented Oct 19, 2026 •

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

[Bug] UnsafeByteArrayInputStream large skips can overflow and rewind the cursor

2 participants