Browse Source

fuzzer: bubble up NoInstructionsRemain error instead of trying to handle as exception (#2566)

Hi,

the `vm-implied` fuzzer panics when executing this testcase:

```javascript
try {
    new function() {
        while (this) {}
    }();
} catch {
}
```

`internal error: entered unreachable code: The NoInstructionsRemain native error cannot be converted to an opaque type`

Handling the `NoInstructionsRemain` error upfront instead of going through the VM exception handling logic seems to work.
pull/2587/head
Mrmaxmeier 2 years ago
parent
commit
4aebe39e15
  1. 10
      boa_engine/src/vm/mod.rs
  2. 4
      fuzz/Cargo.toml

10
boa_engine/src/vm/mod.rs

@ -10,7 +10,7 @@ use crate::{
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
#[cfg(feature = "fuzz")] #[cfg(feature = "fuzz")]
use crate::{JsError, JsNativeError}; use crate::{JsError, JsNativeError, JsNativeErrorKind};
use boa_interner::ToInternedString; use boa_interner::ToInternedString;
use boa_profiler::Profiler; use boa_profiler::Profiler;
use std::{convert::TryInto, mem::size_of, time::Instant}; use std::{convert::TryInto, mem::size_of, time::Instant};
@ -281,6 +281,14 @@ impl Context<'_> {
return Ok((result, ReturnType::Yield)); return Ok((result, ReturnType::Yield));
} }
Err(e) => { Err(e) => {
#[cfg(feature = "fuzz")]
if let Some(native_error) = e.as_native() {
// If we hit the execution step limit, bubble up the error to the
// (Rust) caller instead of trying to handle as an exception.
if matches!(native_error.kind, JsNativeErrorKind::NoInstructionsRemain) {
return Err(e);
}
}
if let Some(address) = self.vm.frame().catch.last() { if let Some(address) = self.vm.frame().catch.last() {
let address = address.next; let address = address.next;
let try_stack_entry = self let try_stack_entry = self

4
fuzz/Cargo.toml

@ -10,9 +10,9 @@ cargo-fuzz = true
[dependencies] [dependencies]
libfuzzer-sys = "0.4" libfuzzer-sys = "0.4"
boa_ast = { path = "../boa_ast", features = ["fuzz"] } boa_ast = { path = "../boa_ast", features = ["arbitrary"] }
boa_engine = { path = "../boa_engine", features = ["fuzz"] } boa_engine = { path = "../boa_engine", features = ["fuzz"] }
boa_interner = { path = "../boa_interner", features = ["fuzz"] } boa_interner = { path = "../boa_interner", features = ["arbitrary"] }
boa_parser = { path = "../boa_parser" } boa_parser = { path = "../boa_parser" }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces

Loading…
Cancel
Save