Details
-
Bug
-
Resolution: Out of scope
-
P1: Critical
-
None
-
5.9.3
-
None
-
Debug x64
Description
Hi, I have tested this regular expression at regex101.com and it runs fine without requiring a possessive qualifier to prevent backtracking. I believe this may be a flaw in the QRegularExpression implementation, i.e. pcre2_match_16.
Test Code:
// begin code QString str("@1&|Aaaaaaaa Bbbbbbbbbb:Ccc Dddddddd,Eeee Ffffffff,Gggg Hhhhhhhh|Iiiiiiii Iiiiiiii:Jjjjjj Jjjjjjjj,Kkkkkk Llllllll,Mmmmmm Nnnnnnnn|Ooooooo Pppppppp:Qqqqqqq,Rrrrrrrrrr|Ssssss Ttttttttt:[tttt tttttt tt tttt::Uuuuuu Vvvvvv Wwwwwwww,Xxxxxx Yyyyyy Zzzzz,Aaaaaa Bbbbbb Ccccccc,Dddddd Eeeeee Ffffffffff Ggggg,Hhhhhh Iiiiii,Jjjjjj Kkkkkkkk Lllllll],Mmmmmm Nnnnnn Ooooo Ppppppp|Qqqqqqq Rrrrrrrr:Sss Ttttttt Uuuuuuuu|Vvvvvv Wwwwwwww:Xxxxxxx,Yyyyyy,Zzzzzzz,Aaaa,Bbbbbbb,Cccccccccc,Dddddd,EFG,Hhhhh,Iiiiiiii Jjjjjjjj,Kkkkkk Llllllllll Mmmm|Nnnnnnnnn Oooooooo:Pppp,Qqqqqq|Rrrr Ssssssss:Tttttt Uuuu,Vvv Wwwwwwwww,Xxxxxxxx Yyyyyyyyy,Zzzz Aaaaaa,Bbbbbbbb Cccc,Dddd Eeeeeee Ffff|Ggggggg Hhhhhhhh:Iiiiii Jjjjj|KkkLll Mmmmmmmm:Nnnnnn Oooooooo,Pppppp QqqRrrrr,Ssssss TttUuuuu,Vvvvv,Wwwwww Xxxxxxxxx,Yyyyyy ZAB Cccc,Dddddd EFG Hhhh|Iiiiiii Jjjjjjjj:Kkkkkk Lllllllll Mmmmmmmm,Nnnnnn Oooooo\n&PQRSTU_VWXYZAB&2&3"); QRegularExpression myRegex; myRegex.setPattern("(?:[^@\\\\]|\\\\.)+"); // match anything other than unescaped '@' // myRegex.setPattern("(?:\\\\.|[^@\\\\])+"); // also fails // myRegex.setPattern("(?:[^@\\\\]|\\\\.)++"); // works but I shouldn't have to do this // myRegex.setPattern("(?>[^@\\\\]|\\\\.)+"); // should be equivalent to the above, yet fails auto myIter = myRegex.globalMatch(str);
Result:
Stack Overflow
Call Stack:
match(const unsigned short * eptr, const unsigned short * ecode, const unsigned short * mstart, unsigned __int64 offset_top, match_block_16 * mb, eptrblock * eptrb, unsigned int rdepth) Line 1110 Cmatch(const unsigned short * eptr, const unsigned short * ecode, const unsigned short * mstart, unsigned __int64 offset_top, match_block_16 * mb, eptrblock * eptrb, unsigned int rdepth) Line 1110 C ...infinite recursion... match(const unsigned short * eptr, const unsigned short * ecode, const unsigned short * mstart, unsigned __int64 offset_top, match_block_16 * mb, eptrblock * eptrb, unsigned int rdepth) Line 1110 C pcre2_match_16(const pcre2_real_code_16 * code, const unsigned short * subject, unsigned __int64 length, unsigned __int64 start_offset, unsigned int options, pcre2_real_match_data_16 * match_data, pcre2_real_match_context_16 * mcontext) Line 6997 C safe_pcre2_match_16(const pcre2_real_code_16 * code, const unsigned short * subject, int length, int startOffset, int options, pcre2_real_match_data_16 * matchData, pcre2_real_match_context_16 * matchContext) Line 1203 C++ QRegularExpressionPrivate::doMatch(const QString & subject, int subjectStart, int subjectLength, int offset, QRegularExpression::MatchType matchType, QFlags<enum QRegularExpression::MatchOption> matchOptions, QRegularExpressionPrivate::CheckSubjectStringOption checkSubjectStringOption, const QRegularExpressionMatchPrivate * previous) Line 1315 C++ QRegularExpression::match(const QString & subject, int offset, QRegularExpression::MatchType matchType, QFlags<enum QRegularExpression::MatchOption> matchOptions) Line 1729 C++ QRegularExpression::globalMatch(const QString & subject, int offset, QRegularExpression::MatchType matchType, QFlags<enum QRegularExpression::MatchOption> matchOptions) Line 1776 C++