Message ID | 20191011173639.2080-1-jamrial@gmail.com |
---|---|
State | Accepted |
Commit | 72704cbff4257466662729fc20e3f0ab85aa8c9e |
Headers | show |
James Almer: > Also propagate proper AVERROR codes while at it. > > Fixes ticket #8230. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > libavformat/dv.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/libavformat/dv.c b/libavformat/dv.c > index eb44e0acb6..e99422d4b5 100644 > --- a/libavformat/dv.c > +++ b/libavformat/dv.c > @@ -495,16 +495,18 @@ static int dv_read_header(AVFormatContext *s) > { > unsigned state, marker_pos = 0; > RawDVContext *c = s->priv_data; > + int ret; > > c->dv_demux = avpriv_dv_init_demux(s); > if (!c->dv_demux) > - return -1; > + return AVERROR(ENOMEM); > > state = avio_rb32(s->pb); > while ((state & 0xffffff7f) != 0x1f07003f) { > if (avio_feof(s->pb)) { > av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n"); > - return -1; > + ret = AVERROR_INVALIDDATA; > + goto fail; > } > if (state == 0x003f0700 || state == 0xff3f0700) > marker_pos = avio_tell(s->pb); > @@ -518,8 +520,10 @@ static int dv_read_header(AVFormatContext *s) > AV_WB32(c->buf, state); > > if (avio_read(s->pb, c->buf + 4, DV_PROFILE_BYTES - 4) != DV_PROFILE_BYTES - 4 || > - avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) > - return AVERROR(EIO); > + avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) { > + ret = AVERROR(EIO); > + goto fail; > + } > > c->dv_demux->sys = av_dv_frame_profile(c->dv_demux->sys, > c->buf, > @@ -527,7 +531,8 @@ static int dv_read_header(AVFormatContext *s) > if (!c->dv_demux->sys) { > av_log(s, AV_LOG_ERROR, > "Can't determine profile of DV input stream.\n"); > - return -1; > + ret = AVERROR_INVALIDDATA; > + goto fail; > } > > s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size, > @@ -538,6 +543,11 @@ static int dv_read_header(AVFormatContext *s) > dv_read_timecode(s); > > return 0; > + > +fail: > + av_freep(&c->dv_demux); > + > + return ret; > } > > static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) > LGTM. - Andreas
On 10/11/2019 8:36 PM, Andreas Rheinhardt wrote: > James Almer: >> Also propagate proper AVERROR codes while at it. >> >> Fixes ticket #8230. >> >> Signed-off-by: James Almer <jamrial@gmail.com> >> --- >> libavformat/dv.c | 20 +++++++++++++++----- >> 1 file changed, 15 insertions(+), 5 deletions(-) >> >> diff --git a/libavformat/dv.c b/libavformat/dv.c >> index eb44e0acb6..e99422d4b5 100644 >> --- a/libavformat/dv.c >> +++ b/libavformat/dv.c >> @@ -495,16 +495,18 @@ static int dv_read_header(AVFormatContext *s) >> { >> unsigned state, marker_pos = 0; >> RawDVContext *c = s->priv_data; >> + int ret; >> >> c->dv_demux = avpriv_dv_init_demux(s); >> if (!c->dv_demux) >> - return -1; >> + return AVERROR(ENOMEM); >> >> state = avio_rb32(s->pb); >> while ((state & 0xffffff7f) != 0x1f07003f) { >> if (avio_feof(s->pb)) { >> av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n"); >> - return -1; >> + ret = AVERROR_INVALIDDATA; >> + goto fail; >> } >> if (state == 0x003f0700 || state == 0xff3f0700) >> marker_pos = avio_tell(s->pb); >> @@ -518,8 +520,10 @@ static int dv_read_header(AVFormatContext *s) >> AV_WB32(c->buf, state); >> >> if (avio_read(s->pb, c->buf + 4, DV_PROFILE_BYTES - 4) != DV_PROFILE_BYTES - 4 || >> - avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) >> - return AVERROR(EIO); >> + avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) { >> + ret = AVERROR(EIO); >> + goto fail; >> + } >> >> c->dv_demux->sys = av_dv_frame_profile(c->dv_demux->sys, >> c->buf, >> @@ -527,7 +531,8 @@ static int dv_read_header(AVFormatContext *s) >> if (!c->dv_demux->sys) { >> av_log(s, AV_LOG_ERROR, >> "Can't determine profile of DV input stream.\n"); >> - return -1; >> + ret = AVERROR_INVALIDDATA; >> + goto fail; >> } >> >> s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size, >> @@ -538,6 +543,11 @@ static int dv_read_header(AVFormatContext *s) >> dv_read_timecode(s); >> >> return 0; >> + >> +fail: >> + av_freep(&c->dv_demux); >> + >> + return ret; >> } >> >> static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) >> > LGTM. > > - Andreas Applied, thanks.
diff --git a/libavformat/dv.c b/libavformat/dv.c index eb44e0acb6..e99422d4b5 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -495,16 +495,18 @@ static int dv_read_header(AVFormatContext *s) { unsigned state, marker_pos = 0; RawDVContext *c = s->priv_data; + int ret; c->dv_demux = avpriv_dv_init_demux(s); if (!c->dv_demux) - return -1; + return AVERROR(ENOMEM); state = avio_rb32(s->pb); while ((state & 0xffffff7f) != 0x1f07003f) { if (avio_feof(s->pb)) { av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n"); - return -1; + ret = AVERROR_INVALIDDATA; + goto fail; } if (state == 0x003f0700 || state == 0xff3f0700) marker_pos = avio_tell(s->pb); @@ -518,8 +520,10 @@ static int dv_read_header(AVFormatContext *s) AV_WB32(c->buf, state); if (avio_read(s->pb, c->buf + 4, DV_PROFILE_BYTES - 4) != DV_PROFILE_BYTES - 4 || - avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) - return AVERROR(EIO); + avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) { + ret = AVERROR(EIO); + goto fail; + } c->dv_demux->sys = av_dv_frame_profile(c->dv_demux->sys, c->buf, @@ -527,7 +531,8 @@ static int dv_read_header(AVFormatContext *s) if (!c->dv_demux->sys) { av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n"); - return -1; + ret = AVERROR_INVALIDDATA; + goto fail; } s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size, @@ -538,6 +543,11 @@ static int dv_read_header(AVFormatContext *s) dv_read_timecode(s); return 0; + +fail: + av_freep(&c->dv_demux); + + return ret; } static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
Also propagate proper AVERROR codes while at it. Fixes ticket #8230. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/dv.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)