Skip to content

cli/context/store: cap tls file size on zip import#6934

Open
texasich wants to merge 1 commit intodocker:masterfrom
texasich:6917-tls-import-size-cap
Open

cli/context/store: cap tls file size on zip import#6934
texasich wants to merge 1 commit intodocker:masterfrom
texasich:6917-tls-import-size-cap

Conversation

@texasich
Copy link
Copy Markdown

  • What I did

Wrap the io.ReadAll call for tls/* entries in importZip with the existing limitedReader, and add a fast-fail check against zf.UncompressedSize64 before opening the entry. Fixes #6917.

  • How I did it

The meta.json branch a few lines above already uses &limitedReader{R: f, N: maxAllowedFileSizeToImport}; the tls/ branch was still calling io.ReadAll(f) directly, which is unbounded after flate has decompressed. A compressed archive that fits under the outer 10 MiB cap can trivially decompress to multi-GB TLS entries and take the CLI out with an OOM.

Primary guard is the header check: if UncompressedSize64 exceeds the cap we bail out before calling zf.Open(), so no decompression happens at all for a well-formed zip bomb. The limitedReader wrapper stays as defense-in-depth for the case where the header lies about the declared size.

  • How to verify it

Added TestImportZipTLSTooLarge in cli/context/store/store_test.go: it builds an in-memory zip whose tls/docker/ca.pem entry is 2 * maxAllowedFileSizeToImport zero bytes (compresses to ~10 KiB, so the outer archive limit is not what's catching it), and asserts that Import rejects it with the expected error. Also ran go vet and go build on linux and windows.

Local go test ./cli/context/store/ passes aside from an unrelated pre-existing TestImportZip TempDir cleanup flake on Windows (open handle on test.zip), which reproduces on master without these changes.

  • Description for the changelog

Reject oversized TLS entries in docker context import of zip archives to prevent OOM from zip bombs.

`io.ReadAll(f)` on the decompressed tls/* entries was unbounded, so a
zip whose compressed archive is within the 10 MiB outer cap could still
decompress to multi-gigabyte TLS files and OOM the CLI. The meta.json
branch right above already wraps its reader in limitedReader, this just
mirrors it for the tls branch.

Also fast-fails on the advertised UncompressedSize64 before calling
zf.Open, so a well-formed zip bomb is rejected without any decompression
at all. limitedReader still guards the stream in case the header lies.

Fixes docker#6917

Signed-off-by: texasich <texasich@users.noreply.github.com>
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.

docker context import TLS Entry Handling results in OOM

1 participant