From f8c6f494f7f6a7b5af6eb9138198b437e1845c50 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 8 Apr 2020 11:57:04 +0200 Subject: [PATCH] [CFI] Skip zeros when entry length is zero Only skip null bytes when format is Dwarf32 Remove skip_null --- src/read/cfi.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/read/cfi.rs b/src/read/cfi.rs index 7b50f66b2..b3d0f76fd 100644 --- a/src/read/cfi.rs +++ b/src/read/cfi.rs @@ -1016,12 +1016,23 @@ where R: Reader, Section: UnwindSection, { - let offset = input.offset_from(section.section()); - let (length, format) = input.read_initial_length()?; + let (offset, length, format) = loop { + let offset = input.offset_from(section.section()); + let (length, format) = input.read_initial_length()?; - if Section::length_value_is_end_of_entries(length) { - return Ok(None); - } + if Section::length_value_is_end_of_entries(length) { + return Ok(None); + } + + // Hack: skip zero padding inserted by buggy compilers/linkers. + // We require that the padding is a multiple of 32-bits, otherwise + // there is no reliable way to determine when the padding ends. This + // should be okay since CFI entries must be aligned to the address size. + + if length.into_u64() != 0 || format != Format::Dwarf32 { + break (offset, length, format); + } + }; let mut rest = input.split(length)?; let cie_offset_base = rest.offset_from(section.section());