Skip to content

Commit

Permalink
bug-1764633: remove non-printable/non-ascii characters from signature (
Browse files Browse the repository at this point in the history
…#6782)

The crash signature contains data from stackwalker output as well as
JavaException annotations and other places, too. Because of this, it's
possible for the signature to contain non-ascii and non-printable
characters. This rule restricts signatures to printable ASCII
characters.
  • Loading branch information
willkg authored Nov 1, 2024
1 parent cce2032 commit 8bf7b51
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions socorro/signature/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SignatureIPCMessageName,
SignatureRunWatchDog,
SignatureShutdownTimeout,
SigPrintableCharsOnly,
SigTruncate,
StackOverflowSignature,
StackwalkerErrorSignatureRule,
Expand All @@ -37,6 +38,7 @@
StackOverflowSignature,
HungProcess,
# NOTE(willkg): These should always come last and in this order
SigPrintableCharsOnly,
SigFixWhitespace,
SigTruncate,
]
Expand Down
14 changes: 14 additions & 0 deletions socorro/signature/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,20 @@ def action(self, crash_data, result):
return True


class SigPrintableCharsOnly(Rule):
"""Remove non-printable characters from signature."""

def action(self, crash_data, result):
original_sig = result.signature
sig = "".join(
[c for c in original_sig.strip() if c.isascii() and c.isprintable()]
)
if sig != original_sig:
result.set_signature(self.name, sig)
result.info(self.name, "unprintable characters removed")
return True


class SigFixWhitespace(Rule):
"""Fix whitespace in signatures.
Expand Down
24 changes: 24 additions & 0 deletions socorro/signature/tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,30 @@ def test_action_non_ascii_abort_message(self):
assert result.signature == "Abort | unknown | hello"


class TestSigPrintableCharsOnly:
@pytest.mark.parametrize(
"signature, expected",
[
("everything | fine", "everything | fine"),
# Non-printable null character
("libxul.so\x00 | frame2", "libxul.so | frame2"),
# Non-ascii emoji
("libxul.so\U0001f600 | frame2", "libxul.so | frame2"),
],
)
def test_whitespace_fixing(self, signature, expected):
rule = rules.SigPrintableCharsOnly()
result = generator.Result()
result.signature = signature
action_result = rule.action({}, result)
assert action_result is True
assert result.signature == expected
if signature != expected:
assert result.notes == [
"SigPrintableCharsOnly: unprintable characters removed"
]


class TestSigFixWhitespace:
@pytest.mark.parametrize(
"signature, expected",
Expand Down

0 comments on commit 8bf7b51

Please sign in to comment.