mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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);
|
"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) {
|
private static String getRtspStatusReasonPhrase(int statusCode) {
|
||||||
switch (statusCode) {
|
switch (statusCode) {
|
||||||
case 200:
|
case 200:
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.rtsp;
|
package com.google.android.exoplayer2.source.rtsp;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
import static com.google.android.exoplayer2.source.rtsp.RtspMessageUtil.checkManifestExpression;
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
|
@ -48,10 +48,11 @@ import java.util.regex.Pattern;
|
||||||
long startTimeMs;
|
long startTimeMs;
|
||||||
long stopTimeMs;
|
long stopTimeMs;
|
||||||
Matcher matcher = NPT_RANGE_PATTERN.matcher(sdpRangeAttribute);
|
Matcher matcher = NPT_RANGE_PATTERN.matcher(sdpRangeAttribute);
|
||||||
checkArgument(matcher.matches());
|
checkManifestExpression(matcher.matches(), /* message= */ sdpRangeAttribute);
|
||||||
|
|
||||||
String startTimeString = checkNotNull(matcher.group(1));
|
@Nullable String startTimeString = matcher.group(1);
|
||||||
if (startTimeString.equals("now")) {
|
checkManifestExpression(startTimeString != null, /* message= */ sdpRangeAttribute);
|
||||||
|
if (castNonNull(startTimeString).equals("now")) {
|
||||||
startTimeMs = LIVE_START_TIME;
|
startTimeMs = LIVE_START_TIME;
|
||||||
} else {
|
} else {
|
||||||
startTimeMs = (long) (Float.parseFloat(startTimeString) * C.MILLIS_PER_SECOND);
|
startTimeMs = (long) (Float.parseFloat(startTimeString) * C.MILLIS_PER_SECOND);
|
||||||
|
|
@ -64,7 +65,7 @@ import java.util.regex.Pattern;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw ParserException.createForMalformedManifest(stopTimeString, e);
|
throw ParserException.createForMalformedManifest(stopTimeString, e);
|
||||||
}
|
}
|
||||||
checkArgument(stopTimeMs > startTimeMs);
|
checkManifestExpression(stopTimeMs >= startTimeMs, /* message= */ sdpRangeAttribute);
|
||||||
} else {
|
} else {
|
||||||
stopTimeMs = C.TIME_UNSET;
|
stopTimeMs = C.TIME_UNSET;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.ParserException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
|
@ -62,8 +63,7 @@ public class RtspSessionTimingTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTiming_withInvalidRangeTiming_throwsIllegalArgumentException() {
|
public void parseTiming_withInvalidRangeTiming_throwsParserException() {
|
||||||
assertThrows(
|
assertThrows(ParserException.class, () -> RtspSessionTiming.parseTiming("npt=10.000-2.054"));
|
||||||
IllegalArgumentException.class, () -> RtspSessionTiming.parseTiming("npt=10.000-2.054"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue