Skip to content

Internal OOM exception broken in 0.8.0 #798

@Icemic

Description

@Icemic

I'm upgrading from 0.5 to 0.8, and have observed that my test case of Quickjs's OOM exception failed.

My test code (in Rust):

#[test] fn memory_limit_exceeded() { let c = Context::builder().memory_limit(100_000).build().unwrap(); assert_eq!( c.eval(" 'abc'.repeat(200_000) ", false), Err(ExecutionError::OutOfMemory), ); }

It simply initializes a quickjs context with a low memory limit and emits the exeception via .eval().

In 0.5.0, it will then throw an exception (get via JS_GetException()) which has a message "out of memory". It is from https://github.com/quickjs-ng/quickjs/blob/91459fb6723e29e923380cec0023af93819ae69d/quickjs.c#L6385

But in 0.8.0, the message is null.

JS_ThrowError2 is refactored between 0.8.0 and 0.5.0, but I found that this is not directly related to the problem.

Whatever, I finally found the source of the problem:

The OOM error is thrown by JS_ThrowOutOfMemory -> JS_ThrowInternalError -> JS_ThrowError -> JS_ThrowError2 -> JS_MakeError -> JS_NewObjectProtoClass -> ...

In JS_NewObjectProtoClass, the js_new_shape returns 0 (but not in 0.5.0), thus causes another exception but it is not checked and handled in JS_MakeError.

I'm not sure why js_new_shape returns 0, and not familiar with those codes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions