From 37f52863156cb496b706f37d26d829b4cb2bf7e8 Mon Sep 17 00:00:00 2001 From: Fabio Bozzo Date: Mon, 16 Sep 2024 14:04:01 +0200 Subject: [PATCH] fix length check per-kind bug --- capability/policy/selector/selector.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/capability/policy/selector/selector.go b/capability/policy/selector/selector.go index 83c90e7..1d57718 100644 --- a/capability/policy/selector/selector.go +++ b/capability/policy/selector/selector.go @@ -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 {