Skip to content

Commit

Permalink
fix length check per-kind bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiobozzo committed Sep 16, 2024
1 parent ad03154 commit 7376256
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions capability/policy/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,24 @@ func resolve(sel Selector, subject ipld.Node, at []string) (ipld.Node, []ipld.No
}
} else {
slice := seg.Slice()
var start, end int64
var start, end, length int64
switch cur.Kind() {
case datamodel.Kind_List:
start, end = resolveSliceIndices(slice, cur.Length())
length = cur.Length()
start, end = resolveSliceIndices(slice, length)
case datamodel.Kind_Bytes:
b, _ := cur.AsBytes()
start, end = resolveSliceIndices(slice, int64(len(b)))
length = int64(len(b))
start, end = resolveSliceIndices(slice, length)
case datamodel.Kind_String:
str, _ := cur.AsString()
start, end = resolveSliceIndices(slice, int64(len(str)))
length = int64(len(str))
start, end = resolveSliceIndices(slice, length)
default:
return nil, nil, newResolutionError(fmt.Sprintf("can not slice on kind: %s", kindString(cur)), at)
}

if start < 0 || end < start {
if start < 0 || end < start || end > length {
if seg.Optional() {
cur = nil
} else {
Expand Down

0 comments on commit 7376256

Please sign in to comment.