Skip to content

Fix buffer overflow when serializing strings longer than 2048 chars#173

Merged
hadashiA merged 1 commit intomasterfrom
fix/expand-buffer-capacity
Mar 10, 2026
Merged

Fix buffer overflow when serializing strings longer than 2048 chars#173
hadashiA merged 1 commit intomasterfrom
fix/expand-buffer-capacity

Conversation

@hadashiA
Copy link
Copy Markdown
Owner

@hadashiA hadashiA commented Mar 9, 2026

Summary

  • Fix ExpandBuffer<T>.AsSpan(int length) to use while instead of if when growing the buffer
  • The buffer only doubled once (1024→2048), so strings exceeding 2048 chars caused ArgumentOutOfRangeException

Closes #168

Test plan

  • Added Serialize_LongString test with a 3000-char string
  • All existing tests pass

🤖 Generated with Claude Code

ExpandBuffer.AsSpan doubled the buffer only once, which was insufficient
for strings exceeding 2x the initial capacity. Use while loop to ensure
the buffer grows enough. (fixes #168)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hadashiA hadashiA force-pushed the fix/expand-buffer-capacity branch from 95da31b to 41bdb6a Compare March 10, 2026 09:01
@hadashiA hadashiA merged commit ff6f2c1 into master Mar 10, 2026
1 check passed
@hadashiA hadashiA deleted the fix/expand-buffer-capacity branch March 10, 2026 14:13
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.

Serializing a literal/multiline string of length > 2048 throws System.ArgumentOutOfRangeException

1 participant