Skip to content

fix: reject NUL characters in multi and stream output - #1347

Open
Nussu06 wants to merge 1 commit into
google:masterfrom
Nussu06:multi-output-nul-check
Open

Nussu06 wants to merge 1 commit into
google:masterfrom
Nussu06:multi-output-nul-check

Conversation

@Nussu06

@Nussu06 Nussu06 commented Oct 25, 2026

Copy link
Copy Markdown

Multi (-m) and stream (-y) results come back from the C API as NUL-terminated strings, which write_multi_output_files and libjsonnet++'s parseMultiOutput split on NUL, but manifestMulti and manifestStream never rejected U+0000, so with --string a NUL inside a value forges extra entries. For example { "report.txt": importstr "upload.txt" }, where upload.txt contains body\0../escaped.sh\0echo pwned, makes jsonnet -S -m out write out/../escaped.sh, a file name the program never produced, and jsonnet -S -y -e '["a\u0000b"]' emits two documents. File names, string-mode contents and stream documents containing NUL now raise a runtime error, since the format cannot represent them; JSON-mode output is unchanged because NUL is already escaped as \u0000 there, so only output that was previously corrupted is affected. Added test_cmd cases multi5, multi6 and yaml4, which fail before the change and pass after it, and make test passes.

The C API returns multi and stream results as NUL-terminated strings,
so a NUL inside a file name, a --string file content or a stream
document was read as a separator and produced extra entries. Raise a
runtime error instead, since the output format cannot represent it.

This branch has not been deployed

No deployments
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.

1 participant