From 77d220c5076e7e61af8fbbd5c6974795c09208e5 Mon Sep 17 00:00:00 2001 From: Copybara-Service Date: Thu, 4 Jan 2024 03:02:29 -0800 Subject: [PATCH] Merge pull request #369 from Tolriq:fix_invalid_frames PiperOrigin-RevId: 595650068 (cherry picked from commit 8eda9f2ed2cc8d00fbd0bb71090a7a77cc10629b) --- RELEASENOTES.md | 3 +++ .../extractor/metadata/id3/Id3Decoder.java | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 763925e48c..2e115013b9 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -42,6 +42,9 @@ * Fix bug where `MediaMetadata` was only populated from Vorbis comments with upper-case keys ([#876](https://github.com/androidx/media/issues/876)). + * Catch `OutOfMemoryError` when parsing very large ID3 frames, meaning + playback can continue without the tag info instead of playback failing + completely. * DRM: * Extend workaround for spurious ClearKey `https://default.url` license URL to API 33+ (previously the workaround only applied on API 33 diff --git a/libraries/extractor/src/main/java/androidx/media3/extractor/metadata/id3/Id3Decoder.java b/libraries/extractor/src/main/java/androidx/media3/extractor/metadata/id3/Id3Decoder.java index 3358fe0daf..3b32805bea 100644 --- a/libraries/extractor/src/main/java/androidx/media3/extractor/metadata/id3/Id3Decoder.java +++ b/libraries/extractor/src/main/java/androidx/media3/extractor/metadata/id3/Id3Decoder.java @@ -371,8 +371,9 @@ public final class Id3Decoder extends SimpleMetadataDecoder { frameSize = removeUnsynchronization(id3Data, frameSize); } + Id3Frame frame = null; + Throwable error = null; try { - Id3Frame frame; if (frameId0 == 'T' && frameId1 == 'X' && frameId2 == 'X' @@ -429,18 +430,21 @@ public final class Id3Decoder extends SimpleMetadataDecoder { String id = getFrameId(majorVersion, frameId0, frameId1, frameId2, frameId3); frame = decodeBinaryFrame(id3Data, frameSize, id); } - if (frame == null) { - Log.w( - TAG, - "Failed to decode frame: id=" - + getFrameId(majorVersion, frameId0, frameId1, frameId2, frameId3) - + ", frameSize=" - + frameSize); - } - return frame; + } catch (OutOfMemoryError | Exception e) { + error = e; } finally { 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