{"action":"opened","issue":{"url":"https://api.github.com/repos/NixOS/patchelf/issues/64","labels_url":"https://api.github.com/repos/NixOS/patchelf/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/NixOS/patchelf/issues/64/comments","events_url":"https://api.github.com/repos/NixOS/patchelf/issues/64/events","html_url":"https://github.com/NixOS/patchelf/issues/64","id":105088769,"number":64,"title":"Malformed input will cause invalid memory read / segfault","user":{"login":"hannob","id":990588,"avatar_url":"https://avatars.githubusercontent.com/u/990588?v=3","gravatar_id":"","url":"https://api.github.com/users/hannob","html_url":"https://github.com/hannob","followers_url":"https://api.github.com/users/hannob/followers","following_url":"https://api.github.com/users/hannob/following{/other_user}","gists_url":"https://api.github.com/users/hannob/gists{/gist_id}","starred_url":"https://api.github.com/users/hannob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hannob/subscriptions","organizations_url":"https://api.github.com/users/hannob/orgs","repos_url":"https://api.github.com/users/hannob/repos","events_url":"https://api.github.com/users/hannob/events{/privacy}","received_events_url":"https://api.github.com/users/hannob/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-06T11:35:45Z","updated_at":"2015-09-06T11:35:45Z","closed_at":null,"body":"This file will generate a segfault / invalid memory read with patchelf:\r\nhttps://crashes.fuzzing-project.org/patchelf-0.8-invalid-memory-read-Elf64_Phdr\r\n\r\nThe error messages I get from debugging tools aren't really clear, it seems it is causing some read to some wrong memory that is neither part of the stack or the heap.\r\n\r\nHere's the address sanitizer stack trace:\r\n```\r\n==5570==ERROR: AddressSanitizer: unknown-crash on address 0x8030afdac1201830 at pc 0x00000049ed24 bp 0x7fff61a59e10 sp 0x7fff61a595c0\r\nREAD of size 56 at 0x8030afdac1201830 thread T0\r\n    #0 0x49ed23 in __asan_memcpy (/tmp/patchelf-0.8/src/patchelf+0x49ed23)\r\n    #1 0x521b7b in __gnu_cxx::new_allocator<Elf64_Phdr>::construct(Elf64_Phdr*, Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/ext/new_allocator.h:130:28\r\n    #2 0x521b7b in void __gnu_cxx::__alloc_traits<std::allocator<Elf64_Phdr> >::construct<Elf64_Phdr>(std::allocator<Elf64_Phdr>&, Elf64_Phdr*, Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/ext/alloc_traits.h:189\r\n    #3 0x521b7b in std::vector<Elf64_Phdr, std::allocator<Elf64_Phdr> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Elf64_Phdr*, std::vector<Elf64_Phdr, std::allocator<Elf64_Phdr> > >, Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/bits/vector.tcc:361\r\n    #4 0x517d8f in std::vector<Elf64_Phdr, std::allocator<Elf64_Phdr> >::push_back(Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/bits/stl_vector.h:925:4\r\n    #5 0x517d8f in ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym>::parse() /tmp/patchelf-0.8/src/patchelf.cc:281\r\n    #6 0x4e5ab9 in void patchElf2<ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym> >(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym>&, unsigned int) /tmp/patchelf-0.8/src/patchelf.cc:1105:5\r\n    #7 0x4e5ab9 in patchElf() /tmp/patchelf-0.8/src/patchelf.cc:1156\r\n    #8 0x4e5ab9 in main /tmp/patchelf-0.8/src/patchelf.cc:1245\r\n    #9 0x7faa93de77af in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.21-r1/work/glibc-2.21/csu/libc-start.c:289\r\n    #10 0x4190f8 in _start (/tmp/patchelf-0.8/src/patchelf+0x4190f8)\r\n\r\n==5570==AddressSanitizer CHECK failed: /var/tmp/portage/sys-devel/llvm-3.7.0/work/llvm-3.7.0.src/projects/compiler-rt/lib/asan/asan_report.cc:347 \"((0 && \"Address is not in memory and not in shadow?\")) != (0)\" (0x0, 0x0)\r\n    #0 0x4bbf2d in __asan::AsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/tmp/patchelf-0.8/src/patchelf+0x4bbf2d)\r\n    #1 0x4c29c3 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/tmp/patchelf-0.8/src/patchelf+0x4c29c3)\r\n    #2 0x4b7f66 in __asan::DescribeAddressIfShadow(unsigned long, __asan::AddressDescription*, bool) (/tmp/patchelf-0.8/src/patchelf+0x4b7f66)\r\n    #3 0x4b9306 in __asan::DescribeAddress(unsigned long, unsigned long, char const*) (/tmp/patchelf-0.8/src/patchelf+0x4b9306)\r\n    #4 0x4bb0eb in __asan_report_error (/tmp/patchelf-0.8/src/patchelf+0x4bb0eb)\r\n    #5 0x49ed44 in __asan_memcpy (/tmp/patchelf-0.8/src/patchelf+0x49ed44)\r\n    #6 0x521b7b in __gnu_cxx::new_allocator<Elf64_Phdr>::construct(Elf64_Phdr*, Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/ext/new_allocator.h:130:28\r\n    #7 0x521b7b in void __gnu_cxx::__alloc_traits<std::allocator<Elf64_Phdr> >::construct<Elf64_Phdr>(std::allocator<Elf64_Phdr>&, Elf64_Phdr*, Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/ext/alloc_traits.h:189\r\n    #8 0x521b7b in std::vector<Elf64_Phdr, std::allocator<Elf64_Phdr> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Elf64_Phdr*, std::vector<Elf64_Phdr, std::allocator<Elf64_Phdr> > >, Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/bits/vector.tcc:361\r\n    #9 0x517d8f in std::vector<Elf64_Phdr, std::allocator<Elf64_Phdr> >::push_back(Elf64_Phdr const&) /usr/lib/gcc/x86_64-pc-linux-gnu/5.2.0/include/g++-v5/bits/stl_vector.h:925:4\r\n    #10 0x517d8f in ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym>::parse() /tmp/patchelf-0.8/src/patchelf.cc:281\r\n    #11 0x4e5ab9 in void patchElf2<ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym> >(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym>&, unsigned int) /tmp/patchelf-0.8/src/patchelf.cc:1105:5\r\n    #12 0x4e5ab9 in patchElf() /tmp/patchelf-0.8/src/patchelf.cc:1156\r\n    #13 0x4e5ab9 in main /tmp/patchelf-0.8/src/patchelf.cc:1245\r\n    #14 0x7faa93de77af in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.21-r1/work/glibc-2.21/csu/libc-start.c:289\r\n    #15 0x4190f8 in _start (/tmp/patchelf-0.8/src/patchelf+0x4190f8)\r\n"}}