github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/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 "testing" 10 11 "github.com/docker/docker/api/types" 12 "github.com/docker/docker/internal/testutil" 13 "gotest.tools/skip" 14 ) 15 16 // Ensure we don't regress on CVE-2017-14992. 17 func TestImportExtremelyLargeImageWorks(t *testing.T) { 18 skip.If(t, runtime.GOARCH == "arm64", "effective test will be time out") 19 skip.If(t, testEnv.OSType == "windows", "TODO enable on windows") 20 21 defer setupTest(t)() 22 client := testEnv.APIClient() 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 }