-
Notifications
You must be signed in to change notification settings - Fork 726
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
CH_CALLBACK_SKIP_PATTERN causes infinite loop in ch_scan() with patterns of empty matches #360
Comments
Had a closer look at the https://github.com/intel/hyperscan/blob/master/chimera/ch_runtime.c#L338-L348 338 if (hyctx->length >= pd->scanStart &&
339 !(pattern->flags & CHIMERA_PATTERN_FLAG_SINGLEMATCH)) {
340 DEBUG_PRINTF("get a new match item\n");
341 int ret = scanPcre(hyctx, len, start, top_id);
342
343 if (ret == CH_CALLBACK_TERMINATE) {
344 DEBUG_PRINTF("user callback told us to terminate scanning\n");
345 return CH_SCAN_TERMINATED;
346 } else if (ret == CH_CALLBACK_SKIP_PATTERN) {
347 DEBUG_PRINTF("user callback told us to skip this pattern\n");
348 pd->scanStart = hyctx->length; It looks to me the conditional at line 338 should be |
This change simply avoids infinite loop for CH_CALLBACK_SKIP_PATTERN flag in your case, but might result in losing the last match id=3, from=38, to=38 for CH_CALLBACK_CONTINUE flag. We'll come with a fix soon. |
fix github issue intel#360
Please refer to latest develop branch. |
Hi, I recently noticed an infinite loop in our program and found the issue to be related with
CH_CALLBACK_SKIP_PATTERN
.When there are patterns that may match empty strings, the
CH_CALLBACK_SKIP_PATTERN
return value from the callback would cause an infinite loop inch_scan()
, specifically incatchupPcre()
. I've reproduced the issue with Hyperscan 5.1.1 and 5.4.0.Below is a test program:
And here is the output log:
So it just keeps repeating the last
id=3, from=38, to=38
...If return
CH_CALLBACK_CONTINUE
from the callback,ch_scan()
works correctly.Please have a look and hope the above test program helps.
Thank you.
The text was updated successfully, but these errors were encountered: