Skip to content

Commit

Permalink
Fix crash when got stack overflow error while computing bytecode posi…
Browse files Browse the repository at this point in the history
…tion

Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 authored and clover2123 committed Sep 24, 2024
1 parent 32f1ebb commit 7365c2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
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

0 comments on commit 7365c2a

Please sign in to comment.