import_test.go 1014 B

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