better bounds check for table.get and table.set

This commit is contained in:
Ilya Rezvov
2023-08-21 21:11:39 -06:00
parent ea50c54900
commit 9f17885106
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -986,7 +986,7 @@ eval budget store FunctionInstance { funcType, moduleInstance, code = Function {
RF fnRef -> fnRef RF fnRef -> fnRef
v -> error "Impossible due to validation" v -> error "Impossible due to validation"
els <- readIORef items els <- readIORef items
if dst > MVector.length els if dst >= MVector.length els
then return Trap then return Trap
else do else do
MVector.unsafeWrite els dst (fromIntegral <$> val) MVector.unsafeWrite els dst (fromIntegral <$> val)
@@ -996,7 +996,7 @@ eval budget store FunctionInstance { funcType, moduleInstance, code = Function {
let TableInstance { t = TableType _ et, items } = tableInstances store ! tableAddr let TableInstance { t = TableType _ et, items } = tableInstances store ! tableAddr
let dst = fromIntegral offset let dst = fromIntegral offset
els <- readIORef items els <- readIORef items
if dst > MVector.length els if dst >= MVector.length els
then return Trap then return Trap
else do else do
v <- MVector.unsafeRead els dst v <- MVector.unsafeRead els dst
+1 -1
View File
@@ -19,7 +19,7 @@ main = do
files <- files <-
filter (not . List.isPrefixOf "simd") . filter (List.isSuffixOf ".wast") filter (not . List.isPrefixOf "simd") . filter (List.isSuffixOf ".wast")
<$> Directory.listDirectory "tests/spec" <$> Directory.listDirectory "tests/spec"
let files = ["table_get.wast"] -- let files = ["table_get.wast"]
scriptTestCases <- (`mapM` files) $ \file -> do scriptTestCases <- (`mapM` files) $ \file -> do
test <- LBS.readFile ("tests/spec/" ++ file) test <- LBS.readFile ("tests/spec/" ++ file)
return $ testCase file $ do return $ testCase file $ do