phpv8 / php-v8

PHP extension for V8 JavaScript engine
https://php-v8.readthedocs.io
MIT License
217 stars 14 forks source link

ScriptCompiler received Segmentation fault if ScriptOriginOptions::IS_MODULE #79

Closed AlexMasterov closed 6 years ago

AlexMasterov commented 6 years ago

V8 6.5.28 on Alpine.

The test case from tests/ScriptCompiler_compileFunctionInContext.phpt:

$isolate = new \V8\Isolate();
$context = new \V8\Context($isolate);

$origin = new \V8\ScriptOrigin('test.js', 0, 0, 0, "", new \V8\ScriptOriginOptions(\V8\ScriptOriginOptions::IS_MODULE));
$source_string = new \V8\StringValue($isolate, '"test"');
$source = new \V8\ScriptCompiler\Source($source_string, $origin);

PHP received signal SIGSEGV, Segmentation fault:

0x00007ffff044f5d7 in v8::internal::ModuleDescriptor::Validate(v8::internal::ModuleScope*, v8::internal::PendingCompilationErrorHandler*, v8::internal::Zone*) () from /usr/local/v8/lib/libv8.so

#0  0x00007ffff044f5d7 in v8::internal::ModuleDescriptor::Validate(v8::internal::ModuleScope*, v8::internal::PendingCompilationErrorHandler*, v8::internal::Zone*) () from /usr/local/v8/lib/libv8.so
#1  0x00007ffff091737e in v8::internal::Parser::DoParseProgram(v8::internal::ParseInfo*) () from /usr/local/v8/lib/libv8.so
#2  0x00007ffff091752d in v8::internal::Parser::ParseProgram(v8::internal::Isolate*, v8::internal::ParseInfo*) () from /usr/local/v8/lib/libv8.so
#3  0x00007ffff091bb70 in v8::internal::parsing::ParseProgram(v8::internal::ParseInfo*, v8::internal::Isolate*) () from /usr/local/v8/lib/libv8.so
#4  0x00007ffff052071b in v8::internal::(anonymous namespace)::CompileToplevel(v8::internal::ParseInfo*, v8::internal::Isolate*) () from /usr/local/v8/lib/libv8.so
#5  0x00007ffff05210e2 in v8::internal::Compiler::GetFunctionFromEval(v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::SharedFunctionInfo>, v8::internal::Handle<v8::internal::Context>, v8::internal::LanguageMode, v8::internal::ParseRestriction, int, int, int, int, int, v8::internal::Handle<v8::internal::Object>, v8::ScriptOriginOptions) () from /usr/local/v8/lib/libv8.so
#6  0x00007ffff0416513 in v8::ScriptCompiler::CompileFunctionInContext(v8::Local<v8::Context>, v8::ScriptCompiler::Source*, unsigned long, v8::Local<v8::String>*, unsigned long, v8::Local<v8::Object>*) () from /usr/local/v8/lib/libv8.so
#7  0x00007ffff13bc6c4 in zim_ScriptCompiler_compileFunctionInContext (execute_data=<optimized out>, return_value=0x7ffff16131f0) at /tmp/php-v8-0.2.1/src/php_v8_script_compiler.cc:248
#8  0x0000555555b409e4 in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER ()
#9  0x0000555555ae890b in execute_ex ()
#10 0x0000555555b42e78 in zend_execute ()
#11 0x0000555555a9eed3 in zend_execute_scripts ()
#12 0x0000555555a3bc80 in php_execute_script ()
#13 0x0000555555b4508c in do_cli ()
#14 0x0000555555697587 in main ()
pinepain commented 6 years ago

I was able to reproduce the issue using libv8 6.5.116. I don't see particular use case for module been compiled as a function within a context. Also, I found no such usage in v8 tests, so I'm going to disable this behavior for now.