Skip to main content

elf_program_headers_readable

Function elf_program_headers_readable 

Source
pub open spec fn elf_program_headers_readable(elf: &ElfFile<'_>) -> bool
Expand description
{
    let (offset, entry_size, count) = match elf.header.pt2 {
        HeaderPt2::Header32(h) => (h.ph_offset as u64, h.ph_entry_size, h.ph_count),
        HeaderPt2::Header64(h) => (h.ph_offset, h.ph_entry_size, h.ph_count),
    };
    if count == 0 || offset == 0 || entry_size == 0 {
        true
    } else {
        let (size, align): (int, int) = match elf.header.pt1.class() {
            Class::ThirtyTwo => (32, 4),
            Class::SixtyFour => (56, 8),
            _ => (0, 0),
        };
        let start = if offset <= usize::MAX {
            offset as int
        } else {
            (offset as int) % (usize::MAX + 1)
        };
        let end = start + count * entry_size;
        &&& align > 0
        &&& end <= usize::MAX
        &&& end <= elf.input@.len()
        &&& entry_size >= size
        &&& (as_ptr_spec(elf.input).addr() + start) % align == 0
        &&& (count == 1 || (entry_size as int) % align == 0)

    }
}

Empty tables or zero offsets/strides stop iteration without reading an entry. Otherwise every entry must fit in the input, hold the class-specific header, and be aligned. The end bound also excludes arithmetic overflow in any build profile. Program-header class comes from pt1, even for a manually built ElfFile.