Repository navigation
fix: handle truncated escape in JSONReaderUTF16 - #7791
Merged
Merged
Conversation
wenshao
previously requested changes
Aug 20, 2026
wenshao
dismissed
their stale review
October 17, 2026 08:24
Dismissing stale review: R1-1 (EOI guard added to only one of the structurally identical sites) is addressed by 27aa75c, which routes all JSONReaderUTF16 escape sites through the bounded char2(chars, offset, end), plus the sibling JSONReaderUTF8; R1-2/R1-3 are test notes. CI green on head. Agent-verified against the head tree.
# Conflicts: # core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java # core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF8.java
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么 / 为什么需要这个修改?
当 JSON 字符串以被截断的反斜杠转义结尾时,
JSONReaderUTF16.readString()会读取字符缓冲区末尾之外。例如,在 JDK 8 上执行
JSON.parse("\"\\")会抛出ArrayIndexOutOfBoundsException,而不是JSONException。由于ArrayIndexOutOfBoundsException不是JSONException的子类,调用方无法通过catch (JSONException)处理该非法输入。本次修改在读取反斜杠后的字符之前检查是否已经到达输入末尾,并抛出
JSONException,使 UTF16 reader 的行为与 UTF8 reader 及其他非法 JSON 输入保持一致。修改摘要
JSONReaderUTF16.readString()的反斜杠处理分支增加输入结束检查。String、char[]和 UTF8 字节数组解析入口。已执行以下验证:
上述命令均执行成功。
#7790