mirror of
https://github.com/samsonjs/media.git
synced 2026-03-29 10:05:48 +00:00
Catch unchecked exception in RtspSessionTiming parsing.
Issue: google/ExoPlayer#10165 #minor-release PiperOrigin-RevId: 443653894
This commit is contained in:
parent
6443d5b840
commit
85bd080a17
3 changed files with 25 additions and 9 deletions
|
|
@ -457,6 +457,21 @@ import java.util.regex.Pattern;
|
|||
"Invalid WWW-Authenticate header " + headerValue, /* cause= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@link ParserException#createForMalformedManifest ParserException} if {@code expression}
|
||||
* evaluates to false.
|
||||
*
|
||||
* @param expression The expression to evaluate.
|
||||
* @param message The error message.
|
||||
* @throws ParserException If {@code expression} is false.
|
||||
*/
|
||||
public static void checkManifestExpression(boolean expression, @Nullable String message)
|
||||
throws ParserException {
|
||||
if (!expression) {
|
||||
throw ParserException.createForMalformedManifest(message, /* cause= */ null);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getRtspStatusReasonPhrase(int statusCode) {
|
||||
switch (statusCode) {
|
||||
case 200:
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.rtsp;
|
||||
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||
import static com.google.android.exoplayer2.source.rtsp.RtspMessageUtil.checkManifestExpression;
|
||||
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
|
|
@ -48,10 +48,11 @@ import java.util.regex.Pattern;
|
|||
long startTimeMs;
|
||||
long stopTimeMs;
|
||||
Matcher matcher = NPT_RANGE_PATTERN.matcher(sdpRangeAttribute);
|
||||
checkArgument(matcher.matches());
|
||||
checkManifestExpression(matcher.matches(), /* message= */ sdpRangeAttribute);
|
||||
|
||||
String startTimeString = checkNotNull(matcher.group(1));
|
||||
if (startTimeString.equals("now")) {
|
||||
@Nullable String startTimeString = matcher.group(1);
|
||||
checkManifestExpression(startTimeString != null, /* message= */ sdpRangeAttribute);
|
||||
if (castNonNull(startTimeString).equals("now")) {
|
||||
startTimeMs = LIVE_START_TIME;
|
||||
} else {
|
||||
startTimeMs = (long) (Float.parseFloat(startTimeString) * C.MILLIS_PER_SECOND);
|
||||
|
|
@ -64,7 +65,7 @@ import java.util.regex.Pattern;
|
|||
} catch (NumberFormatException e) {
|
||||
throw ParserException.createForMalformedManifest(stopTimeString, e);
|
||||
}
|
||||
checkArgument(stopTimeMs > startTimeMs);
|
||||
checkManifestExpression(stopTimeMs >= startTimeMs, /* message= */ sdpRangeAttribute);
|
||||
} else {
|
||||
stopTimeMs = C.TIME_UNSET;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import static org.junit.Assert.assertThrows;
|
|||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
|
@ -62,8 +63,7 @@ public class RtspSessionTimingTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void parseTiming_withInvalidRangeTiming_throwsIllegalArgumentException() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> RtspSessionTiming.parseTiming("npt=10.000-2.054"));
|
||||
public void parseTiming_withInvalidRangeTiming_throwsParserException() {
|
||||
assertThrows(ParserException.class, () -> RtspSessionTiming.parseTiming("npt=10.000-2.054"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue