Repository navigation
fix: bound field name escape read in JSONReaderASCII - #7922
Support-itecz wants to merge 1 commit into
Conversation
wenshao
left a comment
There was a problem hiding this comment.
Not explored to full depth (tool budget reached): "agent 1a": running the new test to confirm end-to-end reachability and green status (no pre-built core/target/classes ; I did not build in the shared worktree).**; "agent 6c": JVM-cost / bytecode-size measurement of readFieldName() after the guard was added (static javac + javap or PrintInlining ) — readFieldName() is off the h…; "agent 1c": static bytecode measurement of readFieldName() before/after (no JDK on PATH); "agent 1c": open the reflection ObjectReader field-name loop to confirm it handles JSONException from readFieldName(); "agent reverse-audit (round 2)": dynamic confirmation (compile + run JSON.parseObject("{\"a\\u00\"}") against a built target/classes ) of whether the ArrayIndexOutOfBoundsException is reac…, and 5 more.
— DeepSeek-V4.1-Flash-1017 via Qwen Code /review (v0.26.0)
|
Ran the items the review couldn't get to, against 6261e45 (the sha in the ledger, so no head drift):
|
What this PR does / why we need it?
JSONReaderASCII.readFieldNamescans a quoted key in afor (... ; offset < end; ...)loop that boundsbytes[offset], but on a\escape it readsbytes[offset + 1]without checking that againstend. When the\is the last byte of a truncated input the read lands onbytes[end], soJSON.parseObject(String)andJSON.parseObject(byte[])raiseArrayIndexOutOfBoundsExceptioninstead ofJSONException. Trigger:JSON.parseObject("{\"\\"), or any key cut at a backslash such as{"ab\.The sibling
readFieldNameinJSONReaderUTF8andJSONReaderUTF16already bound the escape throughbyteAfterEscape/charAfterEscapeandcheckEscapeEnd; the ASCII reader was the only one missing the check, and the value-string readers in the same class already throwinvalid escape character EOIon the same truncation.Summary of your change
offset + 1againstendbefore the escape read inJSONReaderASCII.readFieldName, throwing theinvalid escape character EOIJSONExceptionthe other escape sites in the file already useFieldNameEscapeTruncationTestcovers the truncated-escape key forStringandbyte[]input plus a valid escaped-key round-tripSits with the recent truncated-input bounds work on
readNumber0,skipCommentand thereadFieldNamewhitespace path.Please indicate you've done the following: