fix(encode): add depth counter to prevent stack overflow#71
Conversation
|
Warning Review limit reached
More reviews will be available in 49 minutes and 23 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds depth-aware JSON encoding to prevent stack overflow from circular references or deeply-nested tables. It introduces ChangesDepth-aware JSON encoding with max-depth limit
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…refs and deep nesting Adds ENCODE_MAX_DEPTH = 1000 (matching lua-cjson default) and threads a depth argument through all four container encode helpers. Depth is checked at entry to each container; exceeding the limit raises a clean Lua error instead of crashing the process via stack overflow. Fixes #62
07deb85 to
94c2cc5
Compare
关联 Issue
Closes #62
做了什么
lua/qjson/table.lua中添加ENCODE_MAX_DEPTH = 1000常量(对齐 lua-cjson 默认值)encode、encode_proxy、encode_plain_table添加depth参数透传encode_arrayencode_objectencode_lazy_object_walkingencode_lazy_array_walking_M.encode = encode改为包装函数,调用encode(v, 1)启动深度计数tests/lua/encode_depth_spec.lua,覆盖三种场景Resolved Checklist Items
"qjson.encode: max depth exceeded"为什么这样做
depth > 1000触发错误,即 depth=1000 通过、depth=1001 报错——与 lua-cjson 语义一致encode_proxy的快速路径(dirty=false,直接返回原始 buffer 切片)不做递归,无需检查深度;检查仅在 dirty 走 walking 路径时发生如何验证
make test:131 successes / 0 failures / 0 errorsmake lint:clippy 无 warningt.self = t)→ 抛"qjson.encode: max depth exceeded"而非 stack overflowBreaking Changes
无。
_M.encode公开接口签名不变,depth仅为内部参数。Summary by CodeRabbit
New Features
Tests