Skip to content

fix: JSONB ASM direct-write under-counted object frame bytes (#7616) - #7617

Merged
wenshao merged 2 commits into
mainfrom
fix/issue-7616-asm-jsonb-capacity
Apr 12, 2026
Merged

wenshao merged 2 commits into
mainfrom
fix/issue-7616-asm-jsonb-capacity

Conversation

@wenshao

@wenshao wenshao commented Apr 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes [BUG] JSONB 序列化 UTF-16 大字符串时 arraycopy 越界(2.0.55 正常,2.0.56 起回归) #7616: JSONB.toBytes throws ArrayIndexOutOfBoundsException in JSONB$IO.writeStringUTF16 when serializing a Bean field that holds a large UTF-16 String. Regression introduced in 2.0.56.
  • Root cause: in ObjectWriterCreatorASM.genMethodWriteJSONB, the buffer pre-sizing formula was inverted — (group.start ? 0 : 1) + (group.end ? 0 : 1) contributed 0 bytes exactly when BC_OBJECT / BC_OBJECT_END were actually written, leaving the buffer 2 bytes short for tight Beans (e.g. one large UTF-16 String field).
  • Fix: invert to (group.start ? 1 : 0) + (group.end ? 1 : 0).

Test plan

  • New regression test Issue7616 reproducing the original report (nested Bean → List<Message> → 232,768-char UTF-16 payload), verifies round-trip.
  • Existing JSONB / writer tests pass (JSONBTest*, JSONWriterJSONBTest, ObjectWriterCreatorASMTest, 159 tests).

🤖 Generated with Claude Code

@wenshao wenshao left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The fastjson1-compatible JSON.writeJSONString(...) methods in this PR now preserve UseISO8601DateFormat over an externally supplied dateFormat, but fastjson1-compatible/src/main/java/com/alibaba/fastjson/support/jaxrs/FastJsonProvider.java still calls context.setDateFormat(dateFormat) unconditionally in writeJSONStringWithFastJsonConfig(...). This leaves the JAX-RS integration with the old precedence and makes behavior inconsistent across integrations. Consider applying the same !context.isDateFormatISO8601() guard there as well.

— gpt-5.4 via Qwen Code /review

wenshao and others added 2 commits April 12, 2026 14:55
…city (#7616)

The minCapacity formula in genMethodWriteJSONB was inverted: when a field
group writes BC_OBJECT (start) or BC_OBJECT_END (end), each takes 1 byte,
but the formula contributed 0 in those cases. For Beans whose direct-write
capacity was tight (e.g. a single large UTF-16 String field), the buffer
ended up 2 bytes short, causing JSONB.IO.writeStringUTF16's arraycopy to
overrun. Regression introduced in 2.0.56.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Multi-field UTF-16: ensures the per-field stringCapacity stays in sync
  with the BC_OBJECT/BC_OBJECT_END framing accounting.
- Split-group bean: exercises the (group.start=false, group.end=false)
  middle-direct-group code path that the inverted formula previously
  over-allocated by 2 bytes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wenshao
wenshao force-pushed the fix/issue-7616-asm-jsonb-capacity branch from 8c542ec to 75a784f Compare April 12, 2026 06:55
@wenshao
wenshao merged commit 3697c2d into main Apr 12, 2026
62 checks 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.

[BUG] JSONB 序列化 UTF-16 大字符串时 arraycopy 越界(2.0.55 正常,2.0.56 起回归)

1 participant