Skip to content

os.get_raw_stdin() truncates binary input at the first newline byte #3

Description

@hunterjsb

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions