containerd/patch/0096-importer-stream-oci-layout-and-manifest.json.patch
2023-02-27 16:52:55 +08:00

49 lines
1.3 KiB
Diff

From d86db0de932912591e4a3884305547162b87f885 Mon Sep 17 00:00:00 2001
From: Samuel Karp <samuelkarp@google.com>
Date: Mon, 27 Feb 2023 15:02:01 +0800
Subject: [PATCH] importer: stream oci-layout and manifest.json
Signed-off-by: Samuel Karp <samuelkarp@google.com>
---
images/archive/importer.go | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/images/archive/importer.go b/images/archive/importer.go
index da83275..443b886 100644
--- a/images/archive/importer.go
+++ b/images/archive/importer.go
@@ -23,7 +23,6 @@ import (
"context"
"encoding/json"
"io"
- "io/ioutil"
"path"
"github.com/containerd/containerd/archive/compression"
@@ -192,15 +191,14 @@ func ImportIndex(ctx context.Context, store content.Store, reader io.Reader) (oc
return writeManifest(ctx, store, idx, ocispec.MediaTypeImageIndex)
}
+const (
+ kib = 1024
+ mib = 1024 * kib
+ jsonLimit = 20 * mib
+)
+
func onUntarJSON(r io.Reader, j interface{}) error {
- b, err := ioutil.ReadAll(r)
- if err != nil {
- return err
- }
- if err := json.Unmarshal(b, j); err != nil {
- return err
- }
- return nil
+ return json.NewDecoder(io.LimitReader(r, jsonLimit)).Decode(j)
}
func onUntarBlob(ctx context.Context, r io.Reader, store content.Ingester, size int64, ref string) (digest.Digest, error) {
--
2.33.0