NPE when reading a file with MP4 boxes of field type "genre"
I have an example file, created by iTunes, which won't open in JAT:
java.lang.NullPointerException
at org.jaudiotagger.tag.mp4.field.Mp4GenreField.build(Mp4GenreField.java:111)
at org.jaudiotagger.tag.mp4.Mp4TagField.<init>(Mp4TagField.java:87)
at org.jaudiotagger.tag.mp4.field.Mp4TagTextField.<init>(Mp4TagTextField.java:67)
at org.jaudiotagger.tag.mp4.field.Mp4TagTextNumberField.<init>(Mp4TagTextNumberField.java:57)
at org.jaudiotagger.tag.mp4.field.Mp4GenreField.<init>(Mp4GenreField.java:22)
at org.jaudiotagger.audio.mp4.Mp4TagReader.createMp4Field(Mp4TagReader.java:234)
at org.jaudiotagger.audio.mp4.Mp4TagReader.read(Mp4TagReader.java:164)
at org.jaudiotagger.audio.mp4.Mp4FileReader.getTag(Mp4FileReader.java:46)
at org.jaudiotagger.audio.generic.AudioFileReader.read(AudioFileReader.java:111)
at org.jaudiotagger.audio.AudioFileIO.readFile(AudioFileIO.java:359)
at org.jaudiotagger.audio.AudioFileIO.read(AudioFileIO.java:196)
The cause seems to be the field type of one of the MP4 boxes. The box has the id gnre
, as normal.
Mp4DataBox
is used to read the contents of the box. In the Mp4DataBox
constructor, the type for the box is read as being == 0x12, for which there's no if clause, and so the contents are not read and numbers
is unset.
This means the NPE above ensues when we try to access it in Mp4GenreField
.
Here's how exiftool reports this file:
$ exiftool -Genre 01\ -\ Prelude\ from\ Te\ Deum.m4a
Genre : (Binary data 2 bytes, use -b option to extract)
If I use -b (and hexdump to dump the hex):
$ exiftool -b -Genre 01\ -\ Prelude\ from\ Te\ Deum.m4a | hexdump
0000000 2100
0000002
So that's two bytes, 21 in hex, meaning 33 which I think means 32 (classical) if you 1-base the genre list.
So assuming it's just a list of two byte integers (shorts in Java) I hacked a quick solution in Mp4DataBox:73:
else if (type == Mp4FieldType.IMPLICIT.getFileClassId() || type == Mp4FieldType.GENRES.getFileClassId())
This allows the file to be read. However I'm not comfortable with suggesting this solution without understanding what the genres field type should really contain...
Thoughts anyone?
Comments (6)
-
-
repo owner I think thats okay, lets go with that
-
Ok, I'll prepare a PR in the coming weeks.
-
-
repo owner - changed status to resolved
Fixed, thanks Dan
-
Cheers.
- Log in to comment
Oops, that was me btw!