|
| 1 | +From 95f506a6e77d3ac7588eac7263f95558edfa7f3b Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Mon, 15 Sep 2025 15:19:51 +0800 |
| 4 | +Subject: [PATCH] Merge commit from fork |
| 5 | + |
| 6 | +* fix overflow in check_bulk_memory_overflow |
| 7 | + |
| 8 | +Upstream Patch reference: https://github.com/bytecodealliance/wasm-micro-runtime/commit/95f506a6e77d3ac7588eac7263f95558edfa7f3b.patch |
| 9 | +--- |
| 10 | + .../core/iwasm/compilation/aot_emit_memory.c | 14 ++++++++++++-- |
| 11 | + 1 file changed, 12 insertions(+), 2 deletions(-) |
| 12 | + |
| 13 | +diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c |
| 14 | +index 8c35c3f..6a01c25 100644 |
| 15 | +--- a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c |
| 16 | ++++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c |
| 17 | +@@ -880,7 +880,7 @@ static LLVMValueRef |
| 18 | + check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, |
| 19 | + LLVMValueRef offset, LLVMValueRef bytes) |
| 20 | + { |
| 21 | +- LLVMValueRef maddr, max_addr, cmp; |
| 22 | ++ LLVMValueRef maddr, max_addr, cmp, cmp1, offset1; |
| 23 | + LLVMValueRef mem_base_addr; |
| 24 | + LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder); |
| 25 | + LLVMBasicBlockRef check_succ; |
| 26 | +@@ -922,8 +922,18 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, |
| 27 | + if (mem_data_size > 0 && mem_offset + mem_len <= mem_data_size) { |
| 28 | + /* inside memory space */ |
| 29 | + /* maddr = mem_base_addr + moffset */ |
| 30 | ++ /* Perform zero extension in advance to avoid LLVMBuildInBoundsGEP2 |
| 31 | ++ * interpreting a negative address due to sign extension when |
| 32 | ++ * mem_offset >= 2GiB */ |
| 33 | ++ if (comp_ctx->pointer_size == sizeof(uint64)) { |
| 34 | ++ offset1 = I64_CONST(mem_offset); |
| 35 | ++ } |
| 36 | ++ else { |
| 37 | ++ offset1 = I32_CONST((uint32)mem_offset); |
| 38 | ++ } |
| 39 | ++ CHECK_LLVM_CONST(offset1); |
| 40 | + if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, |
| 41 | +- mem_base_addr, &offset, 1, |
| 42 | ++ mem_base_addr, &offset1, 1, |
| 43 | + "maddr"))) { |
| 44 | + aot_set_last_error("llvm build add failed."); |
| 45 | + goto fail; |
| 46 | +-- |
| 47 | +2.45.4 |
| 48 | + |
0 commit comments