mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-06 13:41:35 +01:00
Merge pull request #605 from miloyip/issue583_regexcrash
Fix regex crash
This commit is contained in:
commit
07343d5e33
@ -53,6 +53,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
* Custom Microsoft headers are necessary only for Visual Studio 2012 and lower (#559)
|
||||
* Fix memory leak for invalid regex (26e69ffde95ba4773ab06db6457b78f308716f4b)
|
||||
* Fix a bug in schema minimum/maximum keywords for 64-bit integer (e7149d665941068ccf8c565e77495521331cf390)
|
||||
* Fix a crash bug in regex (#605)
|
||||
|
||||
### Changed
|
||||
* Clarify problematic JSON license (#392)
|
||||
|
@ -468,17 +468,17 @@ private:
|
||||
static SizeType Min(SizeType a, SizeType b) { return a < b ? a : b; }
|
||||
|
||||
void CloneTopOperand(Stack<Allocator>& operandStack) {
|
||||
const Frag *src = operandStack.template Top<Frag>();
|
||||
SizeType count = stateCount_ - src->minIndex; // Assumes top operand contains states in [src->minIndex, stateCount_)
|
||||
const Frag src = *operandStack.template Top<Frag>(); // Copy constructor to prevent invalidation
|
||||
SizeType count = stateCount_ - src.minIndex; // Assumes top operand contains states in [src->minIndex, stateCount_)
|
||||
State* s = states_.template Push<State>(count);
|
||||
memcpy(s, &GetState(src->minIndex), count * sizeof(State));
|
||||
memcpy(s, &GetState(src.minIndex), count * sizeof(State));
|
||||
for (SizeType j = 0; j < count; j++) {
|
||||
if (s[j].out != kRegexInvalidState)
|
||||
s[j].out += count;
|
||||
if (s[j].out1 != kRegexInvalidState)
|
||||
s[j].out1 += count;
|
||||
}
|
||||
*operandStack.template Push<Frag>() = Frag(src->start + count, src->out + count, src->minIndex + count);
|
||||
*operandStack.template Push<Frag>() = Frag(src.start + count, src.out + count, src.minIndex + count);
|
||||
stateCount_ += count;
|
||||
}
|
||||
|
||||
|
@ -584,4 +584,9 @@ TEST(Regex, Issue538) {
|
||||
EXPECT_TRUE(re.IsValid());
|
||||
}
|
||||
|
||||
TEST(Regex, Issue583) {
|
||||
Regex re("[0-9]{99999}");
|
||||
ASSERT_TRUE(re.IsValid());
|
||||
}
|
||||
|
||||
#undef EURO
|
||||
|
Loading…
x
Reference in New Issue
Block a user