@@ -135,7 +135,7 @@ static constexpr u8 omit_sign_bit_mask_low(u8 value) {
135135
136136void DwarfParser::parse (const char *eh_frame_hdr, size_t size, const char *image_end) {
137137 // Fixed .eh_frame_hdr header: version (1) + 3 encoding bytes + eh_frame_ptr (4)
138- // + fde_count at offset 8 (4), binary-search table starting at offset 16 .
138+ // + fde_count at offset 8 (4), binary-search table starting at offset 12 .
139139 // Refuse anything too small.
140140 if (eh_frame_hdr == NULL || size < 16 ) {
141141 return ;
@@ -168,19 +168,20 @@ void DwarfParser::parse(const char *eh_frame_hdr, size_t size, const char *image
168168 }
169169
170170 u32 fde_count = *(u32 *)(eh_frame_hdr + 8 );
171- u32 *table = ( u32 *)(eh_frame_hdr + 16 );
171+ // Table starts at offset 12 (4-byte header + 4-byte eh_frame_ptr + 4-byte fde_count).
172172 // Each entry is a (initial_loc, fde_ptr) pair of 4-byte section-relative
173173 // offsets (DW_EH_PE_datarel | DW_EH_PE_udata4). Reject a count that would
174174 // make the table walk read past the section.
175- if (fde_count > (size - 16 ) / 8 ) {
175+ u32 *table = (u32 *)(eh_frame_hdr + 12 );
176+ if (fde_count > (size - 12 ) / 8 ) {
176177 Log::warn (" Truncated or invalid .eh_frame_hdr (fde_count=%u, size=%lu) in %s" ,
177178 fde_count, (unsigned long )size, _name);
178179 return ;
179180 }
180181 for (u32 i = 0 ; i < fde_count; i++) {
181- // table[i*2+1] is the FDE pointer (datarel sdata4); table[i*2] is initial_loc .
182- // Cast to int32_t to correctly handle negative offsets (FDE before the header).
183- _ptr = eh_frame_hdr + (int32_t )table[i * 2 + 1 ];
182+ // table[i*2] is initial_loc; table[i*2 +1] is the FDE pointer (datarel sdata4).
183+ // Cast to int to correctly handle negative offsets (FDE before the header).
184+ _ptr = eh_frame_hdr + (int )table[i * 2 + 1 ];
184185 parseFde ();
185186 }
186187}
0 commit comments