Skip to content

Commit 78da984

Browse files
wenyonghvickiegpt
authored andcommitted
Add more checks in wasm loader (bytecodealliance#3300)
In opcode f32.const, f64.const and memory.copy, check whether the buffer to read is out of the range of wasm file before reading it. Signed-off-by: victoryang00 <[email protected]>
1 parent 0ab204d commit 78da984

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13008,6 +13008,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1300813008
break;
1300913009

1301013010
case WASM_OP_F32_CONST:
13011+
CHECK_BUF(p, p_end, sizeof(float32));
1301113012
p += sizeof(float32);
1301213013
#if WASM_ENABLE_FAST_INTERP != 0
1301313014
skip_label();
@@ -13026,6 +13027,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1302613027
break;
1302713028

1302813029
case WASM_OP_F64_CONST:
13030+
CHECK_BUF(p, p_end, sizeof(float64));
1302913031
p += sizeof(float64);
1303013032
#if WASM_ENABLE_FAST_INTERP != 0
1303113033
skip_label();
@@ -14356,6 +14358,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1435614358
}
1435714359
case WASM_OP_MEMORY_COPY:
1435814360
{
14361+
CHECK_BUF(p, p_end, sizeof(int16));
1435914362
/* both src and dst memory index should be 0 */
1436014363
if (*(int16 *)p != 0x0000)
1436114364
goto fail_zero_byte_expected;

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7351,6 +7351,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
73517351
break;
73527352

73537353
case WASM_OP_F32_CONST:
7354+
CHECK_BUF(p, p_end, sizeof(float32));
73547355
p += sizeof(float32);
73557356
#if WASM_ENABLE_FAST_INTERP != 0
73567357
skip_label();
@@ -7369,6 +7370,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
73697370
break;
73707371

73717372
case WASM_OP_F64_CONST:
7373+
CHECK_BUF(p, p_end, sizeof(float64));
73727374
p += sizeof(float64);
73737375
#if WASM_ENABLE_FAST_INTERP != 0
73747376
skip_label();
@@ -7676,6 +7678,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
76767678
}
76777679
case WASM_OP_MEMORY_COPY:
76787680
{
7681+
CHECK_BUF(p, p_end, sizeof(int16));
76797682
/* both src and dst memory index should be 0 */
76807683
bh_assert(*(int16 *)p == 0x0000);
76817684
p += 2;

0 commit comments

Comments
 (0)