import_test.go 1.4 KB

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