Skip to content

Commit

Permalink
[CVE-2018-0777] JIT: Loop analysis bug - Google, Inc.
Browse files Browse the repository at this point in the history
  • Loading branch information
pleath authored and Thomas Moore (CHAKRA) committed Jan 5, 2018
1 parent ee5ac64 commit 14c752b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Backend/GlobOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7072,6 +7072,18 @@ GlobOpt::OptConstFoldUnary(
this->ToFloat64Dst(instr, dst->AsRegOpnd(), this->currentBlock);
}
}

// If this is an induction variable, then treat it the way the prepass would have if it had seen
// the assignment and the resulting change to the value number, and mark it as indeterminate.
for (Loop * loop = this->currentBlock->loop; loop; loop = loop->parent)
{
InductionVariable *iv = nullptr;
if (loop->inductionVariables && loop->inductionVariables->TryGetReference(dstSym->m_id, &iv))
{
iv->SetChangeIsIndeterminate();
}
}

return true;
}

Expand Down Expand Up @@ -12391,6 +12403,17 @@ GlobOpt::OptConstFoldBinary(
this->ToInt32Dst(instr, dst->AsRegOpnd(), this->currentBlock);
}

// If this is an induction variable, then treat it the way the prepass would have if it had seen
// the assignment and the resulting change to the value number, and mark it as indeterminate.
for (Loop * loop = this->currentBlock->loop; loop; loop = loop->parent)
{
InductionVariable *iv = nullptr;
if (loop->inductionVariables && loop->inductionVariables->TryGetReference(dstSym->m_id, &iv))
{
iv->SetChangeIsIndeterminate();
}
}

return true;
}

Expand Down
23 changes: 23 additions & 0 deletions test/Optimizer/bug42111.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function opt(arr, start, end) {
for (let i = start; i < end; i++) {
if (i === 10) {
i += 0;
}
arr[i] = 2.3023e-320;
}
}

let arr = new Array(100);

function main() {
arr.fill(1.1);

for (let i = 0; i < 1000; i++)
opt(arr, 0, 3);

opt(arr, 0, 100000);
}

main();

WScript.Echo(arr[0] === 2.3023e-320 ? 'pass' : 'fail');
5 changes: 5 additions & 0 deletions test/Optimizer/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<files>bug41530.js</files>
</default>
</test>
<test>
<default>
<files>bug42111.js</files>
</default>
</test>
<test>
<default>
<files>bug70.js</files>
Expand Down

0 comments on commit 14c752b

Please sign in to comment.