Skip to content

Panic Index out of bounds in core/string/src/str.rs #4404

@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):

decodeURI('%E7%9A%8')

crashes with this info:

thread 'main' (311051) panicked at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/string/src/str.rs:245:25:
Index out of bounds
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_display
             at /rustc/07d246fc6dc227903da2955b38a59e060539a485/library/core/src/panicking.rs:259:5
   3: core::option::expect_failed
             at /rustc/07d246fc6dc227903da2955b38a59e060539a485/library/core/src/option.rs:2175:5
   4: boa_engine::builtins::uri::decode
   5: boa_engine::builtins::uri::decode_uri
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/builtins/uri/mod.rs:187:22
   6: boa_engine::native_function::NativeFunction::call
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/native_function/mod.rs:306:36
   7: boa_engine::native_function::native_function_call
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/native_function/mod.rs:368:18
   8: boa_engine::object::internal_methods::CallValue::resolve
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/object/internal_methods/mod.rs:493:20
   9: boa_engine::vm::opcode::call::Call::operation
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/opcode/call/mod.rs:196:48
  10: boa_engine::vm::opcode::handle_call
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/vm/opcode/mod.rs:313:17
  11: 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
  12: 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
  13: 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
  14: 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
  15: 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
  16: boa_engine::script::Script::evaluate
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/script.rs:172:30
  17: boa_engine::context::Context::eval
             at /home/runner/.cargo/git/checkouts/boa-126d820dff07bf57/8ea37c6/core/engine/src/context/mod.rs:202:41
  18: boa::check_file
             at ./src/crates/boa/src/main.rs:33:27
  19: boa::main
             at ./src/crates/boa/src/main.rs:22:9
  20: 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