Skip to content

Avoid integer overflow in NBT size limits - #1623

Open
kripypastishka wants to merge 1 commit into
retrooper:2.0from
kripypastishka:fix/nbt-size-limiter-integer-overflow
Open

kripypastishka wants to merge 1 commit into
retrooper:2.0from
kripypastishka:fix/nbt-size-limiter-integer-overflow

Conversation

@kripypastishka

Copy link
Copy Markdown

Prevent integer overflow in NBT size accounting
Summary
Use overflow-safe arithmetic to check the configured maximum size in NBTLimiter.increment(int).
Root cause
The existing check adds two signed int values before comparing the result to maxBytes. With unusually large custom limits, overflow can invalidate the comparison.
Changes

  • Promote the sum to long for the limit check.
  • Show the same overflow-safe total in the exception message.
    Tests
    Three JUnit tests were added: an overflow case, reaching the exact maximum, and rejecting negative increments. A focused standalone Java 21 arithmetic reproduction confirmed the defect and corrected check.

The default NBT size limit is much smaller; no network exploit has been demonstrated. The full Gradle build and new repository tests have not been executed. Please run ./gradlew :api:test.
Compatibility
No API, protocol, schema or configuration default changes.

Please review and test before merging.

@XIII-MC

XIII-MC commented Nov 7, 2026

Copy link
Copy Markdown

Is this AI

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.

3 participants