Skip to content

Commit 9ff5089

Browse files
authored
cifuzz: handle empty frames in get_error_frame to prevent IndexError (#15352)
This bug was caused by cifuzz action: https://github.com/Kludex/python-multipart/actions/runs/24344710532/job/71082324098 When the following pr was merged: Kludex/python-multipart#264
1 parent 432b946 commit 9ff5089

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

infra/cifuzz/sarif_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ def get_error_frame(crash_info):
163163
return None
164164
state = crash_info.crash_state.split('\n')[0]
165165
logging.info('state: %s frames %s, %s', state, crash_info.frames,
166-
[f.function_name for f in crash_info.frames[0]])
166+
[f.function_name for f in crash_info.frames[0]]
167+
if crash_info.frames else [])
167168

168169
for crash_frames in crash_info.frames:
169170
for frame in crash_frames:

infra/cifuzz/sarif_utils_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ def _get_mock_crash_info():
105105
return crash_info
106106

107107

108+
class GetErrorFrameTest(unittest.TestCase):
109+
"""Tests for get_error_frame."""
110+
111+
def test_empty_frames_does_not_raise(self):
112+
"""Tests that get_error_frame doesn't raise IndexError when frames is empty."""
113+
crash_info = mock.MagicMock()
114+
crash_info.frames = []
115+
crash_info.crash_state = 'some_func\nsome_func1'
116+
self.assertIsNone(sarif_utils.get_error_frame(crash_info))
117+
118+
108119
class GetErrorSourceInfoTest(unittest.TestCase):
109120
"""Tests for get_error_source_info."""
110121

0 commit comments

Comments
 (0)