Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oci: unpack: slurp up raw layer stream before Close() #360

Merged
merged 3 commits into from
Mar 30, 2021

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Feb 18, 2021

It's possible there's some trailing bytes after the gzip stream (which
truth be told, probably shouldn't be there), so in order to avoid
spurious errors on layer unpacking with slightly-broken images, just
slurp up that data.

But we should output logging information since this indicates that the
original image builder probably has a bug of some kind.

We also add code to slurp trailing bytes in VerifiedReadCloser.Close()
This is to ensure that we handle both good and bad cases sanely --
namely, that we always are digesting the full blob when Close() is
called. This avoids us producing intermittent errors if blobs have extra
trailing bytes (such as garbage at the end of a gzip stream), as well as
hardening us against incorrect digests (though it should be noted this
case cannot be triggered without disabling size verification -- the size
verficiation we have already blocks this issue).

Fixes #358
Signed-off-by: Aleksa Sarai [email protected]

@cyphar
Copy link
Member Author

cyphar commented Feb 19, 2021

Hmmm, the failure is real but it comes from io.Copy returning io.EOF which should absolutely never happen. This only happens with the pgzip reader, so there's something really weird going on...

@cyphar
Copy link
Member Author

cyphar commented Feb 19, 2021

We need klauspost/pgzip#40 before we can do this.

@cyphar cyphar force-pushed the verified-reader-trailing-bytes branch from 1a1635d to 6e0a77f Compare March 11, 2021 07:14
@tych0
Copy link
Member

tych0 commented Mar 25, 2021

FWIW, this LGTM whenever all the stuff you need to land lands, feel free to merge.

@cyphar
Copy link
Member Author

cyphar commented Mar 29, 2021

Thanks, I might just merge this as-is since the pgzip stuff isn't actually necessary now that I've implemented it by just copying from the actual file stream.

@tych0
Copy link
Member

tych0 commented Mar 29, 2021 via email

cyphar added 2 commits March 30, 2021 04:07
This is to ensure that we handle both good and bad cases sanely --
namely, that we always are digesting the *full* blob when Close() is
called. This avoids us producing intermittent errors if blobs have extra
trailing bytes (such as garbage at the end of a gzip stream), as well as
hardening us against incorrect digests (though it should be noted this
case cannot be triggered without disabling size verification -- the size
verficiation we have already blocks this issue).

Signed-off-by: Aleksa Sarai <[email protected]>
It's possible there's some trailing bytes after the gzip stream (which
truth be told, probably shouldn't be there), so in order to avoid
spurious errors on layer unpacking with slightly-broken images, just
slurp up that data.

But we should output logging information since this indicates that the
original image builder probably has a bug of some kind.

Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar cyphar force-pushed the verified-reader-trailing-bytes branch from 6e0a77f to 6353208 Compare March 29, 2021 17:17
@cyphar
Copy link
Member Author

cyphar commented Mar 29, 2021

LGTM.

@cyphar cyphar force-pushed the verified-reader-trailing-bytes branch 2 times, most recently from 3c9687b to b7f13af Compare March 29, 2021 17:26
Since we are reading blobs we should definitely be returning errors from
the lookup.

Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar cyphar force-pushed the verified-reader-trailing-bytes branch from b7f13af to 0976fbb Compare March 30, 2021 12:17
@codecov-io
Copy link

Codecov Report

Merging #360 (6e0a77f) into master (3d09b87) will decrease coverage by 1.00%.
The diff coverage is 63.15%.

❗ Current head 6e0a77f differs from pull request most recent head 0976fbb. Consider uploading reports for the commit 0976fbb to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #360      +/-   ##
==========================================
- Coverage   74.27%   73.27%   -1.01%     
==========================================
  Files          59       59              
  Lines        3079     3098      +19     
==========================================
- Hits         2287     2270      -17     
- Misses        463      498      +35     
- Partials      329      330       +1     
Impacted Files Coverage Δ
oci/layer/unpack.go 59.33% <16.66%> (-1.78%) ⬇️
pkg/hardening/verified_reader.go 84.12% <84.61%> (-3.88%) ⬇️
pkg/testutils/ftimes_unix.go 0.00% <0.00%> (-100.00%) ⬇️
pkg/testutils/mount_linux.go 0.00% <0.00%> (-33.34%) ⬇️
pkg/fseval/fseval_default.go 61.53% <0.00%> (-26.93%) ⬇️
oci/cas/dir/dir.go 57.62% <0.00%> (-3.39%) ⬇️
oci/casext/refname.go 61.29% <0.00%> (-3.23%) ⬇️
oci/layer/tar_extract.go 54.35% <0.00%> (-2.91%) ⬇️

@cyphar cyphar closed this in 07fa845 Mar 30, 2021
@cyphar cyphar merged commit 07fa845 into opencontainers:master Mar 30, 2021
@cyphar cyphar deleted the verified-reader-trailing-bytes branch March 30, 2021 12:19
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.

Question: unpack: reader size mismatch discarding trailing archive bits
3 participants