Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow in ByteBlockPool, #1003 #1055

Merged
merged 1 commit into from
Dec 4, 2024
Merged

Conversation

paulirwin
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Fix overflow (resulting in ArrayIndexOutOfBoundsException) in ByteBlockPool

Fixes #1003

Description

Thanks to @hidingmyname for the provided test. This fixes an arithmetic overflow that results in an ArrayIndexOutOfBoundsException in ByteBlockPool for fields with a large number of small tokens. In .NET, the checked block causes the overflow to throw an OverflowException, just like how the upstream Java change to use Math.addExact(x, y) throws an ArithmeticException in that case.

@paulirwin paulirwin added the notes:bug-fix Contains a fix for a bug label Dec 3, 2024
@NightOwl888
Copy link
Contributor

I wonder, could Spatial4n/Spatial4n#1 be a similar issue as this (overflow)?

@paulirwin
Copy link
Contributor Author

I wonder, could Spatial4n/Spatial4n#1 be a similar issue as this (overflow)?

I don't think so, since it's not an addition that overflows Int32. In that case, I think it could be an out of range character in the geohash. Without trying out the code, just from thinking through it, it seems like characters above the ASCII alphanumeric set could cause that issue, such as 'Ä' (int value 196) which would result in a calculated index of (int)'Ä' - (int)'0' == 148 which is out of range. Just a thought there, if the caller is not validating that the input is a valid geohash.

@paulirwin paulirwin merged commit d597a5f into apache:master Dec 4, 2024
199 checks passed
@paulirwin paulirwin deleted the issue/1003 branch December 4, 2024 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:bug-fix Contains a fix for a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArrayIndexOutOfBoundsException in ByteBlockPool
2 participants