Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Leaking buffer negative index fault #241

Copy link
Copy link
@svobol13

Description

@svobol13
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.