Some files like PNG and GIF have a magic number in the file header. It is used to "identify the file" as a specific type like PNG. You just check the magic number and that tells you the type. But I don't understand why you would need this because it can be spoofed so easily and nobody is ever going to look at the file and read it I would suppose. It seems if you just assumed it was a specific mime-type and then it either worked or it didn't work, that would be just as effective.

  • 5
    I suppose it is the same as labeling it .pdf or .mp4 , it automates recognition by the os, it is a convenience convention not necessarily a security feature
    – Panther
    Nov 22, 2018 at 16:44

1 Answer 1


Files in linux don't always have a .exe or .png extention at the end of them, like windows requires? So to mitigate that, the magic number is used to help id the file type and open it properly. This is originaly a unix thing that found it's way into linux because it's useful and habit, on the side of the coders.

  • 2
    Also, a library can immediately reject a file that has the wrong signature instead of failing at a later stage when the data does not conform to the expected specification. This is regardless of operating system. Almost any type of data specification specifies a way of identifying the data by means of some sort of signature.
    – Kusalananda
    Nov 22, 2018 at 17:22
  • Absolutly right! @Kusalananda Nov 22, 2018 at 17:30

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