Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elf: allow unaligned compression headers #236

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#![allow(clippy::identity_op)]

use crate::endian::{Endian, I32, I64, U16, U32, U64};
use crate::endian::{Endian, U32Bytes, U64Bytes, I32, I64, U16, U32, U64};
use crate::pod::Pod;

/// The header at the start of every 32-bit ELF file.
Expand Down Expand Up @@ -737,31 +737,37 @@ pub const SHF_MASKPROC: u32 = 0xf000_0000;
/// Section compression header.
///
/// Used when `SHF_COMPRESSED` is set.
///
/// Note: this type currently allows for misaligned headers, but that may be
/// changed in a future version.
#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct CompressionHeader32<E: Endian> {
/// Compression format. One of the `ELFCOMPRESS_*` values.
pub ch_type: U32<E>,
pub ch_type: U32Bytes<E>,
/// Uncompressed data size.
pub ch_size: U32<E>,
pub ch_size: U32Bytes<E>,
/// Uncompressed data alignment.
pub ch_addralign: U32<E>,
pub ch_addralign: U32Bytes<E>,
}

/// Section compression header.
///
/// Used when `SHF_COMPRESSED` is set.
///
/// Note: this type currently allows for misaligned headers, but that may be
/// changed in a future version.
#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct CompressionHeader64<E: Endian> {
/// Compression format. One of the `ELFCOMPRESS_*` values.
pub ch_type: U32<E>,
pub ch_type: U32Bytes<E>,
/// Reserved.
pub ch_reserved: U32<E>,
pub ch_reserved: U32Bytes<E>,
/// Uncompressed data size.
pub ch_size: U64<E>,
pub ch_size: U64Bytes<E>,
/// Uncompressed data alignment.
pub ch_addralign: U64<E>,
pub ch_addralign: U64Bytes<E>,
}

/// ZLIB/DEFLATE algorithm.
Expand Down