Skip to content

Commit 2c9dc59

Browse files
committed
fix(FTB): always strip path in assertion messages
1 parent 88849db commit 2c9dc59

2 files changed

Lines changed: 47 additions & 24 deletions

File tree

FTB/AssertionHelper.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ def getSanitizedAssertionPattern(msgs):
231231
idx += len(chunk) + 1
232232
bsPositions = [bs + 1 if bs > idx else bs for bs in bsPositions]
233233

234+
# Each entry is (match_regex, replacement_text). For most patterns the
235+
# two are identical, but path patterns match with a boundary-restricted
236+
# class while writing a clean `.+/` into the sanitized output.
234237
replacementPatterns = []
235238

236239
# Specific TSan patterns
@@ -252,24 +255,27 @@ def getSanitizedAssertionPattern(msgs):
252255
# Replace rust thread #s
253256
replacementPatterns.append("Thread#[0-9]+' panicked")
254257

255-
# Strip full paths
256-
pathPattern = "([a-zA-Z]:)?/.+/"
258+
replacementPatterns = [(p, p) for p in replacementPatterns]
259+
260+
# Strip full paths. Match using a boundary-restricted class so we don't
261+
# greedily consume text preceding the path, but emit `.+/` as the
262+
# replacement so the resulting signature stays readable.
263+
pathMatch = "[^ '\",(]+/"
264+
pathReplace = ".+/"
257265

258266
# In order to reliably identify paths, we require them to be prefixed
259267
# by some character that doesn't belong to the path. It turns out that
260268
# spaces, quotes and comma are the only things used in the assertions
261269
# we support so far. However, we don't want to group these characters
262270
# into a regex so avoid cluttering the signature too much.
263-
replacementPatterns.append(" " + pathPattern)
264-
replacementPatterns.append("'" + pathPattern)
265-
replacementPatterns.append('"' + pathPattern)
266-
replacementPatterns.append("," + pathPattern)
271+
for prefix in (" ", "'", '"', ","):
272+
replacementPatterns.append((prefix + pathMatch, prefix + pathReplace))
267273

268274
# Replace larger numbers, assuming that 1-digit numbers are likely
269275
# some constant that doesn't need sanitizing.
270-
replacementPatterns.append("[0-9]{2,}")
276+
replacementPatterns.append(("[0-9]{2,}", "[0-9]{2,}"))
271277

272-
for replacementPattern in replacementPatterns:
278+
for matchPattern, replacementPattern in replacementPatterns:
273279

274280
def _handleMatch(match):
275281
start = match.start(0)
@@ -294,7 +300,7 @@ def _handleMatch(match):
294300

295301
return replacementPattern
296302

297-
sanitizedMsg = re.sub(replacementPattern, _handleMatch, sanitizedMsg)
303+
sanitizedMsg = re.sub(matchPattern, _handleMatch, sanitizedMsg)
298304

299305
# backslashes were replaced with / for unified path handling (and because
300306
# backslash is the escape character, which makes pattern matching otherwise
@@ -308,7 +314,7 @@ def _handleMatch(match):
308314

309315
# Some implementations wrap the path into parentheses. We cannot add this to
310316
# replacementPatterns because it would double-escape the leading parenthesis.
311-
sanitizedMsg = re.sub("\\(" + pathPattern, "(" + pathPattern, sanitizedMsg)
317+
sanitizedMsg = re.sub("\\(" + pathMatch, "(" + pathReplace, sanitizedMsg)
312318

313319
sanitizedMsgs.append(sanitizedMsg)
314320

FTB/tests/test_AssertionHelper.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_AssertionHelperTestMozCrash():
7676
)
7777
expectedMsg = (
7878
r"Hit MOZ_CRASH\(named lambda static scopes should have been skipped\) at "
79-
r"([a-zA-Z]:)?/.+/ScopeObject\.cpp(:[0-9]+)+"
79+
r".+/ScopeObject\.cpp(:[0-9]+)+"
8080
)
8181
assert sanitizedMsg == expectedMsg
8282
_check_regex_matches(err, sanitizedMsg)
@@ -94,7 +94,7 @@ def test_AssertionHelperTestMozCrashMultiLine():
9494
)
9595
assert sanitizedMsg[-1] == (
9696
r" combined_local_clip_rect\.size\.height >= 0\.0\)"
97-
r" at gfx/wr/webrender/src/prim_store/mod\.rs(:[0-9]+)+"
97+
r" at .+/mod\.rs(:[0-9]+)+"
9898
)
9999
_check_regex_matches(err, sanitizedMsg)
100100

@@ -106,7 +106,7 @@ def test_AssertionHelperTestMozCrashWithPath():
106106
AssertionHelper.getAssertion(err)
107107
)
108108
expectedMsg = (
109-
r"Hit MOZ_CRASH\(([a-zA-Z]:)?/.+/celt_decoder\.c(:[0-9]+)+ assertion failed: "
109+
r"Hit MOZ_CRASH\(.+/celt_decoder\.c(:[0-9]+)+ assertion failed: "
110110
r"st->start < st->end\) at nil(:[0-9]+)+"
111111
)
112112
assert sanitizedMsg == expectedMsg
@@ -121,7 +121,7 @@ def test_AssertionHelperTestMultiMozCrash():
121121
)
122122
expectedMsg = (
123123
r"Hit MOZ_CRASH\(good message\) at "
124-
r"([a-zA-Z]:)?/.+/spatial_node\.rs(:[0-9]+)+"
124+
r".+/spatial_node\.rs(:[0-9]+)+"
125125
)
126126
assert sanitizedMsg == expectedMsg
127127
_check_regex_matches(err, sanitizedMsg)
@@ -138,7 +138,7 @@ def test_AssertionHelperTestJSSelfHosted():
138138
AssertionHelper.getAssertion(err)
139139
)
140140
expectedMsg = (
141-
r'Self-hosted JavaScript assertion info: "([a-zA-Z]:)?/.+/Intl\.js(:[0-9]+)+: '
141+
r'Self-hosted JavaScript assertion info: ".+/Intl\.js(:[0-9]+)+: '
142142
r'non-canonical BestAvailableLocale locale"'
143143
)
144144

