[File] Unable to load some mp3 files with id3v2 header
Yasir Assam
mail at endlessvoid.com
Thu Oct 29 01:34:58 UTC 2020
Some mp3 files have an id3v2 header, and in some cases _file_ is unable
to detect the mp3 part of the file that follows the id3v2 header.
The reason is that it's valid for id3v2 to take up more file space than
the size indicated in the header. From the id3v2 spec, section 3.3:
3.3. Padding
It is OPTIONAL to include padding after the final frame (at the end
of the ID3 tag), making the size of all the frames together smaller
than the size given in the tag header. A possible purpose of this
padding is to allow for adding a few additional frames or enlarge
existing frames within the tag without having to rewrite the entire
file. The value of the padding bytes must be $00. [1]
[1] - https://id3.org/id3v2.4.0-structure
I only have a superficial understanding of the magic format, but I think
the relevant line is in the file 'audio':
https://github.com/file/file/blob/3810fb8881131bae5b4c4c2acb0b5464b35ff1ea/magic/Magdir/audio#L308
The line is as follows:
>(6.I+10) indirect x \b, contains:
If I've understood this correctly, this will read the size of the ID3v2
structure at byte 6 (which doesn't include the 10 byte prefix), and then
jump to that location to read whatever comes next.
The problem is that for some files, this location isn't actually where
the mp3 data starts, because that files has extra null bytes before the
mp3 data actually starts.
Is there any way to get _file_ to skip past an unknown number of null
bytes and try to detect the start of the mp3 data?
Thanks,
Yasir
More information about the File
mailing list