Well, for the most part, this is true. This method certainly isn't bulletproof, however. And last of all, data streams have no file extensions or descriptors to read at all. Read the file and attempt to recognize the format by specific patterns in the data. Most file formats contain some sort of identifying pattern of data that is identical in all files.
Nothing is easy, however.
And those that do don't necessarily put it at the beginning of the file. Of course, not all graphics formats are suitable to be read as a data stream anyway. Your best bet for a method of format detection is a combination of methods two and three. First believe the file extension or descriptor, read some data, and check for identifying data patterns. If this test fails, then attempt to recognize all other known patterns.