Skip to content

Conversation

@erikh
Copy link
Contributor

@erikh erikh commented Apr 2, 2017

Previously, this would effectively panic on any tar files because it was
expecting a gzip compressed file. This enforces that the +gzip media
type exists before enabling gzip decompression.

I also shimmed in some tests by appropriating some others.

Signed-off-by: Erik Hollensbe [email protected]

@erikh erikh changed the title image/manifest.go: handle tar files as layers appropriately image/manifest.go: handle bare tar files Apr 2, 2017
@cyphar
Copy link
Member

cyphar commented Apr 4, 2017

The thing is, layers now can be either uncompressed or compressed. Maybe you should look at the auto-detect-compression code here? Or we can just handle the two cases separately.

return errors.Wrap(err, "error creating gzip reader")

reader := r
if strings.HasSuffix(mediaType, "+gzip") {
Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry, you're already handling that. Oops.

@erikh
Copy link
Contributor Author

erikh commented Apr 4, 2017

So the thing about this patch that's weird is that now the images I generate, which use tar files, are validating fine against oci-image-tool. I think I did something wrong on my end.

However this patch does validate the media type and switch the reader accordingly so it may be worth keeping. I'll leave it to you.

@stevvooe
Copy link
Contributor

stevvooe commented Apr 6, 2017

@erikh I'd recommend auto-detecting compression to most compatible.

@erikh
Copy link
Contributor Author

erikh commented Apr 6, 2017

@stevvooe not entirely sure what you mean by this, do you mean reading the file header?

@stevvooe
Copy link
Contributor

stevvooe commented Apr 6, 2017

do you mean reading the file header?

Yes.

@erikh
Copy link
Contributor Author

erikh commented Apr 6, 2017 via email

@stevvooe
Copy link
Contributor

stevvooe commented Apr 7, 2017

@erikh I'm just trying to provide a practical approach that has worked for us in employing unpacking for manifests. If you want to over-validate, go ahead, but its much more flexible to autodetect the compression in practice and there isn't really downside to it. Erroring out will just frustrate people that can do nothing about it. It is much better to emit a warning and unpack the layer. As long as the digest matches, it is okay.

For the most part, this will matter as people "shallow convert" existing images to the OCI formats.

Mind you, this is the only exception where I would say go against the media type. In almost all other cases, you should be strict.

@erikh
Copy link
Contributor Author

erikh commented Apr 7, 2017

Fair enough. I will do that.

@coolljt0725
Copy link
Member

@erikh conflict, needs a rebase

@erikh
Copy link
Contributor Author

erikh commented Apr 11, 2017 via email

@erikh erikh force-pushed the fix-tar-files branch 2 times, most recently from e5fed5b to a7de4fc Compare April 19, 2017 14:09
@erikh
Copy link
Contributor Author

erikh commented Apr 19, 2017

PTAL and sorry for the wait.

This patch now:

  • detect compression and appropriately adjusts the reader, warning if it doesn't match the media type
  • proceeds to deal with the file anyway
  • has some tests for testing invalid stuff
  • also support for bzip compression in tests (I omitted xz but we could add that, I don't think it's in the spec?)

@erikh
Copy link
Contributor Author

erikh commented Apr 19, 2017

I'll clean things up; needs a bit of work still. I'll comment when ready.

@erikh erikh force-pushed the fix-tar-files branch 6 times, most recently from 4dd0d5b to 1d22ba9 Compare April 19, 2017 16:12
@erikh
Copy link
Contributor Author

erikh commented Apr 19, 2017

I'll look later. Test is failing in CI but not locally.

@erikh erikh force-pushed the fix-tar-files branch 5 times, most recently from 96e684f to 19293e0 Compare April 19, 2017 19:27
@erikh erikh force-pushed the fix-tar-files branch 14 times, most recently from 02304be to f9b29ec Compare April 20, 2017 05:40
…roblems

Additionally:

* Adjusted go test to use the -v flag to show debug statements
* Imported github.com/dsnet/compress/bzip2 for bzip2 compression
* Wrote several tests to test both valid and invalid media types

Signed-off-by: Erik Hollensbe <[email protected]>
@erikh
Copy link
Contributor Author

erikh commented Apr 20, 2017

ok, this is green now. PTAL.

Note I had to import github.com/dsnet/compress/bzip2 to implement bzip2 compression. the hold-up was my pipe implementation that called bzip2, which works locally but doesn't seem to on travis for some reason.

@erikh erikh changed the title image/manifest.go: handle bare tar files image/manifest.go: implement compression detection / mediatype validation Apr 20, 2017
@vbatts
Copy link
Member

vbatts commented Apr 24, 2017

LGTM

Approved with PullApprove

1 similar comment
@stevvooe
Copy link
Contributor

stevvooe commented Apr 24, 2017

LGTM

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit d7bda79 into opencontainers:master May 11, 2017
@xiekeyang xiekeyang mentioned this pull request Jun 29, 2017
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.

6 participants