Skip to content

Fix TomlGenerator.writeString(char[],int,int) index bug when escaping needed - #726

Open
pjfanning wants to merge 1 commit into
FasterXML:2.21from
pjfanning:toml-char-array-string-escape
Open

pjfanning wants to merge 1 commit into
FasterXML:2.21from
pjfanning:toml-char-array-string-escape

Conversation

@pjfanning

Copy link
Copy Markdown
Member

_writeStringImpl(int, char[], int, int) reads text[offset + len] instead of text[offset + i] in the escaped basic-string branch. So writeString(char[], int, int) with any value containing a character that needs escaping (", \, control chars) either writes the wrong characters (the one just past the range, repeated) or throws ArrayIndexOutOfBoundsException when the array has no slack after the range.

The String variant is unaffected — this only hits streaming users of the char[] overload, which is presumably why it went unnoticed (there were no tests for it).

Spotted while working on #725. One-line fix plus a regression test that checks the char[] output equals the String output and reads back correctly. Affects all branches from 2.18 through 3.x.

🤖 Generated with Claude Code

@cowtowncoder

Copy link
Copy Markdown
Member

Let's start winding down 2.18 branch and only backport security fixes. 2.21 may be targeted for correctness bugs like this one.

… needed

`_writeStringImpl(int, char[], int, int)` read `text[offset + len]` instead
of `text[offset + i]` in the escaped basic-string branch, so any `char[]`
value containing a character that needs escaping (quote, backslash, control
char) was written with the wrong characters, or threw
`ArrayIndexOutOfBoundsException` when the array had no trailing slack.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pjfanning
pjfanning force-pushed the toml-char-array-string-escape branch from be38036 to f781651 Compare September 13, 2026 15:34
@pjfanning
pjfanning changed the base branch from 2.18 to 2.21 September 13, 2026 15:34
@pjfanning

Copy link
Copy Markdown
Member Author

retargeted to 2.21

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.

2 participants