Catch errors and OOM when decoding ID3 frames.

Invalid frames have no impact on ExoPlayer ability to play the media and should not fail on errors.
Some tools can add 100Mb images in the tags that will trigger recoverable OOM with this fix.
This commit is contained in:
Tolriq 2023-05-01 12:32:40 +02:00 committed by Ian Baker
parent c230414bd3
commit de772cfbf0

View File

@ -372,8 +372,9 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
frameSize = removeUnsynchronization(id3Data, frameSize); frameSize = removeUnsynchronization(id3Data, frameSize);
} }
String error = "";
Id3Frame frame = null;
try { try {
Id3Frame frame;
if (frameId0 == 'T' if (frameId0 == 'T'
&& frameId1 == 'X' && frameId1 == 'X'
&& frameId2 == 'X' && frameId2 == 'X'
@ -430,18 +431,24 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
String id = getFrameId(majorVersion, frameId0, frameId1, frameId2, frameId3); String id = getFrameId(majorVersion, frameId0, frameId1, frameId2, frameId3);
frame = decodeBinaryFrame(id3Data, frameSize, id); frame = decodeBinaryFrame(id3Data, frameSize, id);
} }
if (frame == null) { } catch (Exception e) {
Log.w( error = ",error=" + e.getMessage();
TAG, } catch (OutOfMemoryError e) {
"Failed to decode frame: id=" error = ",error=" + e.getMessage();
+ getFrameId(majorVersion, frameId0, frameId1, frameId2, frameId3) }
+ ", frameSize=" finally {
+ frameSize);
}
return frame;
} finally {
id3Data.setPosition(nextFramePosition); id3Data.setPosition(nextFramePosition);
} }
if (frame == null) {
Log.w(
TAG,
"Failed to decode frame: id="
+ getFrameId(majorVersion, frameId0, frameId1, frameId2, frameId3)
+ ", frameSize="
+ frameSize
+ error);
}
return frame;
} }
@Nullable @Nullable