diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index faa912ba..7052a7c1 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -3022,6 +3022,9 @@ void PackLinuxElf64::unpack(OutputFile *fo) fi->readx(&bhdr, szb_info); ph.u_len = get_te32(&bhdr.sz_unc); ph.c_len = get_te32(&bhdr.sz_cpr); + if (ph.c_len > fi->st_size()) + throwCantUnpack("file header corrupted"); + ph.filter_cto = bhdr.b_cto8; // Uncompress Ehdr and Phdrs. @@ -3538,6 +3541,8 @@ void PackLinuxElf32::unpack(OutputFile *fo) fi->readx(&bhdr, szb_info); ph.u_len = get_te32(&bhdr.sz_unc); ph.c_len = get_te32(&bhdr.sz_cpr); + if (ph.c_len > fi->st_size()) + throwCantUnpack("file header corrupted"); ph.filter_cto = bhdr.b_cto8; bool const is_shlib = (ehdr->e_entry==0) || (ehdr->e_shoff!=0);