Repository navigation
Conversation
vszakats
reviewed
Oct 21, 2026
| JSON write-out preserves a large escaped header value | ||
| </name> | ||
| <command option="no-output"> | ||
| http://%HOSTIP:%HTTPPORT/%TESTNUMBER -sS -w '%{header_json}\n' -o %LOGDIR/%TESTNUMBER.out |
Member
There was a problem hiding this comment.
I suggest integrating this into an existing test.
Contributor
Author
There was a problem hiding this comment.
Integrated into test 1671 and removed test 2120.
Huge
force-pushed
the
fix/json-large-writeout-strings
branch
from
October 21, 2026 12:39
f536b5f to
1255ac0
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Per-byte writes regress unbuffered stderr performance; bounded stack buffering would preserve the benefits without that regression.
1 open issue
What changed in this PR
Removes the write-out JSON string buffer limit so large response headers remain intact and produce valid JSON.
Changes:
- Shares per-byte escaping between buffered and streamed output.
- Streams JSON strings without a dynamic buffer.
- Extends test 1671 with a large escaped header value.
| File | Description |
|---|---|
| tests/data/test1671 | Adds regression coverage for large escaped headers. |
| src/tool_writeout_json.c | Extracts shared escaping and streams JSON strings. |
Review effort: Balanced
bagder
requested changes
Oct 23, 2026
Move the escaping of one byte, or of one valid UTF-8 sequence, out of jsonquoted() into a helper so that a caller without a dynbuf can reuse it. The output is unchanged.
jsonWriteString() collected the escaped string in a dynbuf, which needs a
size limit and can fail to allocate. Both cases lose the value and leave
an empty string behind, so %{header_json} could output ["small",] for a
header that needs more than 100000 bytes escaped.
Escape into a small stack buffer and write it whenever it is full. There
is no limit to pick and nothing left to fail, and an unbuffered stream
like stderr still gets one write per chunk rather than one per byte.
Also verify large escaped headers in test 1671.
Reported-by: BS.ehlas.cz
Huge
force-pushed
the
fix/json-large-writeout-strings
branch
from
October 25, 2026 06:34
1255ac0 to
e00c1c9
Compare
Member
|
Thanks, merged! |
vszakats
reviewed
Oct 27, 2026
bagder
added a commit
that referenced
this pull request
Oct 28, 2026
Follow-up to 705b02e Ref: #23535 (comment) Closes #23638
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.

jsonWriteString()capped the escaped string at 100000 bytes and collected it in adynbuf. For a response header needing more than 100000 escaped bytes,%{header_json}dropped the value and left a trailing comma (e.g.["small",]), which is invalid JSON. A failed allocation lost the value the same way.Instead of picking a different limit or collecting large headers in memory, this:
jsonquoted()into a helperjsonescape(). The output of existing callers is unchanged.jsonWriteString()escape into a 128-byte stack buffer and write it to the stream whenever it is full.There is no size limit and no heap allocation, the quotes are always written, and an unbuffered stream such as stderr gets one write per chunk rather than one per byte. A UTF-8 sequence is never split between chunks. Test 1671 now verifies a large escaped header value.
Disclaimer: Found the issue by test-driving an LM-powered vulnerability scanner I work on heavily.