Index: source/Plugins/Process/minidump/MinidumpTypes.cpp =================================================================== --- source/Plugins/Process/minidump/MinidumpTypes.cpp +++ source/Plugins/Process/minidump/MinidumpTypes.cpp @@ -81,11 +81,17 @@ llvm::ArrayRef MinidumpThread::ParseThreadList(llvm::ArrayRef &data) { + const auto orig_size = data.size(); + const llvm::support::ulittle32_t *thread_count; Status error = consumeObject(data, thread_count); if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size()) return {}; + // Sometimes there is padding after the count + if (4 + *thread_count * sizeof(MinidumpThread) < orig_size) + data = data.drop_front(4); + return llvm::ArrayRef( reinterpret_cast(data.data()), *thread_count); } @@ -158,8 +164,15 @@ llvm::ArrayRef MinidumpModule::ParseModuleList(llvm::ArrayRef &data) { + const auto orig_size = data.size(); + const llvm::support::ulittle32_t *modules_count; Status error = consumeObject(data, modules_count); + + // Sometimes there is padding after the count + if (4 + *modules_count * sizeof(MinidumpModule) < orig_size) + data = data.drop_front(4); + if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size()) return {}; @@ -180,8 +193,13 @@ llvm::ArrayRef MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef &data) { + const auto orig_size = data.size(); const llvm::support::ulittle32_t *mem_ranges_count; Status error = consumeObject(data, mem_ranges_count); + // Sometimes there is padding after the count + if (4 + *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) < orig_size) + data = data.drop_front(4); + if (error.Fail() || *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size()) return {}; Index: unittests/Process/minidump/MinidumpParserTest.cpp =================================================================== --- unittests/Process/minidump/MinidumpParserTest.cpp +++ unittests/Process/minidump/MinidumpParserTest.cpp @@ -84,6 +84,79 @@ EXPECT_EQ(1232UL, context.size()); } +TEST_F(MinidumpParserTest, GetThreadListNotPadded) { + // Verify that we can load a thread list that doesn't have 4 bytes of padding + // after the thread count. + SetUpData("thread-list-padded.dmp"); + llvm::ArrayRef thread_list; + + thread_list = parser->GetThreads(); + ASSERT_EQ(2UL, thread_list.size()); + EXPECT_EQ(0x11223344UL, thread_list[0].thread_id); + EXPECT_EQ(0x55667788UL, thread_list[1].thread_id); +} + +TEST_F(MinidumpParserTest, GetThreadListPadded) { + // Verify that we can load a thread list that has 4 bytes of padding + // after the thread count as found in breakpad minidump files. + SetUpData("thread-list-padded.dmp"); + auto thread_list = parser->GetThreads(); + ASSERT_EQ(2UL, thread_list.size()); + EXPECT_EQ(0x11223344UL, thread_list[0].thread_id); + EXPECT_EQ(0x55667788UL, thread_list[1].thread_id); +} + +TEST_F(MinidumpParserTest, GetModuleListNotPadded) { + // Verify that we can load a module list that doesn't have 4 bytes of padding + // after the module count. + SetUpData("module-list-not-padded.dmp"); + auto module_list = parser->GetModuleList(); + ASSERT_EQ(2UL, module_list.size()); + EXPECT_EQ(0x1000UL, module_list[0].base_of_image); + EXPECT_EQ(0x2000UL, module_list[0].size_of_image); + EXPECT_EQ(0x5000UL, module_list[1].base_of_image); + EXPECT_EQ(0x3000UL, module_list[1].size_of_image); +} + +TEST_F(MinidumpParserTest, GetModuleListPadded) { + // Verify that we can load a module list that has 4 bytes of padding + // after the module count as found in breakpad minidump files. + SetUpData("module-list-padded.dmp"); + auto module_list = parser->GetModuleList(); + ASSERT_EQ(2UL, module_list.size()); + EXPECT_EQ(0x1000UL, module_list[0].base_of_image); + EXPECT_EQ(0x2000UL, module_list[0].size_of_image); + EXPECT_EQ(0x5000UL, module_list[1].base_of_image); + EXPECT_EQ(0x3000UL, module_list[1].size_of_image); +} + +TEST_F(MinidumpParserTest, GetMemoryListNotPadded) { + // Verify that we can load a memory list that doesn't have 4 bytes of padding + // after the memory range count. + SetUpData("memory-list-not-padded.dmp"); + + if (auto mem = parser->FindMemoryRange(0x8000)) { + EXPECT_EQ((lldb::addr_t)0x8000, mem->start); + } + if (auto mem = parser->FindMemoryRange(0x8010)) { + EXPECT_EQ((lldb::addr_t)0x8010, mem->start); + } +} + +TEST_F(MinidumpParserTest, GetMemoryListPadded) { + // Verify that we can load a memory list that has 4 bytes of padding + // after the memory range count as found in breakpad minidump files. + SetUpData("memory-list-padded.dmp"); + auto mem = parser->FindMemoryRange(0x8000); + EXPECT_TRUE(mem.hasValue()); + if (mem.hasValue()) + EXPECT_EQ((lldb::addr_t)0x8000, mem->start); + mem = parser->FindMemoryRange(0x8010); + EXPECT_TRUE(mem.hasValue()); + if (mem.hasValue()) + EXPECT_EQ((lldb::addr_t)0x8010, mem->start); +} + TEST_F(MinidumpParserTest, TruncatedMinidumps) { InvalidMinidump("linux-x86_64.dmp", 32); InvalidMinidump("linux-x86_64.dmp", 100);