Fix AIOOBE in readString(Writer) at output buffer boundary - #1673
Open
pjfanning wants to merge 1 commit into
Open
Fix AIOOBE in readString(Writer) at output buffer boundary#1673pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
UTF8StreamJsonParser and UTF8DataInputJsonParser flushed the streaming buffer only inside the ASCII loop, before appending. On exit outPtr could equal the buffer length, so the escape and multi-byte decode arms wrote out of bounds. Add a flush check before the switch; ReaderBasedJsonParser already checked per iteration and is unaffected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0161vnbY6rGfPFAYBMnbv64c
Contributor
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.
JsonParser.readString(Writer)throwsArrayIndexOutOfBoundsExceptionon the two byte-based parsers when a string's plain-ASCII prefix is an exact multiple of the 1024-char streaming buffer and the next character is an escape or a multi-byte UTF-8 char._streamString(Writer)inUTF8StreamJsonParserandUTF8DataInputJsonParseronly checksoutPtr >= outBuf.lengthinside the ASCII loop, before appending. On exit viabreak ascii_loop,outPtrcan equal the buffer length, and thecase 1/2/3/4:decode arms then writeoutBuf[outPtr++]unchecked.Recurs at every multiple of 1024.
ReaderBasedJsonParserchecks at the top of each iteration and is unaffected.Issue appears to be related to #1288 and only affects 3.x releases.
Fix
Add the flush check between the closing-quote test and the
switch, covering cases 1-3 and the high surrogate of case 4 (case 4's existing mid-pair check still handles the low surrogate). The flush carries themaxStringLengthvalidation so constraint enforcement stays on the same cadence as the other flush points.Tests
Two tests added to
ReadStringStreamingTest:escapeAtFullOutputBuffer—\nescape after an ASCII prefix of exactly 1024 and 2048 chars, acrossALL_MODESmultiByteAtFullOutputBuffer— same boundary via 2-, 3- and 4-byte UTF-8 characters, acrossALL_BINARY_MODESThe file's existing boundary tests used
OUT_BUF_SIZE - 1, one char short of the failing case, which is why this slipped through. Both new tests fail without the fix and pass with it; full suite is 1714 tests, 0 failures.No release-notes entry yet — no issue number filed for this.
Forward merge to 3.2 / 3.x left to a human.
🤖 Generated with Claude Code
https://claude.ai/code/session_0161vnbY6rGfPFAYBMnbv64c