From e1a071b33bbea4e6d2832d7fd0313783fedb9f36 Mon Sep 17 00:00:00 2001 From: claincly Date: Fri, 4 Jun 2021 18:50:11 +0100 Subject: [PATCH] Propagate duplicated keys error in SDP better. The current code does not catch the IAE thrown when building a MediaDescription or SessionDescription. This CL catches the IAE and propagates it as a ParserException. Issue: #9014. PiperOrigin-RevId: 377544439 --- .../source/rtsp/SessionDescriptionParser.java | 4 +-- .../source/rtsp/SessionDescriptionTest.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionParser.java b/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionParser.java index b38c72d8ca..cb47251b71 100644 --- a/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionParser.java +++ b/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionParser.java @@ -186,7 +186,7 @@ import java.util.regex.Pattern; try { return sessionDescriptionBuilder.build(); - } catch (IllegalStateException e) { + } catch (IllegalArgumentException | IllegalStateException e) { throw new ParserException(e); } } @@ -197,7 +197,7 @@ import java.util.regex.Pattern; throws ParserException { try { sessionDescriptionBuilder.addMediaDescription(mediaDescriptionBuilder.build()); - } catch (IllegalStateException e) { + } catch (IllegalArgumentException | IllegalStateException e) { throw new ParserException(e); } } diff --git a/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java b/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java index d0a6aa6b23..47cd40e714 100644 --- a/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java +++ b/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertThrows; import android.net.Uri; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.android.exoplayer2.ParserException; import org.junit.Test; import org.junit.runner.RunWith; @@ -149,6 +150,35 @@ public class SessionDescriptionTest { assertThat(sessionDescription).isEqualTo(expectedSession); } + @Test + public void parse_sdpStringWithDuplicatedMediaAttribute_throwsParserException() { + String testMediaSdpInfo = + "v=0\r\n" + + "o=MNobody 2890844526 2890842807 IN IP4 192.0.2.46\r\n" + + "s=SDP Seminar\r\n" + + "i=A Seminar on the session description protocol\r\n" + + "m=audio 3456 RTP/AVP 0\r\n" + + "a=control:audio\r\n" + + "a=control:audio\r\n"; + + assertThrows(ParserException.class, () -> SessionDescriptionParser.parse(testMediaSdpInfo)); + } + + @Test + public void parse_sdpStringWithDuplicatedSessionAttribute_throwsParserException() { + String testMediaSdpInfo = + "v=0\r\n" + + "o=MNobody 2890844526 2890842807 IN IP4 192.0.2.46\r\n" + + "s=SDP Seminar\r\n" + + "a=control:*\r\n" + + "a=control:*\r\n" + + "i=A Seminar on the session description protocol\r\n" + + "m=audio 3456 RTP/AVP 0\r\n" + + "a=control:audio\r\n"; + + assertThrows(ParserException.class, () -> SessionDescriptionParser.parse(testMediaSdpInfo)); + } + @Test public void buildMediaDescription_withInvalidRtpmapAttribute_throwsIllegalStateException() { assertThrows(