sendyhalim / Swime

🗂 Swift MIME type checking based on magic bytes
MIT License
181 stars 38 forks source link

Fix MP4 byte signature check #19

Closed gdavis closed 3 years ago

gdavis commented 3 years ago

When testing for mp4 video file types, I encountered a range issue when checking byte ranges. The code was comparing an array of bytes that have mismatched lengths, therefore the check for a valid mp4 file would always fail since the range checked had a length of 12, and the expected byte values had a range of 16 (with 4 empty bytes at the end of the range).

I have fixed this by removing the check for the last 4 empty bytes, so the range count now matches and will successfully find a valid mp4 file. Attached is the mp4 file I was testing against.

Commit details:

fix mismatched range of bytes check

  • the signature check for mp4 bytes included 16 values, but was only comparing against 12 values, so the check would always fail.
  • removed the check for the empty bytes at the end of the range

https://user-images.githubusercontent.com/110691/134053079-26397b8b-d023-45b8-965d-f1eb2207c3ed.mp4

sendyhalim commented 3 years ago

Sry for late response, thank you @gdavis !