From 8d964c6fb66075b8892034add730e1092c493e2c Mon Sep 17 00:00:00 2001 From: "Warren R. Bank" Date: Thu, 26 Dec 2024 13:16:57 -0800 Subject: [PATCH 1/2] restrict milliseconds field in VTT time codes to 3 digits --- .../media3/extractor/text/webvtt/WebvttParserUtil.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/extractor/src/main/java/androidx/media3/extractor/text/webvtt/WebvttParserUtil.java b/libraries/extractor/src/main/java/androidx/media3/extractor/text/webvtt/WebvttParserUtil.java index 1ba28b7fd73..044f29d7c70 100644 --- a/libraries/extractor/src/main/java/androidx/media3/extractor/text/webvtt/WebvttParserUtil.java +++ b/libraries/extractor/src/main/java/androidx/media3/extractor/text/webvtt/WebvttParserUtil.java @@ -73,6 +73,12 @@ public static long parseTimestampUs(String timestamp) throws NumberFormatExcepti } value *= 1000; if (parts.length == 2) { + if (parts[1].length() > 3) { + try { + parts[1] = parts[1].substring(0, 3); + } + catch(IndexOutOfBoundsException e) {} + } value += Long.parseLong(parts[1]); } return value * 1000; From 57ebbcdc9ed66765890c02426ed3ed4d06c4cb83 Mon Sep 17 00:00:00 2001 From: "Warren R. Bank" Date: Thu, 26 Dec 2024 13:20:04 -0800 Subject: [PATCH 2/2] restrict milliseconds field in SRT time codes to 3 digits --- .../androidx/media3/extractor/text/subrip/SubripParser.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/extractor/src/main/java/androidx/media3/extractor/text/subrip/SubripParser.java b/libraries/extractor/src/main/java/androidx/media3/extractor/text/subrip/SubripParser.java index da98660d3c7..d7d114e6918 100644 --- a/libraries/extractor/src/main/java/androidx/media3/extractor/text/subrip/SubripParser.java +++ b/libraries/extractor/src/main/java/androidx/media3/extractor/text/subrip/SubripParser.java @@ -287,6 +287,12 @@ private static long parseTimecode(Matcher matcher, int groupOffset) { timestampMs += Long.parseLong(Assertions.checkNotNull(matcher.group(groupOffset + 3))) * 1000; @Nullable String millis = matcher.group(groupOffset + 4); if (millis != null) { + if (millis.length() > 3) { + try { + millis = millis.substring(0, 3); + } + catch(IndexOutOfBoundsException e) {} + } timestampMs += Long.parseLong(millis); } return timestampMs * 1000;