Skip to content

Large InputStreams cause negative index fault #124

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

Closed
ahantke opened this issue Nov 14, 2017 · 2 comments
Closed

Large InputStreams cause negative index fault #124

ahantke opened this issue Nov 14, 2017 · 2 comments

Comments

@ahantke
Copy link

ahantke commented Nov 14, 2017

The code attempts to increase the size of the buffer with a 2x multiplier until no further bytes are available. I have some concerns about this (but no concrete solution) because this in-memory approach is not a true stream. But, that aside, the following code within keepSkippedBytesThenRead(...) causes a problem:

byte[] newBuf = new byte[iter.buf.length * 2];

This leads to rapid increases in memory allocation for the buffer. When processing a large input you can easily roll to a negative integer and then you will obviously end up with an allocation error as the length is negative. A better approach, which I'll check in shortly, is to only increase the length of the byte array by the increment of the initially provided size in the JsonIter.parse(...). A more meaningful error than the negative index is also advised.

@taowen
Copy link
Contributor

taowen commented Nov 14, 2017

please provide some sample code to re-produce the problem. Large has many meanings, it is large array or large string?

@taowen
Copy link
Contributor

taowen commented Nov 18, 2017

keepSkippedBytesThenRead is only used when readAny which means skip and copy the bytes. It is not involved in normal encoding process. Keep bytes in memory is expected in this case.

@taowen taowen closed this as completed Nov 18, 2017
svobol13 added a commit to svobol13/json-iter-java that referenced this issue Jun 15, 2019
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

No branches or pull requests

2 participants