Skip to content

Commit e2e582e

Browse files
committed
check addresses for 0-size MemoryCopy
1 parent 993f4c3 commit e2e582e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/Wasm/Exec/Eval.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,16 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do
497497
Right () -> k vs' es
498498
Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es)
499499

500+
(MemoryCopy, I32 0 : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do
501+
inst <- getFrameInst
502+
mem <- lift $ memory inst (0 @@ at)
503+
let addrs = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src]
504+
eres <- lift $ lift $ runExceptT $
505+
mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) addrs
506+
case eres of
507+
Right _ -> k vs' es
508+
Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es)
509+
500510
(MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do
501511
inst <- getFrameInst
502512
mem <- lift $ memory inst (0 @@ at)

0 commit comments

Comments
 (0)