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 when got stack overflow error while computing bytecode posi… #1392

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/interpreter/ByteCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ ExtendedNodeLOC ByteCodeBlock::computeNodeLOCFromByteCode(Context* c, size_t cod
fillLOCData(c, locData);
}

size_t index = 0;
size_t index = SIZE_MAX;
for (size_t i = 0; i < locData->size(); i++) {
if ((*locData)[i].first == codePosition) {
index = (*locData)[i].second;
Expand All @@ -198,8 +198,13 @@ ExtendedNodeLOC ByteCodeBlock::computeNodeLOCFromByteCode(Context* c, size_t cod
}
}

ASSERT(index >= cb->functionStart().index);
size_t indexRelatedWithScript = index;
size_t indexRelatedWithScript = 0;
if (index == SIZE_MAX) {
indexRelatedWithScript = cb->functionStart().index;
} else {
ASSERT(index >= cb->functionStart().index);
indexRelatedWithScript = index;
}
index -= cb->functionStart().index;

auto result = computeNodeLOC(cb->src(), cb->functionStart(), index);
Expand Down
24 changes: 16 additions & 8 deletions src/interpreter/ByteCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,22 @@ void ByteCodeGenerator::collectByteCodeLOCData(Context* context, InterpretedCode

// Parsing
Node* ast = nullptr;
if (codeBlock->isGlobalCodeBlock() || codeBlock->isEvalCode()) {
InterpretedCodeBlock* parentCodeBlock = codeBlock->parent();
bool allowSC = parentCodeBlock ? parentCodeBlock->allowSuperCall() : false;
bool allowSP = parentCodeBlock ? parentCodeBlock->allowSuperProperty() : false;
ast = esprima::parseProgram(context, codeBlock->src(), esprima::generateClassInfoFrom(context, codeBlock->parent()),
codeBlock->script()->isModule(), codeBlock->isStrict(), codeBlock->inWith(), allowSC, allowSP, false, true);
} else {
ast = esprima::parseSingleFunction(context, codeBlock);
// Parsing
try {
if (codeBlock->isGlobalCodeBlock() || codeBlock->isEvalCode()) {
InterpretedCodeBlock* parentCodeBlock = codeBlock->parent();
bool allowSC = parentCodeBlock ? parentCodeBlock->allowSuperCall() : false;
bool allowSP = parentCodeBlock ? parentCodeBlock->allowSuperProperty() : false;
ast = esprima::parseProgram(context, codeBlock->src(), esprima::generateClassInfoFrom(context, codeBlock->parent()),
codeBlock->script()->isModule(), codeBlock->isStrict(), codeBlock->inWith(), allowSC, allowSP, false, true);
} else {
ast = esprima::parseSingleFunction(context, codeBlock);
}
} catch (esprima::Error* orgError) {
// ignore error
context->astAllocator().reset();
GC_enable();
return;
}

// Generate ByteCode
Expand Down
Loading