Skip to content

Commit 26816ef

Browse files
committed
Merge remote-tracking branch 'upstream/main' into HEAD
2 parents 04620c2 + 2285497 commit 26816ef

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ let zero s = expect 0x00 s "zero byte expected"
222222

223223
let memop s =
224224
let align = u32 s in
225-
require (I32.le_u align 32l) s (pos s - 1) "malformed memop flags";
225+
require (I32.lt_u align 32l) s (pos s - 1) "malformed memop flags";
226226
let offset = u64 s in
227227
Int32.to_int align, offset
228228

test/core/align.wast

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,120 @@
864864
(assert_trap (invoke "store" (i32.const 65532) (i64.const -1)) "out of bounds memory access")
865865
;; No memory was changed
866866
(assert_return (invoke "load" (i32.const 65532)) (i32.const 0))
867+
868+
;; Test invalid alignment values that may cause overflow when parsed.
869+
;; These use the binary format, because it stores alignment as a base-2 exponent.
870+
871+
;; Signed 32-bit overflow
872+
(assert_invalid
873+
(module binary
874+
"\00asm" "\01\00\00\00"
875+
"\01\04\01\60\00\00" ;; Type section: 1 type
876+
"\03\02\01\00" ;; Function section: 1 function
877+
"\05\03\01\00\01" ;; Memory section: 1 memory
878+
"\0a\0a\01" ;; Code section: 1 function
879+
880+
;; function 0
881+
"\08\00"
882+
"\41\00" ;; i32.const 0
883+
"\28\1f\00" ;; i32.load offset=0 align=2**31
884+
"\1a" ;; drop
885+
"\0b" ;; end
886+
)
887+
"alignment must not be larger than natural"
888+
)
889+
890+
;; Unsigned 32-bit overflow
891+
(assert_malformed
892+
(module binary
893+
"\00asm" "\01\00\00\00"
894+
"\01\04\01\60\00\00" ;; Type section: 1 type
895+
"\03\02\01\00" ;; Function section: 1 function
896+
"\05\03\01\00\01" ;; Memory section: 1 memory
897+
"\0a\0a\01" ;; Code section: 1 function
898+
899+
;; function 0
900+
"\08\00"
901+
"\41\00" ;; i32.const 0
902+
"\28\20\00" ;; i32.load offset=0 align=2**32
903+
"\1a" ;; drop
904+
"\0b" ;; end
905+
)
906+
"malformed memop flags"
907+
)
908+
909+
;; 32-bit out of range
910+
(assert_malformed
911+
(module binary
912+
"\00asm" "\01\00\00\00"
913+
"\01\04\01\60\00\00" ;; Type section: 1 type
914+
"\03\02\01\00" ;; Function section: 1 function
915+
"\05\03\01\00\01" ;; Memory section: 1 memory
916+
"\0a\0a\01" ;; Code section: 1 function
917+
918+
;; function 0
919+
"\08\00"
920+
"\41\00" ;; i32.const 0
921+
"\28\21\00" ;; i32.load offset=0 align=2**33
922+
"\1a" ;; drop
923+
"\0b" ;; end
924+
)
925+
"malformed memop flags"
926+
)
927+
928+
;; Signed 64-bit overflow
929+
(assert_malformed
930+
(module binary
931+
"\00asm" "\01\00\00\00"
932+
"\01\04\01\60\00\00" ;; Type section: 1 type
933+
"\03\02\01\00" ;; Function section: 1 function
934+
"\05\03\01\00\01" ;; Memory section: 1 memory
935+
"\0a\0a\01" ;; Code section: 1 function
936+
937+
;; function 0
938+
"\08\00"
939+
"\41\00" ;; i32.const 0
940+
"\28\3f\00" ;; i32.load offset=0 align=2**63
941+
"\1a" ;; drop
942+
"\0b" ;; end
943+
)
944+
"malformed memop flags"
945+
)
946+
947+
;; Unsigned 64-bit overflow
948+
(assert_malformed
949+
(module binary
950+
"\00asm" "\01\00\00\00"
951+
"\01\04\01\60\00\00" ;; Type section: 1 type
952+
"\03\02\01\00" ;; Function section: 1 function
953+
"\05\03\01\00\01" ;; Memory section: 1 memory
954+
"\0a\0a\01" ;; Code section: 1 function
955+
956+
;; function 0
957+
"\08\00"
958+
"\41\00" ;; i32.const 0
959+
"\28\40\00" ;; i32.load offset=0 align=2**64
960+
"\1a" ;; drop
961+
"\0b" ;; end
962+
)
963+
"malformed memop flags"
964+
)
965+
966+
;; 64-bit out of range
967+
(assert_malformed
968+
(module binary
969+
"\00asm" "\01\00\00\00"
970+
"\01\04\01\60\00\00" ;; Type section: 1 type
971+
"\03\02\01\00" ;; Function section: 1 function
972+
"\05\03\01\00\01" ;; Memory section: 1 memory
973+
"\0a\0a\01" ;; Code section: 1 function
974+
975+
;; function 0
976+
"\08\00"
977+
"\41\00" ;; i32.const 0
978+
"\28\41\00" ;; i32.load offset=0 align=2**65
979+
"\1a" ;; drop
980+
"\0b" ;; end
981+
)
982+
"malformed memop flags"
983+
)

test/meta/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SHARED_MEM=false
22

33
# SpiderMonkey shell
4-
JSSHELL=~/mozilla-central/js/src/build-debug/dist/bin/js -e 'const WITH_SHARED_MEMORY=$(SHARED_MEM);' -f common.js
4+
#JSSHELL=~/mozilla-central/js/src/build-debug/dist/bin/js -e 'const WITH_SHARED_MEMORY=$(SHARED_MEM);' -f common.js
55

66
# Node.js
77
JSSHELL=./noderun.sh $(SHARED_MEM)

0 commit comments

Comments
 (0)