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

generateinsertlayer: ensure that we close the tarwriter #534

Merged
merged 3 commits into from
Feb 22, 2024

Conversation

mikemccracken
Copy link
Contributor

This fixes #436.

I added a test that shows the issue - the commit with the fix has the full explanation, repeated here:

generatelayer closes the tarwriter, but generateinsertlayer forgets to.

Closing the tarwriter writes the required footer of 1k of zeros.

This results in tar files that are complete but invalid, and different
reading tools will behave differently:

  • bsdtar doesn't complain and exits 0
  • gnu tar (and security scanning tools that use it) will exit 2 with an
    unexpected EOF message
  • python's tarfile library will raise an Unexpected EOF error
  • golang's archive/tar library can raise an unexpected EOF error, but
    for some files created by generateinsertlayer, it just raises a
    plain EOF error, which means golang based tools generally ignore this
    and work fine, this includes umoci.

@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (909d140) 73.44% compared to head (7bb2940) 73.34%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #534      +/-   ##
==========================================
- Coverage   73.44%   73.34%   -0.11%     
==========================================
  Files          60       60              
  Lines        4891     4895       +4     
==========================================
- Hits         3592     3590       -2     
- Misses        940      944       +4     
- Partials      359      361       +2     
Files Coverage Δ
oci/layer/generate.go 64.48% <70.00%> (-1.54%) ⬇️

... and 1 file with indirect coverage changes

@tych0
Copy link
Member

tych0 commented Feb 22, 2024

Everything looks good to me, except you have,

(cherry picked from commit 3f53b10037f03d01412b5b0eb9e50a0053b7a156)

in your commit message, which is a mystery hash?

generatelayer closes the tarwriter, but generateinsertlayer forgets to.

Closing the tarwriter writes the required footer of 1k of zeros.

This results in tar files that are complete but invalid, and different
reading tools will behave differently:

- bsdtar doesn't complain and exits 0
- gnu tar (and security scanning tools that use it) will exit 2 with an
unexpected EOF message
- python's tarfile library will raise an Unexpected EOF error
- golang's archive/tar library can raise an unexpected EOF error, but
  for some files created by generateinsertlayer, it just raises a
  plain EOF error, which means golang based tools generally ignore this
  and work fine, this includes umoci.

Signed-off-by: Michael McCracken <[email protected]>
This warning is a little confusing when err is nil,
and doesn't add any info in that case. Let's clean that up.

Signed-off-by: Michael McCracken <[email protected]>
add a check to image-verify to ensure that all generated tar blobs are
valid and do not cause gnu tar to exit nonzero

add an insert test that adds a very small file to trigger unexpected EOF
in the case where GenerateInsertLayer forgets to close the TarWriter.

Signed-off-by: Michael McCracken <[email protected]>
@tych0 tych0 force-pushed the 2024.02.15/tardebug branch from 831be38 to 7bb2940 Compare February 22, 2024 02:26
@tych0
Copy link
Member

tych0 commented Feb 22, 2024

I just cleaned it up, will merge once that all passes CI

Copy link
Member

@cyphar cyphar left a comment

Choose a reason for hiding this comment

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

LGTM, good catch!

local ocidir="$@"
# test that each generated targz file is valid according to gnutar:
for f in $(ls $ocidir/blobs/sha256/); do
file $ocidir/blobs/sha256/$f | grep "gzip" || {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It would be nice if this check was more "strictly correct" (i.e. it actually detected if the file was actually a tar archive rather than a gzip stream) but given this is just for tests that's not too important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree... I actually thought maybe the right thing was to have the oci-image-tool do this validation, but that seems to be abandoned.
Is there a different tool for standards validation out there somewhere that we should move this to?
Given the recent changes with artifacts, etc, it is probably extra stale now.

Copy link
Member

Choose a reason for hiding this comment

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

There were discussions about moving the image-validation infrastructure to umoci, but nothing has happened with regards to that topic since then. I can take a look at doing this after I do an umoci 0.5 release.

@tych0 tych0 merged commit fb2e46d into opencontainers:main Feb 22, 2024
16 checks passed
@mikemccracken
Copy link
Contributor Author

Everything looks good to me, except you have,

(cherry picked from commit 3f53b10037f03d01412b5b0eb9e50a0053b7a156)

in your commit message, which is a mystery hash?

d'oh- thanks for taking care of this, that hash was a commit on top of the stacker fork of umoci, I should've cleaned up the message.

Thanks for the quick review guys!

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.

images created using umoci/layer can include layers that are invalid tar files
4 participants