This repository was archived by the owner on Nov 3, 2021. It is now read-only.
File tree 2 files changed +19
-12
lines changed 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -145,15 +145,16 @@ let store_packed sz mem a o v =
145
145
| _ -> raise Type
146
146
in storen mem a o n x
147
147
148
- let check_bounds mem a = if I64. ge_u a (bound mem) then raise Bounds
148
+ let check_bounds mem a = if I64. gt_u a (bound mem) then raise Bounds
149
149
150
150
let fill mem a v n =
151
151
let rec loop a n =
152
152
if n > 0l then begin
153
153
store_byte mem a v;
154
154
loop (Int64. add a 1L ) (Int32. sub n 1l )
155
155
end
156
- in check_bounds mem a; loop a n
156
+ in loop a n;
157
+ check_bounds mem Int64. (add a (of_int32 n))
157
158
158
159
let copy mem d s n =
159
160
let n' = Int64. of_int32 n in
@@ -163,10 +164,9 @@ let copy mem d s n =
163
164
store_byte mem d (load_byte mem s);
164
165
loop (Int64. add d dx) (Int64. add s dx) (Int32. sub n 1l ) dx
165
166
end
166
- in
167
- check_bounds mem d;
168
- check_bounds mem s;
169
- if overlap && s < d then
167
+ in (if overlap && s < d then
170
168
loop Int64. (add d (sub n' 1L )) Int64. (add s (sub n' 1L )) n (- 1L )
171
169
else
172
- loop d s n 1L
170
+ loop d s n 1L );
171
+ check_bounds mem (Int64. add d n');
172
+ check_bounds mem (Int64. add s n')
Original file line number Diff line number Diff line change 33
33
(assert_return (invoke " load8_u" (i32.const 0xff00 )) (i32.const 1 ))
34
34
(assert_return (invoke " load8_u" (i32.const 0xffff )) (i32.const 1 ))
35
35
36
- ;; Fail on out-of-bounds even if filling 0 bytes.
37
- (assert_trap (invoke " fill" (i32.const 0x10000 ) (i32.const 0 ) (i32.const 0 ))
36
+ ;; Succeed when writing 0 bytes at the end of the region.
37
+ (invoke " fill" (i32.const 0x10000 ) (i32.const 0 ) (i32.const 0 ))
38
+
39
+ ;; Fail on out-of-bounds when writing 0 bytes outside of memory.
40
+ (assert_trap (invoke " fill" (i32.const 0x10001 ) (i32.const 0 ) (i32.const 0 ))
38
41
" out of bounds memory access" )
39
42
40
43
90
93
(assert_return (invoke " load8_u" (i32.const 0xfffe )) (i32.const 0xaa ))
91
94
(assert_return (invoke " load8_u" (i32.const 0xffff )) (i32.const 0xbb ))
92
95
93
- ;; Fail on out-of-bounds even if copying 0 bytes.
94
- (assert_trap (invoke " copy" (i32.const 0x10000 ) (i32.const 0 ) (i32.const 0 ))
96
+ ;; Succeed when copying 0 bytes at the end of the region.
97
+ (invoke " copy" (i32.const 0x10000 ) (i32.const 0 ) (i32.const 0 ))
98
+ (invoke " copy" (i32.const 0 ) (i32.const 0x10000 ) (i32.const 0 ))
99
+
100
+ ;; Fail on out-of-bounds when copying 0 bytes outside of memory.
101
+ (assert_trap (invoke " copy" (i32.const 0x10001 ) (i32.const 0 ) (i32.const 0 ))
95
102
" out of bounds memory access" )
96
- (assert_trap (invoke " copy" (i32.const 0 ) (i32.const 0x10000 ) (i32.const 0 ))
103
+ (assert_trap (invoke " copy" (i32.const 0 ) (i32.const 0x10001 ) (i32.const 0 ))
97
104
" out of bounds memory access" )
You can’t perform that action at this time.
0 commit comments