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 CharTrie::CloneFrom #6857

Merged
merged 2 commits into from
Nov 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Parser/CharTrie.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "ParserPch.h"
Expand Down Expand Up @@ -199,16 +200,17 @@ namespace UnifiedRegex
#endif
}

void RuntimeCharTrie::CloneFrom(ArenaAllocator* allocator, const CharTrie& other)
void RuntimeCharTrie::CloneFrom(Js::ScriptContext* scriptContext, ArenaAllocator* allocator, const CharTrie& other)
{
PROBE_STACK_NO_DISPOSE(scriptContext, Js::Constants::MinStackRegex);
count = other.count;
if (count > 0)
{
children = AnewArray(allocator, RuntimeCharTrieEntry, count);
for (int i = 0; i < count; i++)
{
children[i].c = other.children[i].c;
children[i].node.CloneFrom(allocator, other.children[i].node);
children[i].node.CloneFrom(scriptContext, allocator, other.children[i].node);
}
}
else
Expand Down
3 changes: 2 additions & 1 deletion lib/Parser/CharTrie.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
Expand Down Expand Up @@ -65,7 +66,7 @@ namespace UnifiedRegex
public:
inline RuntimeCharTrie() : count(0), children(0) {}
void FreeBody(ArenaAllocator* allocator);
void CloneFrom(ArenaAllocator* allocator, const CharTrie& other);
void CloneFrom(Js::ScriptContext* scriptContext, ArenaAllocator* allocator, const CharTrie& other);

bool Match
( const Char* const input
Expand Down
3 changes: 2 additions & 1 deletion lib/Parser/RegexCompileTime.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "ParserPch.h"
Expand Down Expand Up @@ -2538,7 +2539,7 @@ namespace UnifiedRegex
{
// Root of trie will live in compile-time allocator, but body will be in run-time allocator
runtimeTrie = Anew(compiler.ctAllocator, RuntimeCharTrie);
runtimeTrie->CloneFrom(compiler.rtAllocator, trie);
runtimeTrie->CloneFrom(compiler.scriptContext, compiler.rtAllocator, trie);
scheme = Trie;
}
return;
Expand Down
54 changes: 54 additions & 0 deletions test/Regex/regexCharTrieStack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

var testString = "tacgattttatcgcgactagttaatcatcatagcaagtaaaatttgaattatgtcattat\
catgctccattaacaggttatttaattgatactgacgaaattttttcacaatgggttttc\
tagaatttaatatcagtaattgaagccttcataggggtcctactagtatcctacacgacg\
caggtccgcagtatcctggagggacgtgttactgattaaaagggtcaaaggaatgaaggc\
tcacaatgttacctgcttcaccatagtgagccgatgagttttacattagtactaaatccc\
aaatcatactttacgatgaggcttgctagcgctaaagagaatacatacaccaccacatag\
aattgttagcgatgatatcaaatagactcctggaagtgtcagggggaaactgttcaatat\
ttcgtccacaggactgaccaggcatggaaaagactgacgttggaaactataccatctcac\
gcccgacgcttcactaattgatgatccaaaaaatatagcccggattcctgattagcaaag\
ggttcacagagaaagatattatcgacgtatatcccaaaaaacagacgtaatgtgcatctt\
cgaatcgggatgaatacttgtatcataaaaatgtgacctctagtatacaggttaatgtta\
ctcacccacgtatttggtctaattatgttttatttagtgacaatccaatagataaccggt\
cctattaagggctatatttttagcgaccacgcgtttaaacaaaggattgtatgtagatgg\
gcttgatataagatttcggatgtatgggttttataatcgttggagagctcaatcatgagc\
taatacatggatttcgctacctcaccgagagaccttgcatgaagaattctaaccaaaagt\
ttaataggccggattggattgagttaattaagaccttgttcagtcatagtaaaaaccctt\n\
aaattttaccgattgacaaagtgagcagtcgcaataccctatgcgaaacgcctcgatagt\n\
gactaggtatacaaggtttttgagttcctttgaaatagttaactaatttaaaattaatta\n\
acgacatggaaatcacagaacctaatgctttgtaggagttatttatgctgtttactgcct\n\
ctacaaccctaataaagcagtcctaagaatgaaacgcatcttttagttcagaaagtggta\n\
tccagggtggtcaatttaataaattcaacatcgggtctcaggatattcggtcatataatt\n\
tattaagggctcttcgagtcttactctgagtgaaattggaaacagtcatccttttcgttg\n\
tgaggcatcttacaccgctatcgatatacaatgcattccaccgcggtgtcccgtacacaa\n\
ggaaacttgttaccttggggatataagaaaactcacacgtctcattattaaactgagtac\n\
tggaacgcacctcggatctgttgcactggattaaaatccgattatttttaaaaatattca\n\
gtgctagagcatatcaggtctacttttttatctggtatgtaaagcccacggagcgatagt\n\
gagatccttacgactcaacgaaaagttataacataactcccgttagccaaagcccaatcc\n\
\n";
testString = testString + testString + testString;
testString = testString + testString + testString;
testString = testString + testString + testString;
testString = testString + testString + testString;
var seqs = [/a|tttaccct/ig];

Array.prototype.push.call(seqs, false, Array.prototype.concat.call(seqs, seqs, testString));
try {
for (i in seqs) {
testString.match(seqs[i]);
}
print ("Test should produce Stack over flow but didn't, case may need amending")
}
catch(e) {
if (e == "Error: Out of stack space") {
print ("pass")
} else {
print ("Wrong error thrown, expected \"Error: Out of stack space\" but recieved \"" + e + "\"");
}
}
5 changes: 5 additions & 0 deletions test/Regex/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,9 @@
<compile-flags>-args summary -endargs</compile-flags>
</default>
</test>
<test>
<default>
<files>regexCharTrieStack.js</files>
</default>
</test>
</regress-exe>