github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration/image/import_test.go (about)

     1  package image // import "github.com/docker/docker/integration/image"
     2  
     3  import (
     4  	"archive/tar"
     5  	"bytes"
     6  	"context"
     7  	"io"
     8  	"runtime"
     9  	"strings"
    10  	"testing"
    11  
    12  	"github.com/docker/docker/api/types"
    13  	"github.com/docker/docker/testutil"
    14  	"github.com/docker/docker/testutil/daemon"
    15  	"gotest.tools/v3/assert"
    16  	"gotest.tools/v3/skip"
    17  )
    18  
    19  // Ensure we don't regress on CVE-2017-14992.
    20  func TestImportExtremelyLargeImageWorks(t *testing.T) {
    21  	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
    22  	skip.If(t, runtime.GOARCH == "arm64", "effective test will be time out")
    23  	skip.If(t, testEnv.OSType == "windows", "TODO enable on windows")
    24  	t.Parallel()
    25  
    26  	// Spin up a new daemon, so that we can run this test in parallel (it's a slow test)
    27  	d := daemon.New(t)
    28  	d.Start(t)
    29  	defer d.Stop(t)
    30  
    31  	client := d.NewClientT(t)
    32  
    33  	// Construct an empty tar archive with about 8GB of junk padding at the
    34  	// end. This should not cause any crashes (the padding should be mostly
    35  	// ignored).
    36  	var tarBuffer bytes.Buffer
    37  
    38  	tw := tar.NewWriter(&tarBuffer)
    39  	err := tw.Close()
    40  	assert.NilError(t, err)
    41  	imageRdr := io.MultiReader(&tarBuffer, io.LimitReader(testutil.DevZero, 8*1024*1024*1024))
    42  	reference := strings.ToLower(t.Name()) + ":v42"
    43  
    44  	_, err = client.ImageImport(context.Background(),
    45  		types.ImageImportSource{Source: imageRdr, SourceName: "-"},
    46  		reference,
    47  		types.ImageImportOptions{})
    48  	assert.NilError(t, err)
    49  }