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

Handles the case where the reader unexpectedly encounters an oversized value, throwing IonException with a helpful message. #680

Merged
merged 1 commit into from
Dec 26, 2023

Conversation

tgregg
Copy link
Contributor

@tgregg tgregg commented Dec 22, 2023

Description of changes:

Before this change, if the binary reader encountered an oversized value (due to either corruption of the header or an excessively large scalar), and no IonBufferConfiguration had been set, NullPointerException would be thrown. After this change, IonException is thrown with a helpful message. I added some tests to verify in both of the cases listed above that IonExceptions are thrown.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (b0d3dcc) 67.06% compared to head (aa9a794) 67.23%.
Report is 1 commits behind head on master.

Files Patch % Lines
...mazon/ion/impl/IonReaderContinuableCoreBinary.java 90.47% 0 Missing and 4 partials ⚠️
...main/java/com/amazon/ion/impl/IonCursorBinary.java 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #680      +/-   ##
============================================
+ Coverage     67.06%   67.23%   +0.17%     
- Complexity     5469     5484      +15     
============================================
  Files           159      159              
  Lines         22970    23007      +37     
  Branches       4116     4122       +6     
============================================
+ Hits          15404    15469      +65     
+ Misses         6286     6260      -26     
+ Partials       1280     1278       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@popematt popematt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than handling nulls in the implementation here, why not just have a default buffer configuration (that throws IonException) that is used when no buffer configuration is set? Then all of this can be encapsulated in the builder, which I think is better for long term maintainability.

…d value, throwing IonException with a helpful message.
@tgregg tgregg force-pushed the throw-on-null-bufferconfiguration branch from 5ae7ba8 to aa9a794 Compare December 22, 2023 23:45
@tgregg
Copy link
Contributor Author

tgregg commented Dec 22, 2023

@popematt Yeah, I think making the throwing configuration the default makes sense. Updated in revision 2.

// Using null instead of a no-op handler enables a quick null check to skip calculating the amount of data
// processed, improving performance.
BufferConfiguration.DataHandler dataHandler = configuration.getDataHandler();
return dataHandler == IonBufferConfiguration.DEFAULT.getDataHandler() ? null : dataHandler;
Copy link
Contributor

@popematt popematt Dec 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could do something like this. It makes the intention a little more clear. However, if it would be one of those surprisingly invasive changes, then don't bother with it.

Suggested change
return dataHandler == IonBufferConfiguration.DEFAULT.getDataHandler() ? null : dataHandler;
return dataHandler == DataHandler.NO_OP ? null : dataHandler;

@tgregg tgregg merged commit 57c6787 into master Dec 26, 2023
26 of 34 checks passed
@tgregg tgregg deleted the throw-on-null-bufferconfiguration branch December 26, 2023 22:17
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.

2 participants