Skip to content

Leaking buffer negative index fault #241

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

Open
svobol13 opened this issue Jun 13, 2019 · 0 comments
Open

Leaking buffer negative index fault #241

svobol13 opened this issue Jun 13, 2019 · 0 comments

Comments

@svobol13
Copy link
Collaborator

svobol13 commented Jun 13, 2019

I found that when my source is "slow", buffer grows infinitely till it throws java.lang.NegativeArraySizeException. Spent quite some time trying to find minimal reproducible example (it was failing on my 8GB json I didnt really want to post here :D).

  @Test
  public void leakTest() throws IOException {
    InputStream slowStream = new InputStream() {
      int position = 0;
      boolean pretendEmptyNextRead = false;
      byte[] src = "{\"a\":\"123456789abcdef\"}".getBytes();

      @Override
      public int read() throws IOException {
        if (position < src.length) {
          if (pretendEmptyNextRead) {
            pretendEmptyNextRead = false;
            return -1;
          } else {
            pretendEmptyNextRead = true;
            return src[position++];
          }
        }
        return -1;
      }
    };

    JsonIterator jsonIterator = JsonIterator.parse(slowStream, 1024 * 1024);
    jsonIterator.readObject();
    jsonIterator.readAny();
  }

If you run this you will get the exception before parsing whole string. If I observe byte[] newBuf = new byte[iter.buf.length * 2]; it growths even if it doesnt need to.

This issue is probably duplicate of this #124. Using version 0.9.19.

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

1 participant