diff mbox

[FFmpeg-devel,v3,1/3] avformat/hlsenc: fix the av_dirname path isn't include separator in the end of string

Message ID 20191023155517.335-1-lance.lmwang@gmail.com
State Accepted
Commit 7c872df3e175d1c9de4aeb294abcd7c6ab4bb0f3
Headers show

Commit Message

Limin Wang Oct. 23, 2019, 3:55 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/hlsenc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Limin Wang Oct. 24, 2019, 1:04 a.m. UTC | #1
It's rebased against git master, the old patch has conflict for other
developer push.

On Wed, Oct 23, 2019 at 11:55:15PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavformat/hlsenc.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 7b1d54e..af4b532 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -478,6 +478,12 @@ static void reflush_dynbuf(VariantStream *vs, int *range_length)
>      avio_write(vs->out, vs->temp_buffer, *range_length);;
>  }
>  
> +#if HAVE_DOS_PATHS
> +#define SEPARATOR '\\'
> +#else
> +#define SEPARATOR '/'
> +#endif
> +
>  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>                                     VariantStream *vs)
>  {
> @@ -544,7 +550,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>      while (segment) {
>          av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
>                 segment->filename);
> -        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1;
> +        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)+1) + strlen(segment->filename) + 1;
>          path = av_malloc(path_size);
>          if (!path) {
>              ret = AVERROR(ENOMEM);
> @@ -554,8 +560,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>          if (hls->use_localtime_mkdir)
>              av_strlcpy(path, segment->filename, path_size);
>          else { // segment->filename contains basename only
> -            av_strlcpy(path, dirname, path_size);
> -            av_strlcat(path, segment->filename, path_size);
> +            snprintf(path, path_size, "%s%c%s", dirname, SEPARATOR, segment->filename);
>          }
>  
>          proto = avio_find_protocol_name(s->url);
> @@ -575,15 +580,14 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>          if ((segment->sub_filename[0] != '\0')) {
>              char *vtt_dirname_r = av_strdup(vs->vtt_avf->url);
>              vtt_dirname = (char*)av_dirname(vtt_dirname_r);
> -            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname);
> +            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname) + 1;
>              sub_path = av_malloc(sub_path_size);
>              if (!sub_path) {
>                  ret = AVERROR(ENOMEM);
>                  goto fail;
>              }
>  
> -            av_strlcpy(sub_path, vtt_dirname, sub_path_size);
> -            av_strlcat(sub_path, segment->sub_filename, sub_path_size);
> +            snprintf(sub_path, sub_path_size, "%s%c%s", vtt_dirname, SEPARATOR, segment->sub_filename);
>  
>              av_freep(&vtt_dirname);
>  
> -- 
> 2.6.4
>
Limin Wang Oct. 31, 2019, 6:01 a.m. UTC | #2
ping, please help to push the patch, it'll fix ticket #8348 although I have sumit the fix long
time ago after Miachel report it.


