implement size constraint on value
This commit is contained in:
parent
725ee335ec
commit
0f1483430d
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user