You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ok, so a bit of background here. The original intent of the interruptibility was to ensure long-running regular expressions could be stopped. By long running here we mean things like regular expressions with complex alternations... not regular expressions that get stuck because of bad character encoding.
This case, and likely many others, are not interruptible because they get stuck in a tight inner loop trying endlessly to advance a byte offset for a broken multibyte characters. In this case, the code get stuck here:
Adding an interrupt check here would add a lot of overhead to this search logic, so I'm reluctant to do that. We have discussed making joni more robust in the presence of bad character data, however, since there's several places like this that can get stuck.
So unfortunately right now there's no workaround to make interrupting work for your case. It should really be an error. We'll discuss a bit and see if we can figure out a good path forward.
int max = enc.maxLength();
if(max==1) {
while (s < end) {
if (lowerCaseMatch(target, targetP, targetEnd, text, s, textEnd, enc, buf, regex.caseFoldFlag)) return s;
s += enc.length(text, s, textEnd);
}
} else {
int count = s;
while (s < textRange) {
if (lowerCaseMatch(target, targetP, targetEnd, text, s, textEnd, enc, buf, regex.caseFoldFlag)) return s;
int val = enc.length(text, s, textEnd);
if (val > 0) {
s += val;
count += val;
} else {
if (max + s + val < count) {
s += 1;
count = s;
} else { //I believe it shouldn't lag too much behind ?
s += val;
count += 1;
}
}
}
}
besides SLOW_IC_FORWARD, I've also modified MAP_FORWARD,they are similiar.
I wonder is it bad though.
This looks like a decent change! We were discussing on the JRuby matrix how to fix this, and I believe a similar fix was suggested. @lopex What do you think?
I'm reluctant to such changes since they will introduce inconsistencies and diverge us from onigmo even more. The problem is explained more thoroughly in jruby/jcodings#26
Activity
headius commentedon Feb 10, 2020
Hmmm I would have expected that to work. Trying locally.
headius commentedon Feb 10, 2020
Ok, so a bit of background here. The original intent of the interruptibility was to ensure long-running regular expressions could be stopped. By long running here we mean things like regular expressions with complex alternations... not regular expressions that get stuck because of bad character encoding.
This case, and likely many others, are not interruptible because they get stuck in a tight inner loop trying endlessly to advance a byte offset for a broken multibyte characters. In this case, the code get stuck here:
joni/src/org/joni/Search.java
Lines 204 to 207 in 495de01
Adding an interrupt check here would add a lot of overhead to this search logic, so I'm reluctant to do that. We have discussed making joni more robust in the presence of bad character data, however, since there's several places like this that can get stuck.
So unfortunately right now there's no workaround to make interrupting work for your case. It should really be an error. We'll discuss a bit and see if we can figure out a good path forward.
KnIfER commentedon Feb 11, 2020
what about this ?
besides
SLOW_IC_FORWARD, I've also modifiedMAP_FORWARD,they are similiar.I wonder is it bad though.
headius commentedon Feb 11, 2020
This looks like a decent change! We were discussing on the JRuby matrix how to fix this, and I believe a similar fix was suggested. @lopex What do you think?
lopex commentedon Feb 11, 2020
I'm reluctant to such changes since they will introduce inconsistencies and diverge us from onigmo even more. The problem is explained more thoroughly in jruby/jcodings#26
lopex commentedon Feb 11, 2020
Also, jruby/jcodings#26 shows that those infinite loops will exist in other places and it would not be ideal to randomly patch susceptible callsites.
lopex commentedon Feb 11, 2020
For this very case, a quick fix would be to add an unsafe GB18030 version in the same fashion https://github.com/jruby/jcodings/tree/unsafe-encoding aims to.