← All issues

[JSC] Implement Variable Count Parentheses in YarrJIT

6646c49

// JSTests/stress/regexp-greedy-nested-quantifier-backtrack.js
test(/((a+){2,3}){2,3}$/, "aaaaaa", "aaaaaa");
test(/((a+){2,4}){2,3}$/, "aaaaaa", "aaaaaa");
test(/(((a+){2}){2}){1,2}$/, "aaaa", "aaaa");
test(/((a+){2,3}){2,3}$/, "aaa", null);  // must correctly fail

YarrJIT는 ECMAScript 정규 표현식을 native machine code로 직접 컴파일합니다. backtracking 중 capture group 상태를 저장하고 복원하기 위해 ParenContext 객체를 사용합니다. 이전에는 최솟값이 0이 아닌 variable-count 그룹(예: {3,5})이 포함된 경우 JIT 컴파일이 실패하여, 조용히 느린 interpreter로 실행이 전환되었습니다.

이 commit은 m > 0{m,n} 괄호 quantifier를 JIT로 컴파일할 수 있도록 YarrJIT를 확장했습니다. 새로 도입된 count 강제 backtracking 경로는 다음과 같이 동작합니다. backtracking 중 반복 횟수가 최솟값 미만으로 떨어지면, 즉시 실패하는 대신 End.contentBacktrackEntryLabel을 통해 최근 iteration의 내용으로 재진입하여 대안 분기를 시도합니다. zero-length match가 발생하면 interpreter로 처리를 위임합니다. 한편 YarrInterpreter.cpp에도 동일한 correctness fix가 병행 적용되었습니다.

복잡한 backtracking state machine에 대해 안전한 interpreter fallback을 대신하는 새 JIT native code가 도입되었습니다. regex engine에서 correctness 버그, 나아가 memory safety 문제가 발견된 사례가 역사적으로 많은 영역인 만큼, 주의 깊은 검토가 필요합니다.

🔒

New JIT backtracking state machine with multi-level quantifier nesting — edge cases in count enforcement and capture group save/restore are worth auditing.

더 확인하려면 구독해 주세요