From 199ab0a73c87c4592db8dfa66fdfc87a672e5876 Mon Sep 17 00:00:00 2001 From: eupn Date: Mon, 27 Mar 2023 16:29:07 +0400 Subject: [PATCH] elf: fix a section alignment edge case --- tools/src/elf.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/src/elf.rs b/tools/src/elf.rs index 05e16381b..36e2d92bf 100644 --- a/tools/src/elf.rs +++ b/tools/src/elf.rs @@ -372,8 +372,12 @@ pub fn process_minielf(b: &[u8]) -> Result { if s.get_type() != Ok(ShType::NoBits) { let section_data = s.raw_data(&elf); let pad_amount = if let Some(next_section) = section_iter.peek() { - if section_data.len() % next_section.align() as usize != 0 { - next_section.align() as usize - (section_data.len() % next_section.align() as usize) + if next_section.get_type() != Ok(ShType::NoBits) { + if section_data.len() % next_section.align() as usize != 0 { + next_section.align() as usize - (section_data.len() % next_section.align() as usize) + } else { + 0 + } } else { 0 }