Skip to content

fix: guard against ArrayIndexOutOfBounds in readFieldName whitespace skip - #7827

Open
waterWang wants to merge 1 commit into
alibaba:mainfrom
waterWang:fix-issue7826-fieldname-whitespace
Open

fix: guard against ArrayIndexOutOfBounds in readFieldName whitespace skip#7827
waterWang wants to merge 1 commit into
alibaba:mainfrom
waterWang:fix-issue7826-fieldname-whitespace

Conversation

@waterWang

Copy link
Copy Markdown

Fix

Adds bounds checks to the two whitespace-advancement loops in JSONReaderASCII.readFieldName() that could read past the array end when the input ends with whitespace after a field name (or after the colon).

// Before: no bounds check
while (c <= ' ' && ((1L << c) & SPACE) != 0) {
    offset++;
    c = bytes[offset];  // ArrayIndexOutOfBounds when offset == end
}

// After: bounds check, set EOI at end
while (c <= ' ' && ((1L << c) & SPACE) != 0) {
    c = offset + 1 >= end ? EOI : bytes[++offset];
}

JSON.parse("{\"a\" ") now correctly throws JSONException instead of ArrayIndexOutOfBoundsException.

Fixes #7826

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

[BUG] ArrayIndexOutOfBoundsException` on a field name followed by trailing whitespace

2 participants