@@ -11227,6 +11227,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1122711227 bool disable_emit, preserve_local = false, if_condition_available = true;
1122811228 float32 f32_const;
1122911229 float64 f64_const;
11230+ /*
11231+ * It means that the fast interpreter detected an exception while preparing,
11232+ * typically near the block opcode, but it did not immediately trigger
11233+ * the exception. The loader should be capable of identifying it near
11234+ * the end opcode and then raising the exception.
11235+ */
11236+ bool pending_exception = false;
1123011237
1123111238 LOG_OP("\nProcessing func | [%d] params | [%d] locals | [%d] return\n",
1123211239 func->param_cell_num, func->local_cell_num, func->ret_cell_num);
@@ -11577,6 +11584,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1157711584 cell_num = wasm_value_type_cell_num(
1157811585 wasm_type->types[wasm_type->param_count - i - 1]);
1157911586 loader_ctx->frame_offset -= cell_num;
11587+
11588+ if (loader_ctx->frame_offset
11589+ < loader_ctx->frame_offset_bottom) {
11590+ LOG_DEBUG(
11591+ "frame_offset underflow, roll back and "
11592+ "let following stack checker report it\n");
11593+ loader_ctx->frame_offset += cell_num;
11594+ pending_exception = true;
11595+ break;
11596+ }
1158011597#endif
1158111598 }
1158211599 }
@@ -12099,6 +12116,15 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1209912116 }
1210012117 }
1210112118
12119+ #if WASM_ENABLE_FAST_INTERP != 0
12120+ if (pending_exception) {
12121+ set_error_buf(
12122+ error_buf, error_buf_size,
12123+ "There is a pending exception needs to be handled");
12124+ goto fail;
12125+ }
12126+ #endif
12127+
1210212128 break;
1210312129 }
1210412130
0 commit comments