import_test.go 1.3 KB

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