From 62b7a22b6cd11e2a1dd020746d29c620310458c3 Mon Sep 17 00:00:00 2001 From: Aetias Date: Sat, 19 Oct 2024 15:22:28 +0200 Subject: [PATCH 1/2] Fix panic when parsing DWARF 2 line info for empty section --- objdiff-core/src/obj/read.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/objdiff-core/src/obj/read.rs b/objdiff-core/src/obj/read.rs index 2cd7f23e..6b01d042 100644 --- a/objdiff-core/src/obj/read.rs +++ b/objdiff-core/src/obj/read.rs @@ -444,13 +444,9 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection], obj_data: &[u8]) // The next row is the start of a new sequence, which means we must // advance to the next .text section. let section_index = text_sections.next().map(|s| s.index().0); - lines = section_index.map(|index| { - &mut sections - .iter_mut() - .find(|s| s.orig_index == index) - .unwrap() - .line_info - }); + lines = section_index + .and_then(|index| sections.iter_mut().find(|s| s.orig_index == index)) + .map(|s| &mut s.line_info); } } } From f74bb8bbc12a17c36b58160658fda62412e97620 Mon Sep 17 00:00:00 2001 From: Aetias Date: Sat, 19 Oct 2024 15:32:52 +0200 Subject: [PATCH 2/2] Fix panic when parsing DWARF 2 line info for empty section May as well remove both unwraps :p --- objdiff-core/src/obj/read.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/objdiff-core/src/obj/read.rs b/objdiff-core/src/obj/read.rs index 6b01d042..dad64271 100644 --- a/objdiff-core/src/obj/read.rs +++ b/objdiff-core/src/obj/read.rs @@ -431,9 +431,9 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection], obj_data: &[u8]) let mut text_sections = obj_file.sections().filter(|s| s.kind() == SectionKind::Text); let section_index = text_sections.next().map(|s| s.index().0); - let mut lines = section_index.map(|index| { - &mut sections.iter_mut().find(|s| s.orig_index == index).unwrap().line_info - }); + let mut lines = section_index + .and_then(|index| sections.iter_mut().find(|s| s.orig_index == index)) + .map(|s| &mut s.line_info); let mut rows = program.rows(); while let Some((_header, row)) = rows.next_row()? {