-
Notifications
You must be signed in to change notification settings - Fork 611
fix: guard readFieldName lookahead against AIOOBE on trailing backslash #7833
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -946,6 +946,9 @@ public final String readFieldName() { | |
| int c = bytes[offset]; | ||
| if (c == '\\') { | ||
| nameEscape = true; | ||
| if (offset + 1 >= end) { | ||
| throw new JSONException(info("illegal input")); | ||
|
Member
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. [Suggestion] The new throw diverges from this file's established wording for the same condition. — qwen3.8-flash via Qwen Code /review (v0.22.2) |
||
| } | ||
| c = bytes[offset + 1]; | ||
| offset += (c == 'u' ? 6 : (c == 'x' ? 4 : 2)); | ||
| continue; | ||
|
|
||
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.
[Suggestion] Nothing in the test suite pins this guard: reverting all three added lines leaves the entire reactor suite green. Measured during this review — the full 15-module
mvn teston the PR reports 9606 tests / 0 failures, and the same suite on an identical tree with only these three lines reverted (the file restored to30dd009d1) reports the exact same 9606 / 0 failures. The behavioral delta is real, though: with the guard,JSON.parseObject("{\"a\\")throwsJSONException: illegal input; with it reverted, the same call throwsArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4.readFieldName()is a large method that gets hot-path refactors regularly, so a future edit that drops this branch would silently resurrect the original #7809 symptom — an uncheckedArrayIndexOutOfBoundsExceptionescaping callers'catch (JSONException)— with no CI signal. Suggest addingcore/src/test/java/com/alibaba/fastjson2/issues_7000/Issue7809.java(the convention used by the sibling fixes Issue7668/7678/7691):assertThrows(JSONException.class, () -> JSON.parseObject("{\"a\\"))for the inputs{"\,{"a\and{"a":1,"b\— asserting the specific type matters here, sinceArrayIndexOutOfBoundsExceptionis also aRuntimeExceptionand a looseassertThrows(Exception.class, ...)would stay green on the unfixed build — plus one positive control such as{"a\"b":1}still parsing to keya"b. As the acceptance criterion for that new test, remove these three lines and confirm it goes red with theArrayIndexOutOfBoundsException.— qwen3.8-flash via Qwen Code /review (v0.22.2)