1

From https://linux.die.net/man/1/file:

The magic tests are used to check for files with data in particular fixed formats. The canonical example of this is a binary executable (compiled program) a.out file, whose format is defined in #include <a.out.h> and possibly #include <exec.h> in the standard include directory. These files have a 'magic number' stored in a particular place near the beginning of the file that tells the UNIX operating system that the file is a binary executable, and which of several types thereof. The concept of a 'magic' has been applied by extension to data files. Any file with some invariant identifier at a small fixed offset into the file can usually be described in this way. The information identifying these files is read from the compiled magic file /usr/share/misc/magic.mgc, or the files in the directory /usr/share/misc/magic if the compiled file does not exist. In addition, if $HOME/.magic.mgc or $HOME/.magic exists, it will be used in preference to the system magic files. If /etc/magic exists, it will be used together with other magic files.

Fair enough. So if, by coincidence, a text file happens to contain a 'magic number' specific to, for example, an mp4 video at an appropriate offset… Will double-clicking such a text file result in a video player being launched instead of a text editor?

  • You might find polyglot files interesting (look up PoC||GTFO). – Stephen Kitt Apr 21 '17 at 21:33
2

It depends - your desktop may index files by looking at their MIME-type using file. Or it may simply look at the file-suffix and believe that (see for example A Quick Reference to File Extensions and MIME Types ).

In any case, the video player will make its own checks, to ensure that the file loads correctly, and only a naive implementation will just look at the first few bytes.

The file program uses a mixture of information (including weights for the measures it takes). An mpeg4 file has a lot of information which file may not use (or need). See for example MPEG-4 Part 14 Audio (M4A,M4B,M4P) Format & Recovery Example, and MP4 Signature Format: Documentation & Recovery Example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.