Repository navigation
fix: bound backslash scan to the base64 string in JSONReaderUTF8.readBase64 (issue #7967) - #7972
Open
divine-punishment wants to merge 1 commit into
Open
divine-punishment wants to merge 1 commit into
divine-punishment wants to merge 1 commit into
Conversation
…Base64 With Base64StringAsByteArray enabled (the default in the fastjson 1.x compatibility package), deserializing a byte[] field whose base64 value is followed by escaped content elsewhere in the document failed with 'invalid base64 string' (issue alibaba#7967). readBase64 scans for a backslash to reject invalid escaped content, but searched from the value start to the END of the document instead of up to the closing quote. A backslash belonging to a later field (e.g. a nested JSON string containing \" in a sibling field) was therefore treated as part of the base64 value. Only reject when the backslash lies within this string (before the closing quote), consistent with how JSONReaderASCII bounds the same scan in readFieldNameHashCode. Scanning to the end is kept for the vectorized indexOfSlash fast path. A backslash inside the base64 string itself is still rejected.
divine-punishment
force-pushed
the
fix/base64-slash-scan-bounds
branch
from
November 27, 2026 06:33
dada094 to
d1cc358
Compare
This branch has not been deployed
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.
What this PR does / why we need it?
Fixes #7967.
With
Base64StringAsByteArrayenabled (the default in the fastjson 1.x compatibility package), deserializing abyte[]field whose base64 value is followed by escaped content elsewhere in the document failed withinvalid base64 string.Root cause:
JSONReaderUTF8.readBase64scans for a backslash to reject invalid escaped content, but searched from the value start to the end of the document instead of up to the closing quote of the value. A backslash belonging to a later field (e.g. a nested JSON string containing\"in a sibling field) was therefore treated as if it were part of the base64 value.Summary of your change
JSONReaderUTF8.readBase64: only reject when the backslash lies within this string (before the closing quote,slashIndex < index), consistent with howJSONReaderASCII.readFieldNameHashCodebounds the same scan. Scanning to the end is kept for the vectorizedindexOfSlashfast path.\).Issue7967covering both the byte[] and String parse paths of the issue scenario, plus the still-rejected backslash-inside-string case.Please indicate you've done the following:
中文说明
修复内容
Fixes #7967:
Base64StringAsByteArray开启时(fastjson 1.x 兼容包默认开启),byte[]字段的 base64 值之后文档中只要存在转义内容(如兄弟字段嵌套 JSON 字符串中的\"),反序列化即报invalid base64 string。根因:
JSONReaderUTF8.readBase64扫描反斜杠以拒绝非法转义内容,但范围从值起点直到整个文档结尾,而非当前值的结束引号;后续字段的转义反斜杠被误判为 base64 值的一部分。修改方式
slashIndex < index,结束引号之前)才拒绝;与JSONReaderASCII.readFieldNameHashCode对同一函数的边界用法保持一致。扫到文档结尾保留,维持indexOfSlash向量化快路径\)Issue7967:issue 场景的 byte[]/String 双路径 + 字符串内反斜杠仍拒绝