Re: Broken elf header incorrectly identified as missing file

Bart Schaefer <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAH+w=7a0vTk+x9ivALZdc=6ykiZdyFT2nWV4X-rZxoxtEeza0Q@mail.gmail.com>
On Thu, Apr 16, 2026 at 7:47 PM Nathan <[email protected]> wrote:
>
> 1. Create a malformed elf binary by deleting everything past part way through the file (a broken binary that triggers the bug is attached)
[...]
> 4. Observe that the file is incorrectly identified as not existing, when the actual issue is a broken elf header

Firstly, "command not found" does not mean "missing file".  If you are
actually getting a "no such file" error, it probably means the shell
is attempting to read the file as command input and is reporting that
what it thinks is a #! introduction is not followed by a reference to
any existing file, although that would be odd and I'd expect a "bad
interpreter" error or similar.

Secondly, this is an OS-specific problem (see Oliver's reply).  On MacOs:

% dd if=/bin/cat of=$HOME/bin/broken bs=1024 count=1
1+0 records in
1+0 records out
1024 bytes transferred in 0.000589 secs (1738540 bytes/sec)
% chmod +x ~/bin/broken
% broken
zsh: malformed Mach-o file: broken

Thirdly, trying the above on Ubuntu:

% dd if=/bin/cat of=$HOME/bin/broken bs=1024 count=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 4.4878e-05 s, 22.8 MB/s
% chmod +x ~/bin/broken
% broken
zsh: segmentation fault  broken

I can't get anything but a segmentation fault, I never get "not found"
or "no such file".

% file =broken
/home/schaefer/bin/broken: ELF 64-bit LSB shared object, x86-64,
version 1 (SYSV), dynamically linked, interpreter
/lib64/ld-linux-x86-64.so.2, missing section headers at 39320

Finally, if this is important to you for some reason, try adding to .zshrc:

command_not_found_handler() {
  local search=( ${^path}/$1(N) )
  [[ -n $search ]] && file $search
  return 127
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.