github.com/ttys3/engine@v17.12.1-ce-rc2+incompatible/integration/image/import_test.go (about)

     1  package image
     2  
     3  import (
     4  	"archive/tar"
     5  	"bytes"
     6  	"context"
     7  	"io"
     8  	"runtime"
     9  	"testing"
    10  
    11  	"github.com/docker/docker/api/types"
    12  	"github.com/docker/docker/integration/util/request"
    13  	"github.com/docker/docker/internal/testutil"
    14  )
    15  
    16  // Ensure we don't regress on CVE-2017-14992.
    17  func TestImportExtremelyLargeImageWorks(t *testing.T) {
    18  	if runtime.GOARCH == "arm64" {
    19  		t.Skip("effective test will be time out")
    20  	}
    21  
    22  	client := request.NewAPIClient(t)
    23  
    24  	// Construct an empty tar archive with about 8GB of junk padding at the
    25  	// end. This should not cause any crashes (the padding should be mostly
    26  	// ignored).
    27  	var tarBuffer bytes.Buffer
    28  
    29  	tw := tar.NewWriter(&tarBuffer)
    30  	if err := tw.Close(); err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	imageRdr := io.MultiReader(&tarBuffer, io.LimitReader(testutil.DevZero, 8*1024*1024*1024))
    34  
    35  	_, err := client.ImageImport(context.Background(),
    36  		types.ImageImportSource{Source: imageRdr, SourceName: "-"},
    37  		"test1234:v42",
    38  		types.ImageImportOptions{})
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  }