Summary
os.get_raw_stdin() is documented/intended to read all of stdin as raw bytes, but it stops at the first newline (0x0A) — so any binary payload containing a newline byte is silently truncated. "Raw" reads should be line-agnostic.
Reproduction
import os
fn main() {
b := os.get_raw_stdin()
println('read ${b.len} bytes')
}
$ printf 'AB\nCDE' | v run rawstdin.v
read 3 bytes # expected: read 6 bytes
The input is 6 bytes (A B \n C D E); get_raw_stdin returns 3 (A B \n), discarding everything after the first newline.
Expected
All 6 bytes. get_raw_stdin should read to EOF regardless of newline bytes — that's the point of a raw read versus line-based input.
Impact
Silent data corruption for any binary data piped through stdin — protobuf/msgpack/image/compressed payloads routinely contain 0x0A. The failure is silent (no error), which makes it especially easy to ship.
Environment
V 0.5.2 5889122, Linux x86_64.
Note
Hit while piping encoded protobuf through stdin; worked around by reading from a file. Filing on the fork to track for upstream.
Summary
os.get_raw_stdin()is documented/intended to read all of stdin as raw bytes, but it stops at the first newline (0x0A) — so any binary payload containing a newline byte is silently truncated. "Raw" reads should be line-agnostic.Reproduction
The input is 6 bytes (
A B \n C D E);get_raw_stdinreturns 3 (A B \n), discarding everything after the first newline.Expected
All 6 bytes.
get_raw_stdinshould read to EOF regardless of newline bytes — that's the point of a raw read versus line-based input.Impact
Silent data corruption for any binary data piped through stdin — protobuf/msgpack/image/compressed payloads routinely contain
0x0A. The failure is silent (no error), which makes it especially easy to ship.Environment
V 0.5.2 5889122, Linux x86_64.Note
Hit while piping encoded protobuf through stdin; worked around by reading from a file. Filing on the fork to track for upstream.