Merge pull request #18226 from duglin/Issue18170
Fix for zero-sized layers
This commit is contained in:
commit
e345d791f4
2 changed files with 15 additions and 4 deletions
|
@ -128,7 +128,13 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
|
||||||
p := pools.BufioReader32KPool
|
p := pools.BufioReader32KPool
|
||||||
buf := p.Get(archive)
|
buf := p.Get(archive)
|
||||||
bs, err := buf.Peek(10)
|
bs, err := buf.Peek(10)
|
||||||
if err != nil {
|
if err != nil && err != io.EOF {
|
||||||
|
// Note: we'll ignore any io.EOF error because there are some odd
|
||||||
|
// cases where the layer.tar file will be empty (zero bytes) and
|
||||||
|
// that results in an io.EOF from the Peek() call. So, in those
|
||||||
|
// cases we'll just treat it as a non-compressed stream and
|
||||||
|
// that means just create an empty layer.
|
||||||
|
// See Issue 18170
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,11 +216,16 @@ func TestUntarPathWithInvalidDest(t *testing.T) {
|
||||||
invalidDestFolder := path.Join(tempFolder, "invalidDest")
|
invalidDestFolder := path.Join(tempFolder, "invalidDest")
|
||||||
// Create a src file
|
// Create a src file
|
||||||
srcFile := path.Join(tempFolder, "src")
|
srcFile := path.Join(tempFolder, "src")
|
||||||
_, err = os.Create(srcFile)
|
tarFile := path.Join(tempFolder, "src.tar")
|
||||||
|
os.Create(srcFile)
|
||||||
|
os.Create(invalidDestFolder) // being a file (not dir) should cause an error
|
||||||
|
cmd := exec.Command("/bin/sh", "-c", "tar cf "+tarFile+" "+srcFile)
|
||||||
|
_, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Fail to create the source file")
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = UntarPath(srcFile, invalidDestFolder)
|
|
||||||
|
err = UntarPath(tarFile, invalidDestFolder)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("UntarPath with invalid destination path should throw an error.")
|
t.Fatalf("UntarPath with invalid destination path should throw an error.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue