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 infinite loop with MATCH_INVALID_UTF in PCRE2 <10.36 #13311

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Apr 13, 2023

The MATCH_INVALID_UTF8 flag was introduced in PCRE2 10.34 but it has a bug that can lead to infinite loops. This bug is fixed in 10.36 and we should not use this flag with affected versions.

Fixes #13306

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:text labels Apr 13, 2023
@straight-shoota straight-shoota self-assigned this Apr 13, 2023
@HertzDevil
Copy link
Contributor

HertzDevil commented Apr 13, 2023

The infinite loop recreated in Crystal:

# prints only 0 on PCRE 10.34 and 10.35, proceeds on 10.36+
(0..).each do |i|
  p i
  "\u{e7}#a" =~ /^.a/m
end

Locally I could confirm that a JIT-enabled PCRE2 10.36 runs make docs correctly whereas 10.35 gets stuck without this patch.

Some Regex specs need their version checks replaced (Regex::Engine.version_number < {10, 34} etc.).

@beta-ziliani
Copy link
Member

There is one more spec with < 10.35 that probably should be bumped to 10.36

@straight-shoota straight-shoota changed the title Fix infinite loop with MATCH_INVALID_UTF8 in PCRE2 <10.36 Fix infinite loop with MATCH_INVALID_UTF in PCRE2 <10.36 Apr 13, 2023
@straight-shoota straight-shoota merged commit c7d7042 into crystal-lang:master Apr 13, 2023
@straight-shoota straight-shoota deleted the fix/pcre2-invalid_utf-infinite-loop branch April 13, 2023 13:25
@straight-shoota straight-shoota added this to the 1.8.0 milestone Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinite loop in PCRE2 10.34 (affecting crystal docs)
3 participants