Add more checks in wasm loader (#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.
This commit is contained in:
Wenyong Huang 2024-04-11 19:56:48 +08:00 committed by GitHub
parent 19a6eb98b0
commit 1c690b7561
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -13008,6 +13008,7 @@ re_scan:
break;
case WASM_OP_F32_CONST:
CHECK_BUF(p, p_end, sizeof(float32));
p += sizeof(float32);
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
@ -13026,6 +13027,7 @@ re_scan:
break;
case WASM_OP_F64_CONST:
CHECK_BUF(p, p_end, sizeof(float64));
p += sizeof(float64);
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
@ -14356,6 +14358,7 @@ re_scan:
}
case WASM_OP_MEMORY_COPY:
{
CHECK_BUF(p, p_end, sizeof(int16));
/* both src and dst memory index should be 0 */
if (*(int16 *)p != 0x0000)
goto fail_zero_byte_expected;

View File

@ -7351,6 +7351,7 @@ re_scan:
break;
case WASM_OP_F32_CONST:
CHECK_BUF(p, p_end, sizeof(float32));
p += sizeof(float32);
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
@ -7369,6 +7370,7 @@ re_scan:
break;
case WASM_OP_F64_CONST:
CHECK_BUF(p, p_end, sizeof(float64));
p += sizeof(float64);
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
@ -7676,6 +7678,7 @@ re_scan:
}
case WASM_OP_MEMORY_COPY:
{
CHECK_BUF(p, p_end, sizeof(int16));
/* both src and dst memory index should be 0 */
bh_assert(*(int16 *)p == 0x0000);
p += 2;