diff mbox

[FFmpeg-devel,2/5] avformat/mpeg: Add padding to extradata

Message ID 20191022131645.8394-2-andreas.rheinhardt@gmail.com
State Accepted
Commit c36eae65e488d8b047d37aa157c3c3c033f6489d
Headers show

Commit Message

Andreas Rheinhardt Oct. 22, 2019, 1:16 p.m. UTC
Extradata is supposed to be padded with AV_INPUT_BUFFER_PADDING_SIZE bytes,
yet the VobSub demuxer used av_strdup for the allocation of extradata.
This has been changed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
I did not change the extradata_size in order to explicitly include a
zero byte; i.e. the first byte of the padding is the zero byte ending
the string. This is just like now.

 libavformat/mpeg.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Michael Niedermayer Oct. 24, 2019, 5:51 p.m. UTC | #1
On Tue, Oct 22, 2019 at 03:16:42PM +0200, Andreas Rheinhardt wrote:
> Extradata is supposed to be padded with AV_INPUT_BUFFER_PADDING_SIZE bytes,
> yet the VobSub demuxer used av_strdup for the allocation of extradata.
> This has been changed.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> I did not change the extradata_size in order to explicitly include a
> zero byte; i.e. the first byte of the padding is the zero byte ending
> the string. This is just like now.
> 
>  libavformat/mpeg.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index ebc064931a..46c59163fd 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -769,7 +769,7 @@  static int vobsub_read_header(AVFormatContext *s)
         goto end;
     }
 
-    av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED);
+    av_bprint_init(&header, 0, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
     while (!avio_feof(s->pb)) {
         char line[MAX_LINE_SIZE];
         int len = ff_get_line(s->pb, line, sizeof(line));
@@ -896,14 +896,12 @@  static int vobsub_read_header(AVFormatContext *s)
     }
     av_bprint_finalize(&header, &header_str);
     for (i = 0; i < s->nb_streams; i++) {
-        AVStream *sub_st = s->streams[i];
-        sub_st->codecpar->extradata      = av_strdup(header_str);
-        if (!sub_st->codecpar->extradata) {
-            ret = AVERROR(ENOMEM);
-            sub_st->codecpar->extradata_size = 0;
+        AVCodecParameters *par = s->streams[i]->codecpar;
+        ret = ff_alloc_extradata(par, header.len);
+        if (ret < 0) {
             goto end;
         }
-        sub_st->codecpar->extradata_size = header.len;
+        memcpy(par->extradata, header_str, header.len);
     }
 end: