Skip to content

fix: add depth limit and input validation to json parser - #69

Merged
swordqiu merged 1 commit into
yunionio:masterfrom
swordqiu:hotfix/qj-parse-robustness
Sep 16, 2026
Merged

swordqiu merged 1 commit into
yunionio:masterfrom
swordqiu:hotfix/qj-parse-robustness

Conversation

@swordqiu

Copy link
Copy Markdown
Member

变更

  • 解析时对 object/array 的嵌套层数设上限 maxParseDepth,超出返回 ErrNestedTooDeep
  • 值为分隔符时解析结果为空串,改按 null 处理,不再访问第 0 个字节
  • 校验保留键 ___jnid_ 的值类型,非整数返回 ErrInvalidNodeId
  • 节点 ID 重复时返回 ErrDuplicateNodeId

测试

新增 parse_test.go

  • TestParseNoPanic 覆盖截断、空值等畸形输入组合
  • TestParseInvalidNodeId 覆盖 ___jnid_ 取值类型与重复节点 ID
  • TestParseNestingDepth 验证深度边界(限制内可正常解析,超出报错)

go test ./... 全量通过。

- cap the nesting level of object/array at maxParseDepth
- treat an empty value as null instead of indexing into it
- validate the type of the reserved node id key
- report a duplicated node id as an error
@swordqiu
swordqiu merged commit 8e0c8de into yunionio:master Sep 16, 2026
1 check passed
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.

1 participant