Skip to content

Commit 2d96931

Browse files
committed
Handle certain types of capture file corruption
Signed-off-by: Matt Wozniski <[email protected]>
1 parent 858f1c9 commit 2d96931

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/memray/_memray/record_reader.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ RecordReader::processFramePush(const FramePush& record)
177177
if (!d_track_stacks) {
178178
return true;
179179
}
180+
if (!d_curr_thread_stack) {
181+
throw std::runtime_error("invalid capture file: FRAME_PUSH with no previous CONTEXT_SWITCH");
182+
}
180183
auto& stack = *d_curr_thread_stack;
181184
FrameTree::index_t current_stack_id = stack.empty() ? 0 : stack.back();
182185
FrameTree::index_t new_stack_id;
@@ -202,6 +205,9 @@ RecordReader::processFramePop(const FramePop& record)
202205
if (!d_track_stacks) {
203206
return true;
204207
}
208+
if (!d_curr_thread_stack) {
209+
throw std::runtime_error("invalid capture file: FRAME_POP with no previous CONTEXT_SWITCH");
210+
}
205211

206212
auto& stack = *d_curr_thread_stack;
207213
assert(!stack.empty());
@@ -311,6 +317,9 @@ RecordReader::parseAllocationRecord(AllocationRecord* record, unsigned int flags
311317
bool
312318
RecordReader::processAllocationRecord(const AllocationRecord& record)
313319
{
320+
if (!d_curr_thread_stack) {
321+
throw std::runtime_error("invalid capture file: ALLOCATION with no previous CONTEXT_SWITCH");
322+
}
314323
d_latest_allocation.tid = d_last.thread_id;
315324
d_latest_allocation.address = record.address;
316325
d_latest_allocation.size = record.size;

0 commit comments

Comments
 (0)