hluk run: non-UTF-8 bytes in guest stdout reach the host as U+FFFD

Aperta
#293 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@enilsen16 ci sta già lavorando.

Dal 2/12/2026.

  • #307 di @enilsen16 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend, cli

Direzione di ricerca

Find the write host function and trace how Console echoes guest output through GuestOutput and Console::emit; the issue names these entry points but no file paths. First inspect the raw-byte handling and the captured-output path (take_output / drain_output). Add a regression test based on the provided printf '\377\376x' repro; done means the CLI preserves those bytes while captured output remains a String.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Bug: hluk run replaces non-UTF-8 bytes in guest stdout with U+FFFD

What happens

A guest program that writes bytes that aren't UTF-8 to stdout doesn't get those bytes through to the host's stdout. Each invalid byte arrives as U+FFFD (ef bf bd).

Repro (hluk 0.21.0, x86_64 Linux, GitHub Actions runner with KVM)

Inside the guest, the bytes are intact:

$ hluk run --runtime bash --exec "printf '\377\376x' | od -An -tx1"
 ff fe 78

Piped out to the host, they're replaced:

$ hluk run --runtime bash --exec "printf '\377\376x'" | od -An -tx1
 ef bf bd ef bf bd 78

Expected: ff fe 78 in both cases.

Cause

The write host function receives raw bytes (its doc comment says "Bytes, not a string: what a program writes need not be UTF-8"), but Console decodes them through GuestOutput before echoing them, and Console::emit writes the decoded text with print!/eprint!. GuestOutput documents that "bytes that are not UTF-8 read as U+FFFD", so the replacement looks intended for the captured text. For the echo to the CLI's own stdout and stderr, though, it means any binary output can't get through: gzip -c, tar c, images, protobuf, or a program printing Latin-1.

Proposed fix

When echo is on, write the guest's bytes to the host's stdout/stderr as they are (std::io::stdout().write_all(&bytes) plus flush), and keep decoding only for the captured output (take_output / drain_output), so the library API stays String and doesn't change. Two notes:

  • A failed write to stdout currently panics through print!, which is what makes hluk run | head -1 end with its reader. The byte path would keep that behaviour.
  • A character split across two writes needs no special handling in the echo path, because the bytes simply go out in order.

A bytes accessor for captured output (next to take_output) could be a separate follow-up if that's wanted.

I'm happy to send a PR for the echo-path change, with a test along the lines of the repro above, if this approach sounds right to you.

Lingua principale
Rust
Stelle
77
Fork
14
Merge medio
2g 1h
PR unite (30g)
24

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hyperlight-dev/hyperlight-unikraft

Tutte le issue di hyperlight-dev/hyperlight-unikraft

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.