왜 다음과 같은 segfault가 있으며 어떻게 방지 할 수 있습니까?PHP regex segfault를 방지해야합니다.
<?php
$str = ' <fieldset> <label for="go-to">Go to: </label> '
. str_repeat(' ', 10000)
. '<input type="submit" value="Go" /> </fieldset> </form>';
preg_match_all("@
</?(?![bisa]\b)(?!em\b)[^>]*> # starting tag, must not be one of several inline tags
(?:[^<]|</?(?:(?:[bisau]|em|strong|sup)\b)[^>]*>)* #allow text and some inline tags
[\?\!\.]+
@ix", $str, $matches);
?>
나는 그것이 ...를 기다리고 있다고 생각합니다 .... 스택 오버플로.
편집 :
위의 단순화 된 버전이 문제를 보여줍니다 패턴입니다. 더 완전한 버전 :
@
</?(?![bisa]\b)(?!em\b)[^>]*> # starting tag, must not be one of several inline tags
(?:[^<]|</?(?:(?:[bisau]|em|strong|sup)\b)[^>]*>)* # continue, allow text content and some inline tags
# normal sentence ending
[\?\!\.]+ # valid ending characters -- note elipses allowed
(?<!\b[ap]m\.)(?<!\b[ap]\.m\.)(?<!digg this\!)(?<!Stumble This\!) # disallow some false positives that we don't care about
\s*
(?:'|&\#0*34;|'|‘)?\s* # closing single quotes, in the unusual case like "he said: 'go away'".
(?:"|"|&\#0*34;|&\#x0*22;|”|&\#0*8221;|&\#x0*201D;|''|``|\xe2\x80\x9d|&\#0*148;|&\#x0*94;|\x94|\))?\s* # followed by any kind of close-quote char
(?=\<) # should be followed by a tag.
@ix
목적은 유효한 영어 문장 끝 모양처럼 보이는 것으로 끝나는 것처럼 보이는 html 블록을 찾는 것입니다. 나는이 방법이 '내용'텍스트 (기사 본문과 같은)와 '레이아웃'텍스트 (탐색 요소와 같음)의 차이를 말하는 데 매우 효과적이라는 것을 발견했습니다. 때로는 태그 사이에 방대한 양의 공백이있을 경우 블로깅됩니다.
멋진 별명, ʞɔıu! – Boldewyn
Intresting - 충돌을 재현 할 수 있습니다. 나는 당신이 충돌을 멈출 때까지 요소를 꺼내면서 정규 표현식을 해체 할 것을 제안한다. 그런 다음 충돌을 일으키는 요소를 취할 수 있는지 확인하고 segfaults 인 가장 간단한 예제를 만들고 bugs.php.net에 로그인하십시오. –
정규식 엔진의 버그라고 생각하지 않습니다. 난 그냥 당신이 거꾸로 처리하는 거대한 스택을 구축하고 있다고 생각합니다. 아마 당신이 무엇을 잡으려고하는지 설명 할 수 있다면 우리는 더 적은 역 추적으로 대체 정규 표현을 제안 할 수 있습니다. –