Fix infinite loop if section header has ( (#283)

This commit is contained in:
Jonathan Lee 2024-07-22 17:33:18 -05:00 committed by GitHub
parent 1aef9d71af
commit cf3b9cc6a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -480,9 +480,7 @@ class LST {
} }
if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE ) ) { if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE ) ) {
$mata = []; $begin_off = end($m)[1];
$no_parenthesis = preg_match_all( '/\(/', $pat, $mata );
$begin_off = $m[$no_parenthesis][1];
$head_len = strlen( $m[1][0] ); $head_len = strlen( $m[1][0] );
$headLine = trim( $m[0][0], "\n =\t" ); $headLine = trim( $m[0][0], "\n =\t" );
} elseif ( $nr == -2 ) { } elseif ( $nr == -2 ) {
@ -559,6 +557,11 @@ class LST {
if ( $sec == '' ) { if ( $sec == '' ) {
$continueSearch = false; $continueSearch = false;
} else { } else {
if ( $end_off == 0 ) {
// we have made no progress - something has gone wrong, but at least don't loop forever
break;
}
// this could lead to quadratic runtime...
$text = substr( $text, $end_off ); $text = substr( $text, $end_off );
} }
} else { } else {