Skip to content

Panic index out of bounds: the len is 0 but the index is 0 in core/engine/src/vm/opcode/define/mod.rs #4400

@qarmin

Description

@qarmin

Rust code

fn check_file(path: &str) {
    let Ok(file_content) = fs::read(path) else {
        return;
    };
    println!("Checking file: {path}");
    let mut context = Context::default();

    let _result = context.eval(Source::from_bytes(&file_content));
}

when evaluating javascript code(at the bottom should be attached raw, not formatted file - github removes some non-printable characters, so copying from here may not work):

class C{constructor(){class D{}}}new C

crashes with this info:

thread 'main' (431907) panicked at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/opcode/define/mod.rs:82:33:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/07d246fc6dc227903da2955b38a59e060539a485/library/std/src/panicking.rs:698:5
   1: core::panicking::panic_fmt
             at /rustc/07d246fc6dc227903da2955b38a59e060539a485/library/core/src/panicking.rs:75:14
   2: core::panicking::panic_bounds_check
             at /rustc/07d246fc6dc227903da2955b38a59e060539a485/library/core/src/panicking.rs:271:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index_mut
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:271:14
   4: core::slice::index::<impl core::ops::index::IndexMut<I> for [T]>::index_mut
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:30:15
   5: <alloc::vec::Vec<T,A> as core::ops::index::IndexMut<I>>::index_mut
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3629:9
   6: boa_engine::environments::runtime::declarative::PoisonableEnvironment::set
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/environments/runtime/declarative/mod.rs:310:35
   7: boa_engine::environments::runtime::declarative::DeclarativeEnvironmentKind::set
   8: boa_engine::environments::runtime::declarative::DeclarativeEnvironment::set
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/environments/runtime/declarative/mod.rs:80:19
   9: boa_engine::environments::runtime::EnvironmentStack::put_lexical_value
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/environments/runtime/mod.rs:280:13
  10: boa_engine::vm::opcode::define::PutLexicalValue::operation
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/opcode/define/mod.rs:82:33
  11: boa_engine::vm::opcode::handle_put_lexical_value
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/opcode/mod.rs:313:17
  12: boa_engine::vm::opcode::<impl boa_engine::context::Context>::execute_bytecode_instruction
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/opcode/mod.rs:464:9
  13: core::ops::function::FnOnce::call_once
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:253:5
  14: boa_engine::vm::<impl boa_engine::context::Context>::execute_instruction
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/mod.rs:649:9
  15: boa_engine::vm::<impl boa_engine::context::Context>::execute_one
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/mod.rs:674:14
  16: boa_engine::vm::<impl boa_engine::context::Context>::run
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/mod.rs:858:24
  17: boa_engine::script::Script::evaluate
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/script.rs:172:30
  18: boa_engine::context::Context::eval
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/context/mod.rs:202:41
  19: boa::check_file
             at ./src/crates/boa/src/main.rs:33:27
  20: boa::main
             at ./src/crates/boa/src/main.rs:22:9
  21: core::ops::function::FnOnce::call_once
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:253:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

compressed.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions