Sublime Forum

Crash on Find in Files by regex

#1

Try to find in files (*.asp, *.js, *.inc) by next regex.

(\w+?)\s*?=\s*?GetDBConnection(.|\n)*?\1.]\w+?

ST3 3047 crashes after a few seconds.

I know that this regex is not the best thing you’ve ever seen (it was written fast and dirty), but, I guess, its usage should not lead to crash.

0 Likes

#2

Hi - It works for me in ST3 3056, on Win7
(if I put this line in one of my .js files…)
a = GetDBConnection. a.b
(Note: there are 4 spaces at the end of the line that don’t show up here or in the results below, or the regex wouldn’t have matched. It requires at least 1.)

Results:
Searching 28 files for “(\w+?)\s*?=\s*?GetDBConnection(.|\n)*?\1.]\w+?” (regex)
C:\NodeJS\Apps\xxxxxxxxxxx\src\Client\js\Role - Copy.js:
51: a = GetDBConnection. a.b
1 match in 1 file

If I then change the regex to “(\w+?)\s*?=\s*?GetDBConnectionXXX***(.|\n)?\1.]\w+?" (something it can’t possibly find)
then I get
Searching 28 files for "(\w+?)\s
?=\s
?GetDBConnectionXXX(.|\n)*?\1.]\w+?” (regex)
0 matches across 0 files
but no crash.

0 Likes

#3

This is happening in ST3 3059 still. (Mac OS 10.9.3)
It happens on minified javascript when the file is large enough. Have not found the limits yet, but any file which exists on one very long line would likely trigger the crash.

Useful parts of the crash report for the dev:

Part of the crash report that
Application Specific Information:
terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injectorstd::runtime_error >: The complexity of matching the regular expression exceeded predefined bounds. Try refactoring the regular expression to make each choice made by the state machine unambiguous. This exception is thrown to prevent “eternal” matches that take an indefinite period time to locate.
abort() called

Thread 13 Crashed:: grep
0 libsystem_kernel.dylib 0x00007fff88e96866 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff834c135c pthread_kill + 92
2 libsystem_c.dylib 0x00007fff8293bb1a abort + 125
3 libc++abi.dylib 0x00007fff84f9df31 abort_message + 257
4 libc++abi.dylib 0x00007fff84fc393a default_terminate_handler() + 240
5 libobjc.A.dylib 0x00007fff82e41322 _objc_terminate() + 124
6 libc++abi.dylib 0x00007fff84fc11d1 std::__terminate(void ()()) + 8
7 libc++abi.dylib 0x00007fff84fc0e7b __cxa_rethrow + 109
8 com.sublimetext.3 0x000000010de4e258 boost::re_detail::perl_matcher<wchar_t const
, std::__1::allocator<boost::sub_match<wchar_t const*> >, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >::find_imp() + 580
9 com.sublimetext.3 0x000000010dbeb596 bool boost::regex_search<wchar_t const*, std::__1::allocator<boost::sub_match<wchar_t const*> >, wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >(wchar_t const*, wchar_t const*, boost::match_results<wchar_t const*, std::__1::allocator<boost::sub_match<wchar_t const*> > >&, boost::basic_regex<wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&, boost::regex_constants::_match_flags, wchar_t const*) + 76
10 com.sublimetext.3 0x000000010dbec6b8 boost::regex_iterator<wchar_t const*, wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >::regex_iterator(wchar_t const*, wchar_t const*, boost::basic_regex<wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&, boost::regex_constants::_match_flags) + 204
11 com.sublimetext.3 0x000000010dbe8e5c search_thread(void*) + 1533
12 libsystem_pthread.dylib 0x00007fff834c0899 _pthread_body + 138
13 libsystem_pthread.dylib 0x00007fff834c072a _pthread_start + 137
14 libsystem_pthread.dylib 0x00007fff834c4fc9 thread_start + 13

Thread 13 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x000000011e991000 rcx: 0x000000011e98fd68 rdx: 0x0000000000000000
rdi: 0x000000000000c01b rsi: 0x0000000000000006 rbp: 0x000000011e98fd90 rsp: 0x000000011e98fd68
r8: 0x0000000000000002 r9: 0x00007fff829638d0 r10: 0x0000000008000000 r11: 0x0000000000000206
r12: 0x000000011e98fef0 r13: 0x000000011f960dd0 r14: 0x0000000000000006 r15: 0x000000011e98fdd0
rip: 0x00007fff88e96866 rfl: 0x0000000000000206 cr2: 0x000000011e98cea0

0 Likes

#4

Though to be fair my regex was also quite terrible.
I wanted to find everywhere “mapp” appeared within quotes.

This crashed the find in files:
("(?:.)mApp(?:.)")

This does not. Negating character class does not cause backtracking so I believe it is the equivalent to what I was trying to do.
("^"]mApp^"]")

0 Likes

#5

[quote=“PaulECoyote”]Though to be fair my regex was also quite terrible.
I wanted to find everywhere “mapp” appeared within quotes.

This crashed the find in files:
("(?:.)mApp(?:.)")

This does not. Negating character class does not cause backtracking so I believe it is the equivalent to what I was trying to do.
("^"]mApp^"]")[/quote]

wow that’s pretty bad dude.

0 Likes