Commit 72ef70dc93 for ffmpeg
commit 72ef70dc934322ec69cd276fadf316f9682cabd2
Author: Martin Mirchev <mmirchev@comp.nus.edu.sg>
Date: Mon Nov 30 15:18:02 2026 +0800
avformat/rtsp: ignore non-NPT SDP ranges
rtsp_parse_range_npt() leaves its outputs untouched for non-NPT
ranges, so the SDP caller could write uninitialized timing values.
Skip the timing update when the helper does not recognize the range
format. SDP can describe a range in multiple time formats, so an
unsupported format should also preserve any NPT timing already parsed.
Signed-off-by: Martin Mirchev <mmirchev@comp.nus.edu.sg>
Assisted-by: Fairy
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index d455438fa5..4006fa634a 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -200,27 +200,29 @@ static void get_word(char *buf, int buf_size, const char **pp)
/** Parse a string p in the form of Range:npt=xx-xx, and determine the start
* and end time.
* Used for seeking in the rtp stream.
+ * Return 0 if the range uses NPT, even if a timestamp fails to parse,
+ * or AVERROR(ENOTSUP) for any other time format.
*/
-static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end)
+static int rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end)
{
char buf[256];
p += strspn(p, SPACE_CHARS);
if (!av_stristart(p, "npt=", &p))
- return;
+ return AVERROR(ENOTSUP);
*start = AV_NOPTS_VALUE;
*end = AV_NOPTS_VALUE;
get_word_sep(buf, sizeof(buf), "-", &p);
- if (av_parse_time(start, buf, 1) < 0)
- return;
- if (*p == '-') {
+ if (av_parse_time(start, buf, 1) >= 0 && *p == '-') {
p++;
get_word_sep(buf, sizeof(buf), "-", &p);
if (av_parse_time(end, buf, 1) < 0)
av_log(NULL, AV_LOG_DEBUG, "Failed to parse interval end specification '%s'\n", buf);
}
+
+ return 0;
}
static int get_sockaddr(AVFormatContext *s,
@@ -661,7 +663,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
int64_t start, end;
// this is so that seeking on a streamed file can work.
- rtsp_parse_range_npt(p, &start, &end);
+ if (rtsp_parse_range_npt(p, &start, &end) < 0)
+ return;
s->start_time = start;
/* AV_NOPTS_VALUE means live broadcast (and can't seek) */
if (end != AV_NOPTS_VALUE)