It is currently March 28th, 2024, 7:50 pm

[FIX BRINGS NEW PROBLEM]bad regular expression crashes Rai

Report bugs with the Rainmeter application and suggest features.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

[FIX BRINGS NEW PROBLEM]bad regular expression crashes Rai

Post by moshi »

i managed to crash Rainmeter with a bad regular expression (this is just a report, no need for help, i solved it already):

Code: Select all

[MeasureWOEIDS]
Measure=String
String=https://weather.yahoo.com/austria/tyrol/innsbruck-550763/
RegExpSubstitute=1
Substitute="^.*(\d*).*$":"\1"
this shouldn't happen in my opinion.

3.2.0 beta r2355 64-bit (Jan 27 2015)
Windows 8.1 64-bit (build 9600)
Path: C:\Program Files\Rainmeter\
IniFile: C:\Users\Alex\AppData\Roaming\Rainmeter\Rainmeter.ini
SkinPath: C:\Users\Alex\Documents\Rainmeter\Skins\
Last edited by moshi on May 27th, 2015, 8:11 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG] bad regular expression crashes Rainmeter

Post by jsmorley »

Thanks for the report. I'll try to run it in Studio and see if I can spot where it is blowing up. It would be easier if it was in fact "crashing", but it isn't. It just causes Rainmeter to become "unresponsive".
/^.*(\d*).*$/
^ assert position at start of the string
.* matches any character (except newline)
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
1st Capturing group (\d*)
\d* match a digit [0-9]
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
.* matches any character (except newline)
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
$ assert position at end of the string
In my view that should at best return "3" (or more likely nothing) from your string since it is "greedy" and does a ton of backtracking and "giving back" due to the .* sequences, but certainly shouldn't bork things.

Seems to me that:

Substitute="^\D*(\d+)\D*$":"\1"

Would work. Doesn't cause it to "eat" the entire string, then backtrack to figure out what to keep and what to give back. "Any number character" is also "any character".
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG] bad regular expression crashes Rainmeter

Post by jsmorley »

moshi wrote:i managed to crash Rainmeter with a bad regular expression (this is just a report, no need for help, i solved it already):

Code: Select all

[MeasureWOEIDS]
Measure=String
String=https://weather.yahoo.com/austria/tyrol/innsbruck-550763/
RegExpSubstitute=1
Substitute="^.*(\d*).*$":"\1"
this shouldn't happen in my opinion.
This has been corrected in the 3.3 r2414 beta. Sorry it took so long, but this was a rare enough issue that it kept falling off the radar.

The initial .* used in a greedy way will cause the expression to first immediately zoom out to the end of the string. All the characters in the string match "any character". Then it will start backtracking and giving back to try and make the match on the capture.

[MeasureWOEIDS]
Measure=String
String=https://weather.yahoo.com/austria/tyrol/innsbruck-550763/
RegExpSubstitute=1
Substitute="^.*(\d*).*$":"\1"

Will return "", since the "zero or more" quantifiers will cause PCRE to basically "give back" everything it matches as it backtracks into the string.

[MeasureWOEIDS]
Measure=String
String=https://weather.yahoo.com/austria/tyrol/innsbruck-550763/
RegExpSubstitute=1
Substitute="^.*(\d+).*$":"\1"

Will return "3", since the "one or more" quantifier will capture the "last" \d in the string as it backtracks into the string.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: [Solved] bad regular expression crashes Rainmeter

Post by moshi »

try this:

Code: Select all

[MeasureTest]
Measure=String
String=""
RegExpSubstitute=1
Substitute="^$":"eh!"
:/

this is new with the latest version. not good at all.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Solved] bad regular expression crashes Rainmeter

Post by jsmorley »

moshi wrote:try this:

Code: Select all

[MeasureTest]
Measure=String
String=""
RegExpSubstitute=1
Substitute="^$":"eh!"
:/

this is new with the latest version. not good at all.
Yes, that is clearly a deal-breaker. We will look into it.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [FIX BRINGS NEW PROBLEM]bad regular expression crashes R

Post by jsmorley »

Moshi,

Can you do us a HUGE favor and beat the crap out of this?

http://builds.rainmeter.net/Rainmeter-3.3-r2415-beta.exe

We hope this one works correctly in all situations.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: [FIX BRINGS NEW PROBLEM]bad regular expression crashes R

Post by moshi »

i think it broke something if you combine a negative lookahead with zero or more in a regular expression.
sorry, no example. fixed the skin in question a few days ago but didn't remember to copy the old expression.
but then negative lookaheads aren't used that often in Rainmeter skins.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: [FIX BRINGS NEW PROBLEM]bad regular expression crashes R

Post by moshi »

ok, found it:

Code: Select all

[MeterTest]
Measure=String
String=chicken
RegExpSubstitute=1
Substitute="^(?(?!chicken).*)":"dog"
this returns in r2413 and earlier: dogchicken
this returns in r2414 and earlier: chicken

please don't ask me which one would be the correct result :confused: