-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconfig.py
More file actions
216 lines (197 loc) · 5.92 KB
/
Copy pathconfig.py
File metadata and controls
216 lines (197 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
"""
PatchFuzz 引擎配置
每个 JS 引擎的配置包括:
- POC 路径模式
- Bug 识别规则
- 源码路径过滤
- JS 预处理规则
"""
from dataclasses import dataclass, field
from typing import List, Pattern
import re
@dataclass
class BugPatterns:
"""Bug 识别模式"""
message_patterns: List[Pattern] # commit message 中的 bug 关键词
poc_path_pattern: Pattern # POC 文件路径模式
url_patterns: List[Pattern] # bug URL 模式
exclude_patterns: List[Pattern] = field(default_factory=list) # 排除模式
@dataclass
class AllowlistFilter:
"""Allowlist 过滤规则"""
source_extensions: List[str] = field(default_factory=lambda: ['.c', '.h', '.cpp', '.cc'])
path_prefix: str = '' # 源码路径前缀过滤
@dataclass
class JSProcessorRules:
"""JS 文件预处理规则"""
skip_patterns: List[str] # 包含这些字符串的文件跳过
wasm_patterns: List[str] # WebAssembly 相关模式(跳过)
replacements: List[tuple] # (pattern, replacement) 替换规则
@dataclass
class EngineConfig:
"""引擎完整配置"""
name: str
bug_patterns: BugPatterns
allowlist_filter: AllowlistFilter
processor_rules: JSProcessorRules
# ============== JSC (WebKit) ==============
JSC_CONFIG = EngineConfig(
name='jsc',
bug_patterns=BugPatterns(
message_patterns=[
re.compile(r'^bug', re.IGNORECASE),
re.compile(r'fix', re.IGNORECASE),
re.compile(r'crash', re.IGNORECASE),
],
poc_path_pattern=re.compile(r'JSTests/stress'),
url_patterns=[
re.compile(r'bugs\.webkit\.org'),
re.compile(r'http://webkit\.org/b/'),
],
),
allowlist_filter=AllowlistFilter(
path_prefix='Source/JavaScriptCore',
),
processor_rules=JSProcessorRules(
skip_patterns=[
'export ',
'$vm.Element;',
'$vm.Root;',
'$vm.getElement;',
],
wasm_patterns=[
'isWasmSupported',
'wasmCode',
'wasmEntry',
],
replacements=[
(r'\$vm[.]\w+', 'print'),
(r'abort\(', 'print('),
(r'assert[.]?\w* ?\(', 'print('),
(r'\(assert\w*\)', '(print)'),
(r'generateBinaryTests\(', 'print('),
(r'load\(', 'print('),
],
),
)
# ============== V8 ==============
V8_CONFIG = EngineConfig(
name='v8',
bug_patterns=BugPatterns(
message_patterns=[
re.compile(r'^bug', re.IGNORECASE),
re.compile(r'fix', re.IGNORECASE),
],
poc_path_pattern=re.compile(r'test/mjsunit/regress'),
url_patterns=[
re.compile(r'chromium-review\.googlesource\.com'),
re.compile(r'codereview\.chromium\.org'),
],
exclude_patterns=[
re.compile(r'^Bug:$'),
re.compile(r'^BUG=$'),
re.compile(r'^BUG=none$'),
],
),
allowlist_filter=AllowlistFilter(),
processor_rules=JSProcessorRules(
skip_patterns=['export '],
wasm_patterns=['WasmModuleBuilder('],
replacements=[
(r'assert[.]?\w* ?\(', 'print('),
(r'd8[.]file[.]execute\(.*\);?', ''),
],
),
)
# ============== SpiderMonkey (Firefox) ==============
SM_CONFIG = EngineConfig(
name='sm',
bug_patterns=BugPatterns(
message_patterns=[
re.compile(r'bug #?\d+', re.IGNORECASE),
re.compile(r'fix', re.IGNORECASE),
re.compile(r'crash', re.IGNORECASE),
re.compile(r'b=\d+', re.IGNORECASE),
],
poc_path_pattern=re.compile(r'js/src/jit-test'),
url_patterns=[
re.compile(r'phabricator\.services\.mozilla\.com'),
],
exclude_patterns=[
re.compile(r'^Backed out', re.IGNORECASE),
],
),
allowlist_filter=AllowlistFilter(
path_prefix='js/src',
),
processor_rules=JSProcessorRules(
skip_patterns=[],
wasm_patterns=[
'instantiate(',
'wasmEvalText(',
'wasmTextToBinary(',
],
replacements=[
(r'assert[.]?\w* ?\(', 'print('),
(r'crash\(', 'print('),
(r'appendToActual\(', 'print('),
(r'load\(.*\)', ''),
],
),
)
# ============== ChakraCore ==============
CHAKRA_CONFIG = EngineConfig(
name='chakra',
bug_patterns=BugPatterns(
message_patterns=[
re.compile(r'^bug', re.IGNORECASE),
re.compile(r'fix', re.IGNORECASE),
re.compile(r'CVE'),
],
poc_path_pattern=re.compile(r'test/\S*[.]js'),
url_patterns=[],
),
allowlist_filter=AllowlistFilter(),
processor_rules=JSProcessorRules(
skip_patterns=[],
wasm_patterns=[],
replacements=[
(r'WScript\.\w+', 'print'),
(r'console\.log\(', 'print('),
(r'testRunner\.runTests\(', 'print('),
],
),
)
# ============== JerryScript ==============
JERRY_CONFIG = EngineConfig(
name='jerry',
bug_patterns=BugPatterns(
message_patterns=[
re.compile(r'^bug', re.IGNORECASE),
re.compile(r'fix', re.IGNORECASE),
],
poc_path_pattern=re.compile(r'tests/.*[.]js'),
url_patterns=[],
),
allowlist_filter=AllowlistFilter(
path_prefix='jerry',
),
processor_rules=JSProcessorRules(
skip_patterns=['export '],
wasm_patterns=[],
replacements=[],
),
)
# 引擎配置映射
ENGINE_CONFIGS = {
'jsc': JSC_CONFIG,
'v8': V8_CONFIG,
'sm': SM_CONFIG,
'chakra': CHAKRA_CONFIG,
'jerry': JERRY_CONFIG,
}
def get_engine_config(name: str) -> EngineConfig:
"""获取引擎配置"""
if name not in ENGINE_CONFIGS:
raise ValueError(f"Unknown engine: {name}. Available: {list(ENGINE_CONFIGS.keys())}")
return ENGINE_CONFIGS[name]