Skip to content

Commit

Permalink
fix incorrect usage of json.NewDecoder
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Jul 1, 2024
1 parent 80518e2 commit f8bc2e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cache/remotecache/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ func (s3Client *s3Client) getManifest(ctx context.Context, key string, config *v
if err := decoder.Decode(config); err != nil {
return false, errors.WithStack(err)
}
if _, err := decoder.Token(); !errors.Is(err, io.EOF) {
return false, errors.Errorf("unexpected data after JSON object")
}

return true, nil
}
Expand Down
6 changes: 5 additions & 1 deletion executor/runcexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,13 @@ func (w *runcExecutor) Exec(ctx context.Context, id string, process executor.Pro
defer f.Close()

spec := &specs.Spec{}
if err := json.NewDecoder(f).Decode(spec); err != nil {
dec := json.NewDecoder(f)
if err := dec.Decode(spec); err != nil {
return err
}
if _, err := dec.Token(); !errors.Is(err, io.EOF) {
return errors.Errorf("unexpected data after JSON spec object")
}

if process.Meta.User != "" {
uid, gid, sgids, err := oci.GetUser(state.Rootfs, process.Meta.User)
Expand Down
4 changes: 4 additions & 0 deletions exporter/attestation/unbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package attestation
import (
"context"
"encoding/json"
"io"
"os"
"path"
"strings"
Expand Down Expand Up @@ -141,6 +142,9 @@ func unbundle(root string, bundle exporter.Attestation) ([]exporter.Attestation,
if err := dec.Decode(&stmt); err != nil {
return nil, errors.Wrap(err, "cannot decode in-toto statement")
}
if _, err := dec.Token(); !errors.Is(err, io.EOF) {
return nil, errors.New("in-toto statement is not a single JSON object")
}
if bundle.InToto.PredicateType != "" && stmt.PredicateType != bundle.InToto.PredicateType {
return nil, errors.Errorf("bundle entry %s does not match required predicate type %s", stmt.PredicateType, bundle.InToto.PredicateType)
}
Expand Down

0 comments on commit f8bc2e0

Please sign in to comment.