mbrubeck / tree_magic

Determines the MIME type of a file by traversing a filetype tree.
MIT License
34 stars 9 forks source link

mime detection when file is smaller than region_len / range-length #15

Closed iyzana closed 7 months ago

iyzana commented 1 year ago

The shared-mime-info-spec does not mention it but I assume this check is incorrect https://github.com/mbrubeck/tree_magic/blob/adc1b4024cf0a44fdf9692ee721d36e5e8a03665/src/fdo_magic/check.rs#L8-L10

As an example it prevents mime-type detection of this short html file.

<!DOCTYPE HTML>
<html>
  <head>
    <title>Test</title>
  </head>
  <body></body>
</html>

The magic file contains the following rule for text/html

>0=\x00\x0E<!DOCTYPE HTML+257

setting a range-length of 257 bytes preventing detection of the 90 byte html file.

My interpretation of the spec is that the first range-length bytes should be searched for the value, but not that the file needs to be at least range-length bytes long.