-
Notifications
You must be signed in to change notification settings - Fork 1.8k
AVRO-4241: [Java] BinaryDecoder should verify available bytes before reading #3725
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,18 @@ public int read(byte[] b, int off, int len) throws IOException { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int available() throws IOException { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's this real oddness with available(), in that some interpret it as "all that is left in the stream" but it can also be interpreted as "bytes you can read() before blocking for new data". that's probably the correct one. it does hold here, just important not to use available() as measures of how much is left in a stream, which may be larger. looks like you are doing the right thing and testing it later on. |
||
| long remaining = 0; | ||
| for (int i = current; i < buffers.size(); i++) { | ||
| remaining += buffers.get(i).remaining(); | ||
| if (remaining >= Integer.MAX_VALUE) { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
| } | ||
| return (int) remaining; | ||
| } | ||
|
|
||
| /** | ||
| * Read a buffer from the input without copying, if possible. | ||
| */ | ||
|
|
||
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.
I worry about the cost of this operation on a complex wide and recursive structure, as it'll be invoked once per record.
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.
I added a JMH benchmark test to measure the impact of this for wide and deeply nested structures the results are promising apparently the extra cost is negligible.
https://gist.github.com/iemejia/bae3302ec0f3d2abf92e99911ccba606
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.
that's cool. I'm hitting serious field enum problems on variants in parquet, as shredded variants explode the schema.