@@ -11234,6 +11234,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1123411234 bool disable_emit, preserve_local = false, if_condition_available = true;
1123511235 float32 f32_const;
1123611236 float64 f64_const;
11237+ /*
11238+ * It means that the fast interpreter detected an exception while preparing,
11239+ * typically near the block opcode, but it did not immediately trigger
11240+ * the exception. The loader should be capable of identifying it near
11241+ * the end opcode and then raising the exception.
11242+ */
11243+ bool pending_exception = false;
1123711244
1123811245 LOG_OP("\nProcessing func | [%d] params | [%d] locals | [%d] return\n",
1123911246 func->param_cell_num, func->local_cell_num, func->ret_cell_num);
@@ -11584,6 +11591,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1158411591 cell_num = wasm_value_type_cell_num(
1158511592 wasm_type->types[wasm_type->param_count - i - 1]);
1158611593 loader_ctx->frame_offset -= cell_num;
11594+
11595+ if (loader_ctx->frame_offset
11596+ < loader_ctx->frame_offset_bottom) {
11597+ LOG_DEBUG(
11598+ "frame_offset underflow, roll back and "
11599+ "let following stack checker report it\n");
11600+ loader_ctx->frame_offset += cell_num;
11601+ pending_exception = true;
11602+ break;
11603+ }
1158711604#endif
1158811605 }
1158911606 }
@@ -12106,6 +12123,15 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1210612123 }
1210712124 }
1210812125
12126+ #if WASM_ENABLE_FAST_INTERP != 0
12127+ if (pending_exception) {
12128+ set_error_buf(
12129+ error_buf, error_buf_size,
12130+ "There is a pending exception needs to be handled");
12131+ goto fail;
12132+ }
12133+ #endif
12134+
1210912135 break;
1211012136 }
1211112137
0 commit comments