Skip to content

Commit f8bc2e0

Browse files
committed
fix incorrect usage of json.NewDecoder
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 80518e2 commit f8bc2e0

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

cache/remotecache/s3/s3.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ func (s3Client *s3Client) getManifest(ctx context.Context, key string, config *v
408408
if err := decoder.Decode(config); err != nil {
409409
return false, errors.WithStack(err)
410410
}
411+
if _, err := decoder.Token(); !errors.Is(err, io.EOF) {
412+
return false, errors.Errorf("unexpected data after JSON object")
413+
}
411414

412415
return true, nil
413416
}

executor/runcexecutor/executor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,13 @@ func (w *runcExecutor) Exec(ctx context.Context, id string, process executor.Pro
422422
defer f.Close()
423423

424424
spec := &specs.Spec{}
425-
if err := json.NewDecoder(f).Decode(spec); err != nil {
425+
dec := json.NewDecoder(f)
426+
if err := dec.Decode(spec); err != nil {
426427
return err
427428
}
429+
if _, err := dec.Token(); !errors.Is(err, io.EOF) {
430+
return errors.Errorf("unexpected data after JSON spec object")
431+
}
428432

429433
if process.Meta.User != "" {
430434
uid, gid, sgids, err := oci.GetUser(state.Rootfs, process.Meta.User)

exporter/attestation/unbundle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package attestation
33
import (
44
"context"
55
"encoding/json"
6+
"io"
67
"os"
78
"path"
89
"strings"
@@ -141,6 +142,9 @@ func unbundle(root string, bundle exporter.Attestation) ([]exporter.Attestation,
141142
if err := dec.Decode(&stmt); err != nil {
142143
return nil, errors.Wrap(err, "cannot decode in-toto statement")
143144
}
145+
if _, err := dec.Token(); !errors.Is(err, io.EOF) {
146+
return nil, errors.New("in-toto statement is not a single JSON object")
147+
}
144148
if bundle.InToto.PredicateType != "" && stmt.PredicateType != bundle.InToto.PredicateType {
145149
return nil, errors.Errorf("bundle entry %s does not match required predicate type %s", stmt.PredicateType, bundle.InToto.PredicateType)
146150
}

0 commit comments

Comments
 (0)