On Wed, Oct 23, 2019 at 11:55:15PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavformat/hlsenc.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 7b1d54e..af4b532 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -478,6 +478,12 @@ static void reflush_dynbuf(VariantStream *vs, int *range_length)
>      avio_write(vs->out, vs->temp_buffer, *range_length);;
>  }
>  
> +#if HAVE_DOS_PATHS
> +#define SEPARATOR '\\'
> +#else
> +#define SEPARATOR '/'
> +#endif
> +
>  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>                                     VariantStream *vs)
>  {
> @@ -544,7 +550,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>      while (segment) {
>          av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
>                 segment->filename);
> -        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1;
> +        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)+1) + strlen(segment->filename) + 1;
>          path = av_malloc(path_size);
>          if (!path) {
>              ret = AVERROR(ENOMEM);
> @@ -554,8 +560,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>          if (hls->use_localtime_mkdir)
>              av_strlcpy(path, segment->filename, path_size);
>          else { // segment->filename contains basename only
> -            av_strlcpy(path, dirname, path_size);
> -            av_strlcat(path, segment->filename, path_size);
> +            snprintf(path, path_size, "%s%c%s", dirname, SEPARATOR, segment->filename);
>          }
>  
>          proto = avio_find_protocol_name(s->url);
> @@ -575,15 +580,14 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>          if ((segment->sub_filename[0] != '\0')) {
>              char *vtt_dirname_r = av_strdup(vs->vtt_avf->url);
>              vtt_dirname = (char*)av_dirname(vtt_dirname_r);
> -            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname);
> +            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname) + 1;
>              sub_path = av_malloc(sub_path_size);
>              if (!sub_path) {
>                  ret = AVERROR(ENOMEM);
>                  goto fail;
>              }
>  
> -            av_strlcpy(sub_path, vtt_dirname, sub_path_size);
> -            av_strlcat(sub_path, segment->sub_filename, sub_path_size);
> +            snprintf(sub_path, sub_path_size, "%s%c%s", vtt_dirname, SEPARATOR, segment->sub_filename);
>  
>              av_freep(&vtt_dirname);
>  
> -- 
> 2.6.4
>
Steven Liu Oct. 31, 2019, 6:17 a.m. UTC | #3
> 在 2019年10月31日,14:01,Limin Wang <lance.lmwang@gmail.com> 写道:
> 
> 
> 
> ping, please help to push the patch, it'll fix ticket #8348 although I have sumit the fix long
> time ago after Miachel report it.
Waiting that reporter test it, i will push it if test passed.
> 
> 
> On Wed, Oct 23, 2019 at 11:55:15PM +0800, lance.lmwang@gmail.com wrote:
>> From: Limin Wang <lance.lmwang@gmail.com>
>> 
>> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> ---
>> libavformat/hlsenc.c | 16 ++++++++++------
>> 1 file changed, 10 insertions(+), 6 deletions(-)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index 7b1d54e..af4b532 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -478,6 +478,12 @@ static void reflush_dynbuf(VariantStream *vs, int *range_length)
>>     avio_write(vs->out, vs->temp_buffer, *range_length);;
>> }
>> 
>> +#if HAVE_DOS_PATHS
>> +#define SEPARATOR '\\'
>> +#else
>> +#define SEPARATOR '/'
>> +#endif
>> +
>> static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>>                                    VariantStream *vs)
>> {
>> @@ -544,7 +550,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>>     while (segment) {
>>         av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
>>                segment->filename);
>> -        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1;
>> +        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)+1) + strlen(segment->filename) + 1;
>>         path = av_malloc(path_size);
>>         if (!path) {
>>             ret = AVERROR(ENOMEM);
>> @@ -554,8 +560,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>>         if (hls->use_localtime_mkdir)
>>             av_strlcpy(path, segment->filename, path_size);
>>         else { // segment->filename contains basename only
>> -            av_strlcpy(path, dirname, path_size);
>> -            av_strlcat(path, segment->filename, path_size);
>> +            snprintf(path, path_size, "%s%c%s", dirname, SEPARATOR, segment->filename);
>>         }
>> 
>>         proto = avio_find_protocol_name(s->url);
>> @@ -575,15 +580,14 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>>         if ((segment->sub_filename[0] != '\0')) {
>>             char *vtt_dirname_r = av_strdup(vs->vtt_avf->url);
>>             vtt_dirname = (char*)av_dirname(vtt_dirname_r);
>> -            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname);
>> +            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname) + 1;
>>             sub_path = av_malloc(sub_path_size);
>>             if (!sub_path) {
>>                 ret = AVERROR(ENOMEM);
>>                 goto fail;
>>             }
>> 
>> -            av_strlcpy(sub_path, vtt_dirname, sub_path_size);
>> -            av_strlcat(sub_path, segment->sub_filename, sub_path_size);
>> +            snprintf(sub_path, sub_path_size, "%s%c%s", vtt_dirname, SEPARATOR, segment->sub_filename);
>> 
>>             av_freep(&vtt_dirname);
>> 
>> -- 
>> 2.6.4
>> 
> _______________________________________________
> 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".

Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7b1d54e..af4b532 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -478,6 +478,12 @@  static void reflush_dynbuf(VariantStream *vs, int *range_length)
     avio_write(vs->out, vs->temp_buffer, *range_length);;
 }
 
+#if HAVE_DOS_PATHS
+#define SEPARATOR '\\'
+#else
+#define SEPARATOR '/'
+#endif
+
 static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
                                    VariantStream *vs)
 {
@@ -544,7 +550,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
     while (segment) {
         av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
                segment->filename);
-        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1;
+        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)+1) + strlen(segment->filename) + 1;
         path = av_malloc(path_size);
         if (!path) {
             ret = AVERROR(ENOMEM);
@@ -554,8 +560,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
         if (hls->use_localtime_mkdir)
             av_strlcpy(path, segment->filename, path_size);
         else { // segment->filename contains basename only
-            av_strlcpy(path, dirname, path_size);
-            av_strlcat(path, segment->filename, path_size);
+            snprintf(path, path_size, "%s%c%s", dirname, SEPARATOR, segment->filename);
         }
 
         proto = avio_find_protocol_name(s->url);
@@ -575,15 +580,14 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
         if ((segment->sub_filename[0] != '\0')) {
             char *vtt_dirname_r = av_strdup(vs->vtt_avf->url);
             vtt_dirname = (char*)av_dirname(vtt_dirname_r);
-            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname);
+            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname) + 1;
             sub_path = av_malloc(sub_path_size);
             if (!sub_path) {
                 ret = AVERROR(ENOMEM);
                 goto fail;
             }
 
-            av_strlcpy(sub_path, vtt_dirname, sub_path_size);
-            av_strlcat(sub_path, segment->sub_filename, sub_path_size);
+            snprintf(sub_path, sub_path_size, "%s%c%s", vtt_dirname, SEPARATOR, segment->sub_filename);
 
             av_freep(&vtt_dirname);