Skip to content

Reject EOF while seeking through a decompressor pipe - #38

Closed
Test-bot-cell wants to merge 2 commits into
bdrung:mainfrom
Test-bot-cell:codex/reject-truncated-pipe
Closed

Test-bot-cell wants to merge 2 commits into
bdrung:mainfrom
Test-bot-cell:codex/reject-truncated-pipe

Conversation

@Test-bot-cell

@Test-bot-cell Test-bot-cell commented Nov 11, 2026 •

Copy link
Copy Markdown

When a decompressor pipe ends before the cpio payload size declared in its header, ChildStdout::seek_forward loops forever: read returns zero and remaining never decreases. Return UnexpectedEof at that point, preserving the existing propagation of read errors.

The regression test uses a real child stdout pipe and covers a zero-length skip without consuming data, an exact-length skip, and EOF before the requested offset.

A minimal reproducer for 0.14.0 and the current main branch:

import gzip
from pathlib import Path
name = b"payload\0"
fields = [1, 0o100644, 0, 0, 1, 0, 4096, 0, 0, 0, 0, len(name), 0]
header = b"070701" + "".join(f"{field:08x}" for field in fields).encode() + name
header += b"\0" * (-len(header) % 4)
Path("truncated-payload.cpio.gz").write_bytes(gzip.compress(header + b"x" * 100, mtime=0))
timeout 2s 3cpio --examine --raw truncated-payload.cpio.gz

Before the fix, the command times out. With the fix it exits with status 1 and reports the missing 3996 bytes. A native Ubuntu package built from the same fix completed this check in 17 ms; valid bzip2, gzip, lz4, lzop, xz and zstd input and zstd extraction still passed.

Validation on main 505212c916b7fefa8b53c006daa351cfe26526c5 plus this change, using Rust 1.93.1:

  • RUSTFLAGS=-Dwarnings cargo test --locked --all: 118 unit tests, 38 CLI tests and 5 doctests passed, none ignored.
  • RUSTFLAGS=-Dwarnings cargo clippy --locked --all-targets --all-features: passed.
  • cargo fmt --all --check: passed.

The Ubuntu 26.04 CI runner uses sudo-rs, which ignores sudo -E. The root tests passed but wrote LLVM profiles outside the expected directory. The root runner now explicitly preserves LLVM_PROFILE_FILE; all nine CI jobs pass, including generation of the root coverage report. This changes no Rust code or test assertions.

The existing ISC license is retained.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.51%. Comparing base (505212c) to head (158d718).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
- Coverage   94.59%   94.51%   -0.09%     
==========================================
  Files          13       13              
  Lines        4092     4009      -83     
==========================================
- Hits         3871     3789      -82     
+ Misses        221      220       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the change addressing premature EOF during archive skips.

No open issues 🎉

What changed in this PR

This PR prevents archive processing from hanging when a decompressor pipe ends before the requested skip completes.

Changes:

  • Return UnexpectedEof when a read yields zero bytes during a pending skip, reporting the missing byte count and preserving existing read-error propagation.
  • Add a real child-stdout regression test covering zero-length skips without consuming data, exact-length skips, and premature EOF.
File Description
src/​seek_forward.rs Detects premature pipe EOF and adds regression coverage for skip boundary behavior.

Review effort: Balanced

@aozmekik aozmekik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this on a real initrd: the Ubuntu 26.04 runner's own /boot/initrd.img (46 MB, zstd), cut to 30, 60, 90 and 99% of its size. On main, --list and --examine hang on all four after zstd's "Read error (39) : premature end" (killed after 30 s). With this branch they exit 1 right away with "missing N bytes while seeking forward ...", and the untruncated initrd still lists fine.

I ran into this hang with the truncated initrd from LP #2157789 (see #39).

bdrung added a commit that referenced this pull request Nov 14, 2026
When a decompressor pipe ends before the cpio payload size declared in
its header, `ChildStdout::seek_forward` loops forever: `read` returns
zero and `remaining` never decreases.

Replace the manual read loop with `std::io::copy` into `std::io::sink()`
and return `ErrorKind::UnexpectedEof` if fewer than `offset` bytes were
consumed. This retains the `splice` optimization used by `std::io::copy`
on Linux pipes.

Add a test case similar to the minimal reproducer provided in
#38.
bdrung added a commit that referenced this pull request Nov 14, 2026
When a decompressor pipe ends before the cpio payload size declared in
its header, `ChildStdout::seek_forward` loops forever: `read` returns
zero and `remaining` never decreases.

Replace the manual read loop with `std::io::copy` into `std::io::sink()`
and return `ErrorKind::UnexpectedEof` if fewer than `offset` bytes were
consumed. This retains the `splice` optimization used by `std::io::copy`
on Linux pipes.

Add a test case similar to the minimal reproducer provided in
#38.
@bdrung

bdrung commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR. I converted your minimal reproducer into a test case and rewrote seek_forward to not need a loop any more.

@bdrung bdrung closed this Nov 14, 2026
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.

4 participants