Skip to content

Commit

Permalink
Only keep in stack trace referenced debug images
Browse files Browse the repository at this point in the history
Remove the debug images not referenced in the stack trace so the debug
images don't contain customer data.

Fixes GH-46174
  • Loading branch information
philipphofmann committed Mar 29, 2023
1 parent 46dbf5d commit f038111
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/sentry/utils/sdk_crashes/event_stripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def strip_event_data(self, event: Event) -> Event:
stripped_frames = self._strip_frames(frames)
new_event["exception"]["values"][0]["stacktrace"]["frames"] = stripped_frames

debug_meta_images = get_path(event, "debug_meta", "images")
stripped_debug_meta_images = self._strip_debugMeta(debug_meta_images, stripped_frames)
new_event["debug_meta"]["images"] = stripped_debug_meta_images

return new_event

def _filter_event(self, pair):
Expand All @@ -49,6 +53,16 @@ def _filter_contexts(self, pair):
return True
return False

def _strip_debugMeta(
self, debug_meta_images: Sequence[Mapping[str, Any]], frames: Sequence[Mapping[str, Any]]
) -> Sequence[Mapping[str, Any]]:

frame_image_addresses = set(map(lambda frame: frame["image_addr"], frames))

return [
image for image in debug_meta_images if image["image_addr"] in frame_image_addresses
]

def _strip_frames(self, frames: Sequence[Mapping[str, Any]]) -> Sequence[Mapping[str, Any]]:
"""
Only keep SDK frames or non in app frames.
Expand Down
12 changes: 12 additions & 0 deletions tests/sentry/utils/sdk_crashes/test_event_stripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ def test_strip_frames(function, in_app):
len([frame for frame in stripped_frames if frame["function"] == IN_APP_FRAME["function"]])
== 0
), "in_app frame should be removed"


def test_strip_event_data_strips_non_referenced_dsyms():
event_stripper = EventStripper(Mock())

stripped_event = event_stripper.strip_event_data(get_crash_event())

debug_meta_images = get_path(stripped_event, "debug_meta", "images")

image_addresses = set(map(lambda image: image["image_addr"], debug_meta_images))
expected_image_addresses = {"0x1025e8000", "0x102b8c000", "0x102f68000", "0x19c9eb000"}
assert image_addresses == expected_image_addresses
56 changes: 49 additions & 7 deletions tests/sentry/utils/sdk_crashes/test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get_sentry_frame(function: str, in_app: bool = False) -> Mapping[str, Any]:
"function": function,
"package": "Sentry",
"in_app": in_app,
"image_addr": "0x102f68000",
}


Expand All @@ -31,37 +32,43 @@ def get_frames(function: str, sentry_frame_in_app: bool = False) -> Sequence[Map
"symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF",
"package": "SentryApp",
"filename": "LoginViewController.swift",
"image_addr": "0x102b8c000",
},
IN_APP_FRAME,
{
"function": "-[UIViewController _setViewAppearState:isAnimating:]",
"symbol": "-[UIViewController _setViewAppearState:isAnimating:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "-[UIViewController __viewDidAppear:]",
"symbol": "-[UIViewController __viewDidAppear:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "-[UIViewController _endAppearanceTransition:]",
"symbol": "-[UIViewController _endAppearanceTransition:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
"symbol": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
"symbol": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
]

Expand Down Expand Up @@ -139,16 +146,51 @@ def get_crash_event_with_frames(
"type": "os",
},
},
# Todo add referenced in stacktrace
"debug_meta": {
"images": [
{
"name": "CrashProbeiOS",
"image_vmaddr": "0x0000000100000000",
"image_addr": "0x0000000100088000",
"type": "apple",
"image_size": 65536,
"uuid": "2C656702-AA16-3E5F-94D9-D4430DA53398",
"code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/SentryApp.app/iOS-SentryApp",
"debug_id": "97862189-a5be-3af8-bcaa-7066ae872592",
"arch": "arm64",
"image_addr": "0x1025e8000",
"image_size": 170224,
"image_vmaddr": "0x187011000",
"type": "macho",
},
{
"code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/iOS-Swift.app/iOS-Swift",
"debug_id": "97862189-a5be-3af8-bcaa-7066ae872591",
"arch": "arm64",
"image_addr": "0x102b8c000",
"image_size": 180224,
"image_vmaddr": "0x100000000",
"type": "macho",
},
{
"code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/iOS-Swift.app/Frameworks/Sentry.framework/Sentry",
"debug_id": "4726c693-2359-3e9a-bd3a-559760d87486",
"arch": "arm64",
"image_addr": "0x102f68000",
"image_size": 786432,
"type": "macho",
},
{
"code_file": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"debug_id": "b0858d8e-7220-37bf-873f-ecc2b0a358c3",
"arch": "arm64e",
"image_addr": "0x19c9eb000",
"image_size": 25309184,
"image_vmaddr": "0x18907f000",
"type": "macho",
},
{
"code_file": "/System/Library/Frameworks/CFNetwork.framework/CFNetwork",
"debug_id": "b2273be9-538a-3f56-b9c7-801f39550f58",
"arch": "arm64e",
"image_addr": "0x19b98e000",
"image_size": 3977216,
"image_vmaddr": "0x188022000",
"in_app": False,
},
]
},
Expand Down

0 comments on commit f038111

Please sign in to comment.