@@ -156,7 +156,7 @@ def test_AssertionHelperTestV8Abort():
156156
assert len(sanitizedMsgs) == 2
157157

158158
expectedMsgs = [
159-
r"# Fatal error in \.\./src/compiler\.cc, line [0-9]+",
159+
r"# Fatal error in .+/compiler\.cc, line [0-9]+",
160160
(
161161
r"# Check failed: !feedback_vector_->metadata\(\)->SpecDiffersFrom\( "
162162
r"literal\(\)->feedback_vector_spec\(\)\)\."
@@ -174,7 +174,7 @@ def test_AssertionHelperTestChakraAssert():
174174
AssertionHelper.getAssertion(err)
175175
)
176176
expectedMsg = (
177-
r"ASSERTION [0-9]{2,}: \(([a-zA-Z]:)?/.+/ByteCodeEmitter\.cpp, line [0-9]+\) "
177+
r"ASSERTION [0-9]{2,}: \(.+/ByteCodeEmitter\.cpp, line [0-9]+\) "
178178
r"scope->HasInnerScopeIndex\(\)"
179179
)
180180

@@ -200,7 +200,7 @@ def test_AssertionHelperTestWindowsPathSanitizing():
200200

201201
expectedMsg = (
202202
r"Assertion failure: block->graph\(\)\.osrBlock\(\), at "
203-
r"([a-zA-Z]:)?/.+/Lowering\.cpp(:[0-9]+)+"
203+
r".+/Lowering\.cpp(:[0-9]+)+"
204204
)
205205

206206
assert sanitizedMsg1 == expectedMsg
@@ -217,6 +217,26 @@ def test_AssertionHelperTestWindowsPathSanitizing():
217217
# _check_regex_matches(err2, sanitizedMsg2)
218218

219219

220+
def test_AssertionHelperTestRelativePath():
221+
err = ["Assertion failure: false, at foo/FileName.cpp:123"]
222+
sanitizedMsg = AssertionHelper.getSanitizedAssertionPattern(
223+
AssertionHelper.getAssertion(err)
224+
)
225+
expectedMsg = r"Assertion failure: false, at .+/FileName\.cpp(:[0-9]+)+"
226+
assert sanitizedMsg == expectedMsg
227+
_check_regex_matches(err, sanitizedMsg)
228+
229+
230+
def test_AssertionHelperTestBareFilename():
231+
err = ["Assertion failure: false, at FileName.cpp:123"]
232+
sanitizedMsg = AssertionHelper.getSanitizedAssertionPattern(
233+
AssertionHelper.getAssertion(err)
234+
)
235+
expectedMsg = r"Assertion failure: false, at FileName\.cpp(:[0-9]+)+"
236+
assert sanitizedMsg == expectedMsg
237+
_check_regex_matches(err, sanitizedMsg)
238+
239+
220240
def test_AssertionHelperTestAuxiliaryAbortASan():
221241
err = (
222242
(FIXTURE_PATH / "assert_asan_heap_buffer_overflow.txt").read_text().splitlines()
@@ -254,7 +274,7 @@ def test_AssertionHelperTestRustPanic01():
254274
expectedMsg = (
255275
r"thread 'StyleThread#[0-9]+' panicked at "
256276
r"'assertion failed: self\.get_data\(\)\.is_some\(\)', "
257-
r"([a-zA-Z]:)?/.+/wrapper\.rs(:[0-9]+)+"
277+
r".+/wrapper\.rs(:[0-9]+)+"
258278
)
259279

260280
assert sanitizedMsg == expectedMsg
@@ -268,7 +288,7 @@ def test_AssertionHelperTestRustPanic02():
268288
)
269289
expectedMsg = (
270290
r"thread 'RenderBackend' panicked at 'called `Option::unwrap\(\)` "
271-
r"on a `None` value', ([a-zA-Z]:)?/.+/option\.rs(:[0-9]+)+"
291+
r"on a `None` value', .+/option\.rs(:[0-9]+)+"
272292
)
273293

274294
assert sanitizedMsg == expectedMsg
@@ -286,8 +306,5 @@ def test_AssertionHelperTestRustPanic03():
286306
sanitizedMsg[0]
287307
== r"thread '<unnamed>' panicked at 'assertion failed: `\(left == right\)`"
288308
)
289-
assert (
290-
sanitizedMsg[-1]
291-
== r" right: `Block`', ([a-zA-Z]:)?/.+/style_adjuster\.rs(:[0-9]+)+"
292-
)
309+
assert sanitizedMsg[-1] == r" right: `Block`', .+/style_adjuster\.rs(:[0-9]+)+"
293310
_check_regex_matches(err, sanitizedMsg)

0 commit comments

Comments
 (0)