neilharvey / FileSignatures

A small library for detecting the type of a file based on header signature (also known as magic number).
MIT License
250 stars 41 forks source link

Null file extension in object #16

Closed ventil8 closed 5 years ago

ventil8 commented 5 years ago

More of a question than an issue but If we get an object back from the inspector as bellow.

Dim inspector As New FileSignatures.FileFormatInspector() Dim format = inspector.DetermineFileFormat(aFile.InputStream)

Is it possible that format is not nothing that the format.Extension can be null or if thats null then the format object would be nothing.

My code is blowing up and wonder if the end user is uploading an unknown file type

neilharvey commented 5 years ago

A null format will be returned if no matching formats could be returned. This is intensional, I did consider making an UnknownFormat or similar, but you would just be trading one type of check for another and it raises questions about what the properties of that format would actually be.

Looking at the code, we don't check for a null/empty extension in the base FileFormat. Presumably this was in case we could determine the format of a file, but that format did not have a particular extension defined.

I've checked the built-in formats and they all have a non-null extension, so unless you've got a custom format with a null extension then it must be that whatever the user is uploading couldn't be recognised.