From 7ad940844c0c82447aa40777451da9fb72a2c3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 23 Oct 2024 11:31:41 +0200 Subject: [PATCH] selector: disallow backward slicing --- pkg/policy/selector/selector.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/policy/selector/selector.go b/pkg/policy/selector/selector.go index 09d6dc4..859e2bf 100644 --- a/pkg/policy/selector/selector.go +++ b/pkg/policy/selector/selector.go @@ -344,9 +344,10 @@ func resolveSliceIndices(slice []int64, length int64) (start int64, end int64) { end = length + slice[1] } - // TODO: is backward iteration allowed? - // if yes, we need to return a +1 or -1 "step" - // if no, we need to error + if start >= end { + // backward iteration is not allowed, shortcut to an empty result + start, end = 0, 0 + } return start, end }