Choosing a MagicNumber or Signature for a Binary File Format

I'm defining some binary formats to encode some information and dump it to a file. I want to place a MagicNumber/Signature at the beginning of files encoded in my format to be able to tell them apart from other types of files. My question is: How do I choose a good signature? I've been thinking about picking 4 bytes that I believe aren't used already, but this solution has issues: I wouldn't know how to let the world know that the Magic Number I chose is used by my format. For instance I doubt my file format will be supported by magic any time soon. Someone else could choose the same Magic Number for a different file format without knowing that we're overlapping each other. It seems bad to let people arbitrarily pick 4 bytes. It's going to lead to the same problems we have with IPv4 addresses. More problems actually, since no authority is assigning those 4 bytes and making sure they're not duplicated. Are there better solutions?

Apr 4, 2025 - 01:42
 0
Choosing a MagicNumber or Signature for a Binary File Format

I'm defining some binary formats to encode some information and dump it to a file.

I want to place a MagicNumber/Signature at the beginning of files encoded in my format to be able to tell them apart from other types of files. My question is:

How do I choose a good signature?

I've been thinking about picking 4 bytes that I believe aren't used already, but this solution has issues:

  1. I wouldn't know how to let the world know that the Magic Number I chose is used by my format. For instance I doubt my file format will be supported by magic any time soon.

  2. Someone else could choose the same Magic Number for a different file format without knowing that we're overlapping each other.

  3. It seems bad to let people arbitrarily pick 4 bytes. It's going to lead to the same problems we have with IPv4 addresses. More problems actually, since no authority is assigning those 4 bytes and making sure they're not duplicated.

Are there better solutions?