Skip to content

Commit 9b64e30

Browse files
committed
fix: throw when thread index is out of bounds in mergeProfilesForDiffing
1 parent fae652e commit 9b64e30

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/profile-logic/merge-compare.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export function mergeProfilesForDiffing(
169169
);
170170
}
171171
const profile = profiles[i];
172+
if (selectedThreadIndex >= profile.threads.length) {
173+
throw new Error(
174+
`Thread index ${selectedThreadIndex} is out of bounds for profile ${i} (${profile.threads.length} threads).`
175+
);
176+
}
172177
let thread = { ...profile.threads[selectedThreadIndex] };
173178

174179
transformStacks[i] = translateTransformStack(

src/test/store/receive-profile.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,23 @@ describe('actions/receive-profile', function () {
19861986
'show [thread Diff between 1 and 2 comparison]',
19871987
]);
19881988
});
1989+
1990+
it('gives a fatal error when the selected thread index is out of bounds', async function () {
1991+
const { dispatch, getState } = blankStore();
1992+
const { profile1, profile2 } = getSomeProfiles();
1993+
window.fetchMock.getOnce('*', profile1).getOnce('*', profile2);
1994+
1995+
await dispatch(
1996+
retrieveProfilesToCompare([
1997+
'https://fakeurl.com/public/fakehash1/?thread=5&v=3',
1998+
'https://fakeurl.com/public/fakehash2/?thread=0&v=3',
1999+
])
2000+
);
2001+
2002+
const view = getView(getState());
2003+
expect(view.phase).toBe('FATAL_ERROR');
2004+
expect((view as any).error.message).toMatch(/out of bounds/);
2005+
});
19892006
});
19902007

19912008
describe('retrieveProfileForRawUrl', function () {

0 commit comments

Comments
 (0)