commit 0f1483430dd0e9d50e21770a87d5052f4fe4fa65
parent 725ee335ec2d0247bf1959bb9e38ca94d572a672
Author: lash <dev@holbrook.no>
Date: Fri, 31 Mar 2023 20:23:45 +0100
implement size constraint on value
Diffstat:
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/go/state/state.go b/go/state/state.go
@@ -66,7 +66,13 @@ func(st *State) Down(input string) {
st.ExecPath = append(st.ExecPath, input)
}
-func(st *State) Add(key string, value string, sizeHint uint32) error {
+func(st *State) Add(key string, value string, sizeHint uint16) error {
+ if sizeHint > 0 {
+ l := uint16(len(value))
+ if l > sizeHint {
+ return fmt.Errorf("value length %v exceeds value size limit %v", l, sizeHint)
+ }
+ }
checkFrame := st.frameOf(key)
if checkFrame > -1 {
return fmt.Errorf("key %v already defined in frame %v", key, checkFrame)
@@ -78,7 +84,6 @@ func(st *State) Add(key string, value string, sizeHint uint32) error {
log.Printf("add key %s value size %v", key, sz)
st.Cache[len(st.Cache)-1][key] = value
st.CacheUseSize += sz
- _ = sizeHint
return nil
}
diff --git a/go/vm/vm.go b/go/vm/vm.go
@@ -118,7 +118,7 @@ func RunCatch(instruction []byte, st state.State, rs resource.Fetcher, ctx conte
return st, instruction, err
}
_ = tail
- st.Add(head, r, uint32(len(r)))
+ st.Add(head, r, 0)
return st, []byte{}, nil
}
@@ -141,15 +141,15 @@ func RunLoad(instruction []byte, st state.State, rs resource.Fetcher, ctx contex
if !st.Check(head) {
return st, instruction, fmt.Errorf("key %v already loaded", head)
}
- sz := uint32(tail[0])
+ sz := uint16(tail[0])
tail = tail[1:]
r, err := refresh(head, tail, rs, ctx)
if err != nil {
return st, tail, err
}
- st.Add(head, r, sz)
- return st, tail, nil
+ err = st.Add(head, r, sz)
+ return st, tail, err
}
func RunReload(instruction []byte, st state.State, rs resource.Fetcher, ctx context.Context) (state.State, []byte, error) {