You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(security): cap decompressed output to stop image/archive decompression bombs (#142)
A malicious image layer or build-context archive that compresses tiny but
expands to hundreds of GB could fill the HOST disk during pull/build (DoS) —
extraction streamed gzip/zstd/bzip2/xz into tar with no bound on decompressed
output. The sibling ADD-URL path already caps downloads at MAX_ADD_URL_BYTES
(512 MiB); the local-archive and layer paths had no equivalent.
- New `oci::limited_reader::LimitedReader`: a Read adapter that errors once a
byte budget is exceeded, plus `cap_from_env` for operator-tunable ceilings.
- extract_layer (registry pull): wrap the decoder, cap total decompressed bytes
(A3S_BOX_MAX_LAYER_BYTES, default 16 GiB). Refactored into a cap-parameterized
inner fn so the bomb path is testable without env races. Also surface the
underlying cause in the error (tar's Display alone hides the cap abort).
- extract_tar_to_dst (build ADD/COPY auto-extract): wrap every decoder branch
(tar/tar.gz/tar.bz2/tar.xz) with the cap (A3S_BOX_MAX_BUILD_EXTRACT_BYTES,
default 4 GiB) — restoring parity with the already-capped ADD-URL path.
Defaults are generous (no realistic legit single layer/archive hits them) and
env-tunable; a bomb (100s of GB–PB) is bounded and aborts with a clear error.
Tests: LimitedReader unit tests (errors past cap / passes under); extract_layer
bomb test asserts a 64 KiB member under a 4 KiB cap ABORTS and bounds bytes
written; generous-cap test confirms no regression. Neuter-verified on the KVM
server (dropping the wrap makes the bomb test FAIL: got Ok). fmt + clippy clean.
Severity: HIGH for build ADD (build farms / hosted build APIs run untrusted
Dockerfiles), MEDIUM for layer pull (malicious-image precondition).
Co-authored-by: Roy Lin <roylin@a3s.box>
0 commit comments