mudge / re2

Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python".
http://mudge.name/re2/
BSD 3-Clause "New" or "Revised" License
130 stars 13 forks source link

RE2.QuoteMeta doesn’t work with strings containing null byte. #130

Closed manueljacob closed 9 months ago

manueljacob commented 9 months ago

I’d expect RE2.QuoteMeta("abc\0def") to return "abc\\x00def" but it returns "abc". The reason is that in https://github.com/mudge/re2/blob/v2.6.0/ext/re2/re2.cc#L1756, RSTRING_PTR is used to convert the Ruby String to char *. RE2::QuoteMeta then interprets it as a null-terminated string. In addition to the truncation problem, according to the Ruby documentation, the result of RSTRING_PTR may not be NUL-terminated, potentially leading to a buffer over-read.

mudge commented 9 months ago

Thanks for reporting this, @manueljacob.

This should now be fixed in the newly released 2.7.0, can you please let me know if that resolves your issue?

It should also fix handling of null bytes across the library where possible (note that null bytes are not valid in capturing group names as that is dictated by RE2 itself).

manueljacob commented 9 months ago

It works for me, thank you!