CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// Plan and execution must review the same bounded object, including when a
|
|
// file grows between its initial stat and the actual read.
|
|
func readCapabilityInput(path string) (json.RawMessage, error) {
|
|
if path == "" {
|
|
return json.RawMessage(`{}`), nil
|
|
}
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !info.Mode().IsRegular() || info.Size() > 1<<20 {
|
|
return nil, fmt.Errorf("input-file must be a regular JSON file of at most 1 MiB")
|
|
}
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
info, err = file.Stat()
|
|
if err != nil || !info.Mode().IsRegular() {
|
|
return nil, fmt.Errorf("input-file must remain a regular file")
|
|
}
|
|
data, err := io.ReadAll(io.LimitReader(file, (1<<20)+1))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(data) > 1<<20 {
|
|
return nil, fmt.Errorf("input-file exceeds 1 MiB")
|
|
}
|
|
var object map[string]json.RawMessage
|
|
if json.Unmarshal(data, &object) != nil || object == nil {
|
|
return nil, fmt.Errorf("input-file must contain one JSON object")
|
|
}
|
|
return data, nil
|
|
}
|