Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on invalid date object #317

Merged
merged 1 commit into from
Sep 21, 2024
Merged

Conversation

bnoordhuis
Copy link
Collaborator

@bnoordhuis bnoordhuis commented Sep 21, 2024

mini_racer converts JS objects to Ruby objects. Ruby's C API functions call rb_raise() on invalid inputs, and rb_raise() in turn is a glorified longjmp() that jumps up the stack.

Longjmp and C++ destructors do not play well together. It left V8 in an undefined state, resulting in random "Disposing the isolate that is entered by a thread" fatal errors.

Fixes: #316


Easiest to review with ?w=1 (link), the bulk is whitespace change because of an extra level of indent.

The title says "invalid date object" but this pull request in fact addresses a wider range of bugs around value conversion.

There is at least one other instance around JSON parsing. I'll open another PR for that.

@bnoordhuis
Copy link
Collaborator Author

I wonder if I found a truffleruby bug...

MiniRacerTest#test_date_nan:
NoMethodError: undefined method `source_location' for "<internal:core> core/float.rb:114:in `to_i'":Thread::Backtrace::Location
    lib/mini_racer/truffleruby.rb:199:in `block in translate'
    lib/mini_racer/truffleruby.rb:199:in `select'
    lib/mini_racer/truffleruby.rb:199:in `translate'
    lib/mini_racer/truffleruby.rb:132:in `eval_unsafe'
    lib/mini_racer.rb:237:in `block (2 levels) in eval'
    lib/mini_racer.rb:358:in `timeout'
    lib/mini_racer.rb:236:in `block in eval'
    lib/mini_racer.rb:234:in `synchronize'
    lib/mini_racer.rb:234:in `eval'
    test/mini_racer_test.rb:257:in `test_date_nan'

mini_racer converts JS objects to Ruby objects. Ruby's C API functions
call rb_raise() on invalid inputs, and rb_raise() in turn is a glorified
longjmp() that jumps up the stack.

Longjmp and C++ destructors do not play well together. It left V8 in an
undefined state, resulting in random "Disposing the isolate that is
entered by a thread" fatal errors.

Fixes: rubyjs#316
@bnoordhuis bnoordhuis merged commit 5a03255 into rubyjs:main Sep 21, 2024
18 of 21 checks passed
@bnoordhuis bnoordhuis deleted the protect branch September 21, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid date causes V8 fatal error
1 participant