From 462453cfb6267661fcefb2a6bd5d72425d8ba05a Mon Sep 17 00:00:00 2001 From: Steven Casper Date: Mon, 14 Oct 2024 22:56:12 -0400 Subject: [PATCH 1/4] Fix data tooltip panic Prevents panicing when attempting to display the data tooltip for a symbol that is too large by just using as many bytes as needed from the begging of the symbol. --- objdiff-core/src/arch/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 71113411..0879fb20 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -34,9 +34,12 @@ pub enum DataType { impl DataType { pub fn display_bytes(&self, bytes: &[u8]) -> Option { - if self.required_len().is_some_and(|l| bytes.len() < l) { + let Some(required_len) = self.required_len() else { return None; - } + }; + // TODO: For symbols larger than their data type, we should probably support + // using the relocation's relative offset to read the bytes. + let bytes = bytes.get(0..required_len)?; match self { DataType::Int8 => { From d6769729b80ea0f4e4570fa452df81753ede4afd Mon Sep 17 00:00:00 2001 From: Steven Casper Date: Mon, 14 Oct 2024 23:45:47 -0400 Subject: [PATCH 2/4] Don't attempt to interpret wrongly sized data --- objdiff-core/src/arch/mod.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 0879fb20..765433a2 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -34,12 +34,9 @@ pub enum DataType { impl DataType { pub fn display_bytes(&self, bytes: &[u8]) -> Option { - let Some(required_len) = self.required_len() else { + if self.required_len().is_some_and(|l| bytes.len() != l) { return None; - }; - // TODO: For symbols larger than their data type, we should probably support - // using the relocation's relative offset to read the bytes. - let bytes = bytes.get(0..required_len)?; + } match self { DataType::Int8 => { From 742f83d30a3f2901d7381877f3dc604596a7c6d5 Mon Sep 17 00:00:00 2001 From: Steven Casper Date: Mon, 14 Oct 2024 23:50:11 -0400 Subject: [PATCH 3/4] Reference data display improvment issue --- objdiff-core/src/arch/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 765433a2..4026817c 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -34,6 +34,9 @@ pub enum DataType { impl DataType { pub fn display_bytes(&self, bytes: &[u8]) -> Option { + // TODO: Attempt to interpret large symbols as arrays of a smaller type, + // fallback to intrepreting it as bytes. + // https://github.com/encounter/objdiff/issues/124 if self.required_len().is_some_and(|l| bytes.len() != l) { return None; } From 581fcf4e6929bc64b867d4dda2bc0464a9c20a84 Mon Sep 17 00:00:00 2001 From: Steven Casper Date: Mon, 14 Oct 2024 23:55:34 -0400 Subject: [PATCH 4/4] Log failure to display a symbol's value --- objdiff-core/src/arch/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 4026817c..494aff69 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -38,6 +38,7 @@ impl DataType { // fallback to intrepreting it as bytes. // https://github.com/encounter/objdiff/issues/124 if self.required_len().is_some_and(|l| bytes.len() != l) { + log::warn!("Failed to display a symbol value for a symbol whose size doesn't match the instruction referencing it."); return None; }