-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add a _Private_IonConstants.ARRAY_MAXIMUM_SIZE #708
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Use the new constant where appropriate Arrays in Java must be indexed by integers (JLS 10.4), but the true maximum array size may be less than `Integer.MAX_VALUE`. True maximum array size is a JVM implementation detail, and varies by type and by JVM. We have this pinned at `Integer.MAX_VALUE - 8` because that's a fairly common value in the JDK itself, in classes such as `ConcurrentHashMap`, `InputStream`, `Hashtable`, `ByteArrayChannel`, etc. In testing against a variety of JVMs and types the smallest maximum size I've seen is `Integer.MAX_VALUE - 2`, and the smallest maximum size I've seen reported is `Integer.MAX_VALUE - 6`
tgregg
approved these changes
Jan 26, 2024
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #708 +/- ##
============================================
+ Coverage 67.23% 67.25% +0.02%
- Complexity 5484 5488 +4
============================================
Files 159 159
Lines 23025 23030 +5
Branches 4126 4128 +2
============================================
+ Hits 15481 15489 +8
+ Misses 6262 6260 -2
+ Partials 1282 1281 -1 ☔ View full report in Codecov by Sentry. |
tgregg
approved these changes
Jan 30, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
tgregg
pushed a commit
that referenced
this pull request
Feb 8, 2024
* Add a _Private_IonConstants.ARRAY_MAXIMUM_SIZE * Use the new constant where appropriate Arrays in Java must be indexed by integers (JLS 10.4), but the true maximum array size may be less than `Integer.MAX_VALUE`. True maximum array size is a JVM implementation detail, and varies by type and by JVM. We have this pinned at `Integer.MAX_VALUE - 8` because that's a fairly common value in the JDK itself, in classes such as `ConcurrentHashMap`, `InputStream`, `Hashtable`, `ByteArrayChannel`, etc. In testing against a variety of JVMs and types the smallest maximum size I've seen is `Integer.MAX_VALUE - 2`, and the smallest maximum size I've seen reported is `Integer.MAX_VALUE - 6` * Add test coverage for maximum buffer size * Add more test coverage for maximum buffer size * Ensure that a modeled exception is thrown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
Arrays in Java must be indexed by integers (JLS 10.4), but the true maximum array size may be less than
Integer.MAX_VALUE
. True maximum array size is a JVM implementation detail, and varies by type and by JVM. We have this pinned atInteger.MAX_VALUE - 8
because that's a fairly common value in the JDK itself, in classes such asConcurrentHashMap
,InputStream
,Hashtable
,ByteArrayChannel
, etc.In testing against a variety of JVMs and types the smallest maximum size I've seen is
Integer.MAX_VALUE - 2
, and the smallest maximum size I've seen reported isInteger.MAX_VALUE - 6
This change adds a constant
_Private_IonConstants.ARRAY_MAXIMUM_SIZE
and uses the new constant where appropriate.Need for this safeguard was exposed by another bug which caused excessive buffering in this chunk of IonCursorBinary:
ion-java/src/main/java/com/amazon/ion/impl/IonCursorBinary.java
Lines 502 to 511 in 3c1b6b1
While that is still under investigation, this at least should prevent
Requested array size exceeds VM limit
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.