Bug 12691 – std.regex.bmatch bug in empty OR operator inside of ()*

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-05-02T15:18:00Z
Last change time
2014-05-13T00:33:53Z
Keywords
pull
Assigned to
dmitry.olsh
Creator
yxcvbasdfgqwert02

Attachments

IDFilenameSummaryContent-TypeSize
1349dvt5.dSource code for test casetext/x-dsrc886

Comments

Comment #0 by yxcvbasdfgqwert02 — 2014-05-02T15:18:53Z
Created attachment 1349 Source code for test case Certain expressions/haystacks seem to trigger a memory error in std.regex.bmatch. In the attached source code, the regular expression is kind-of stupid, however it should be either treated as wrong (std.regex.regex should throw an exception) or should work, but never crash. In the test case, the expression "([a-z]|)" uses an empty string after the OR operator. The crash also occurred on a more complex expression with 2 OR operators beneath, containing something like "a||b". Using match instead of bmatch returns the expected result: the expression doesn't match the haystack. Btw, I used bmatch instead of match because bmatch is way faster (see issue 12690).
Comment #1 by dmitry.olsh — 2014-05-02T21:06:16Z
And on Win32: object.Error@(0): Access Violation Got to look in it.
Comment #2 by dmitry.olsh — 2014-05-12T15:35:56Z
https://github.com/D-Programming-Language/phobos/pull/2164 The bug also applies to ctRegex as they share engines. Reduced test-case: import std.regex; void main() { assert(bmatch("e@", "^([a-z]|)*$").empty); assert(bmatch("e@", ctRegex!`^([a-z]|)*$`).empty); }
Comment #3 by github-bugzilla — 2014-05-13T00:33:52Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/520438d9ef3f80af3e6c790798cfab4158e3402f Fix issue 12691 std.regex.bmatch bug in empty OR operator inside of ()* Must save variables that track advancement inside of infinite loops on per-thread basis. Apparently no amount of trickery would let us avoid it. https://github.com/D-Programming-Language/phobos/commit/5ac0225a5b1fcde88864bc5705323cc398948b47 Merge pull request #2164 from DmitryOlshansky/issue-12691 Fix issue 12691 std.regex.bmatch bug in empty OR operator inside of ()*