From e4a8af9b5bc6a59d781dd2dc020994d6c12fba52 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Fri, 8 Dec 2023 18:36:33 +0100 Subject: [PATCH] fix negative shift amount error, found with fuzzy testing :) --- funcs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/funcs.go b/funcs.go index 0033113..4b116d4 100644 --- a/funcs.go +++ b/funcs.go @@ -457,12 +457,20 @@ func DefineFunctions() Funcalls { "<": NewFuncall( func(arg Numbers) R { + // Shift by negative number provibited, so check it. + // Note that we check agains uint64 overflow as well here + if arg[1] < 0 || uint64(arg[1]) > math.MaxInt64 { + return NewR(0, errors.New("negative shift amount")) + } return NewR(float64(int(arg[0])<": NewFuncall( func(arg Numbers) R { + if arg[1] < 0 || uint64(arg[1]) > math.MaxInt64 { + return NewR(0, errors.New("negative shift amount")) + } return NewR(float64(int(arg[0])>>int(arg[1])), nil) }, 2),