Commit 231862a
committed
fast-interp: reject br/br_if/br_table to loop entry from inside try-region
When a br skips over a try-region's END, the runtime br doesn't pop
eh-stack entries. For a one-shot br to a block / function-end /
catch, the leaked entry is absorbed by the static
`exception_handler_count * EH_ENTRY_CELLS` reservation and dies at
frame teardown — a load-time `LOG_WARNING` surfaces the shape for
embedders.
If the br target is a LOOP entry, however, every iteration's TRY
push adds one more entry to the eh-stack. After more iterations
than the function's `exception_handler_count`, the next TRY push
writes past the static reservation. `bh_assert(eh_count < count)`
catches this in debug builds, but is a no-op without `BH_DEBUG` —
release builds silently corrupt whatever sat past the reservation
in the frame allocation.
This commit changes that pathological shape from "log a warning
and accept" to "fail load with an explicit error". The check sits
next to the existing `count_try_blocks_crossed > 0` warning at all
three branch sites (BR, BR_IF, BR_TABLE) and only fires when
`frame_csp_tmp->label_type == LABEL_TYPE_LOOP`. The error message
is identical at each site modulo opcode name:
"br[_if|_table] to loop entry from inside try-region not
supported in fast interpreter (would leak eh-stack entries
per iteration)"
Emitting a synthetic eh-stack pop at the br site would be the
other fix and would let valid modules with this shape run, but it
complicates the rewritten IR's br-info layout (the br dispatch
currently emits a single uint32 depth; a pop-count immediate
would need a per-target lookup) and the shape is rare in
practice. Rejecting at load is the conservative, App-Store-safe
choice — embedders see a deterministic error rather than silent
memory corruption.
Test added in the external integration suite: the previously-
ignored `br_out_of_try_inside_loop` became
`br_out_of_try_inside_loop_rejected`, which asserts the loader
fails with the expected error string.
Codex P1 review feedback on both PRs ("Reject branches that leak
EH entries" / "Reject branches that leak EH stack entries").1 parent 54bac97 commit 231862a
1 file changed
Lines changed: 51 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13433 | 13433 | | |
13434 | 13434 | | |
13435 | 13435 | | |
13436 | | - | |
13437 | | - | |
13438 | | - | |
13439 | | - | |
13440 | | - | |
13441 | | - | |
13442 | | - | |
13443 | | - | |
13444 | | - | |
13445 | | - | |
13446 | | - | |
| 13436 | + | |
| 13437 | + | |
| 13438 | + | |
| 13439 | + | |
| 13440 | + | |
| 13441 | + | |
| 13442 | + | |
| 13443 | + | |
| 13444 | + | |
| 13445 | + | |
| 13446 | + | |
| 13447 | + | |
| 13448 | + | |
| 13449 | + | |
| 13450 | + | |
| 13451 | + | |
| 13452 | + | |
| 13453 | + | |
| 13454 | + | |
13447 | 13455 | | |
13448 | 13456 | | |
13449 | | - | |
| 13457 | + | |
| 13458 | + | |
| 13459 | + | |
| 13460 | + | |
| 13461 | + | |
| 13462 | + | |
| 13463 | + | |
| 13464 | + | |
| 13465 | + | |
| 13466 | + | |
13450 | 13467 | | |
13451 | 13468 | | |
13452 | 13469 | | |
| |||
13470 | 13487 | | |
13471 | 13488 | | |
13472 | 13489 | | |
13473 | | - | |
| 13490 | + | |
13474 | 13491 | | |
13475 | 13492 | | |
13476 | | - | |
| 13493 | + | |
| 13494 | + | |
| 13495 | + | |
| 13496 | + | |
| 13497 | + | |
| 13498 | + | |
| 13499 | + | |
| 13500 | + | |
| 13501 | + | |
| 13502 | + | |
13477 | 13503 | | |
13478 | 13504 | | |
13479 | 13505 | | |
| |||
13550 | 13576 | | |
13551 | 13577 | | |
13552 | 13578 | | |
13553 | | - | |
| 13579 | + | |
13554 | 13580 | | |
13555 | 13581 | | |
13556 | | - | |
| 13582 | + | |
| 13583 | + | |
| 13584 | + | |
| 13585 | + | |
| 13586 | + | |
| 13587 | + | |
| 13588 | + | |
| 13589 | + | |
| 13590 | + | |
| 13591 | + | |
13557 | 13592 | | |
13558 | 13593 | | |
13559 | 13594 | | |
| |||
0 commit comments