diff mbox series

[FFmpeg-devel] avformat/hlsenc: correctly reset subtitle stream counter per-varstream

Message ID 20240816000301.61579-1-timo@rothenpieler.org
State New
Headers show
Series [FFmpeg-devel] avformat/hlsenc: correctly reset subtitle stream counter per-varstream | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Timo Rothenpieler Aug. 16, 2024, 12:02 a.m. UTC
Without resetting it, if there was a previous set of varstreams with
subtitles, it would subtract from all the streams, leading to chaos and
segfaults when trying to access for example stream -1.
---
 libavformat/hlsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Steven Liu Aug. 16, 2024, 2:20 a.m. UTC | #1
Timo Rothenpieler <timo@rothenpieler.org>于2024年8月16日 周五08:03写道:

> Without resetting it, if there was a previous set of varstreams with
> subtitles, it would subtract from all the streams, leading to chaos and
> segfaults when trying to access for example stream -1.
> ---
>  libavformat/hlsenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 6d6ede1b6f..1e932b7b0e 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2441,7 +2441,6 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>      int is_ref_pkt = 1;
>      int ret = 0, can_split = 1, i, j;
>      int stream_index = 0;
> -    int subtitle_streams = 0;
>      int range_length = 0;
>      const char *proto = NULL;
>      int use_temp_file = 0;
> @@ -2449,6 +2448,7 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>      char *old_filename = NULL;
>
>      for (i = 0; i < hls->nb_varstreams; i++) {
> +        int subtitle_streams = 0;
>          vs = &hls->var_streams[i];
>          for (j = 0; j < vs->nb_streams; j++) {
>              if (vs->streams[j]->codecpar->codec_type ==
> AVMEDIA_TYPE_SUBTITLE) {
> --
> 2.44.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".


should be ok
It this patch fix ticket 9719?



Thanks
Steven

>
>
Timo Rothenpieler Aug. 16, 2024, 12:03 p.m. UTC | #2
On 16/08/2024 04:20, Steven Liu wrote:
> Timo Rothenpieler <timo@rothenpieler.org>于2024年8月16日 周五08:03写道:
> 
>> Without resetting it, if there was a previous set of varstreams with
>> subtitles, it would subtract from all the streams, leading to chaos and
>> segfaults when trying to access for example stream -1.
>> ---
>>   libavformat/hlsenc.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index 6d6ede1b6f..1e932b7b0e 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -2441,7 +2441,6 @@ static int hls_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>       int is_ref_pkt = 1;
>>       int ret = 0, can_split = 1, i, j;
>>       int stream_index = 0;
>> -    int subtitle_streams = 0;
>>       int range_length = 0;
>>       const char *proto = NULL;
>>       int use_temp_file = 0;
>> @@ -2449,6 +2448,7 @@ static int hls_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>       char *old_filename = NULL;
>>
>>       for (i = 0; i < hls->nb_varstreams; i++) {
>> +        int subtitle_streams = 0;
>>           vs = &hls->var_streams[i];
>>           for (j = 0; j < vs->nb_streams; j++) {
>>               if (vs->streams[j]->codecpar->codec_type ==
>> AVMEDIA_TYPE_SUBTITLE) {
>> --
>> 2.44.2
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 
> 
> should be ok
> It this patch fix ticket 9719?
> 

It was intended to fix ticket 9877, but 9719 looks to be the same issue.

Basically whenever a var stream map with subtitles in any but the last 
set of streams is used, it'll inevitably segfault right now.

Will apply soon and backport as far as possible, likely all the way back 
to 5.0.
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 6d6ede1b6f..1e932b7b0e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2441,7 +2441,6 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     int is_ref_pkt = 1;
     int ret = 0, can_split = 1, i, j;
     int stream_index = 0;
-    int subtitle_streams = 0;
     int range_length = 0;
     const char *proto = NULL;
     int use_temp_file = 0;
@@ -2449,6 +2448,7 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     char *old_filename = NULL;
 
     for (i = 0; i < hls->nb_varstreams; i++) {
+        int subtitle_streams = 0;
         vs = &hls->var_streams[i];
         for (j = 0; j < vs->nb_streams; j++) {
             if (vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {