neilharvey / FileSignatures

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

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' #8

Closed xantari closed 6 years ago

xantari commented 6 years ago

When calling: var format = inspector.DetermineFileFormat(ms);

With a MemoryStream that is empty will cause the following error:

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'

Looks like it is missing bounds checking...

neilharvey commented 6 years ago

I've changed this in https://github.com/neilharvey/FileSignatures/commit/ff0cf2660cba3cb677c0ebfe918798a9ca8b077e so that it will return a null value when the passed stream is empty (which is the same behaviour as an unrecognised file format).

neilharvey commented 6 years ago

This is fixed in v2.0, which will be available on Nuget shortly.