diff mbox series

[FFmpeg-devel] lavc/vp9: fix reference frame dimensions check

Message ID 1583923145-9182-1-git-send-email-linjie.fu@intel.com
State New
Headers show
Series [FFmpeg-devel] lavc/vp9: fix reference frame dimensions check
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Fu, Linjie March 11, 2020, 10:39 a.m. UTC
With the description in frame size with refs semantics (SPEC 7.2.5),
it is a requirement of bitstream conformance that for at least one
reference frame has the valid dimensions.

Modify the check to make sure the decoder works well in the condition
that not all references frames have valid dimensions.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
Fix the the decoding faiure for frames with dimension-ilegal refs.
Verifying with native vp9 and libvpx-vp9 decoder, the md5 result matches.
https://github.com/webmproject/libvpx/blob/master/vp9/decoder/vp9_decodeframe.c#L1580

 libavcodec/vp9.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Carl Eugen Hoyos March 11, 2020, 10:47 a.m. UTC | #1
Am Mi., 11. März 2020 um 11:44 Uhr schrieb Linjie Fu <linjie.fu@intel.com>:
>
> With the description in frame size with refs semantics (SPEC 7.2.5),
> it is a requirement of bitstream conformance that for at least one
> reference frame has the valid dimensions.
>
> Modify the check to make sure the decoder works well in the condition
> that not all references frames have valid dimensions.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> Fix the the decoding faiure for frames with dimension-ilegal refs.
> Verifying with native vp9 and libvpx-vp9 decoder, the md5 result matches.
> https://github.com/webmproject/libvpx/blob/master/vp9/decoder/vp9_decodeframe.c#L1580

Did you provide a sample?

Carl Eugen
Fu, Linjie March 11, 2020, 12:44 p.m. UTC | #2
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Carl Eugen Hoyos
> Sent: Wednesday, March 11, 2020 18:48
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/vp9: fix reference frame
> dimensions check
> 
> Am Mi., 11. März 2020 um 11:44 Uhr schrieb Linjie Fu <linjie.fu@intel.com>:
> >
> > With the description in frame size with refs semantics (SPEC 7.2.5),
> > it is a requirement of bitstream conformance that for at least one
> > reference frame has the valid dimensions.
> >
> > Modify the check to make sure the decoder works well in the condition
> > that not all references frames have valid dimensions.
> >
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > ---
> > Fix the the decoding faiure for frames with dimension-ilegal refs.
> > Verifying with native vp9 and libvpx-vp9 decoder, the md5 result matches.
> >
> https://github.com/webmproject/libvpx/blob/master/vp9/decoder/vp9_de
> codeframe.c#L1580
> 
> Did you provide a sample?
> 
I'd like to, but to be honest, it seems kind of hard to produce such a stream available
for public (compared with setting TU depth for one frame), hence I could not promise
but will try. (any hints for this?)

To elaborate more, one of the failure case is a 480x272 inter frame with two refs:
Ref[0]: 1920x1088 key frame, invalid;
Ref[1]:  960x 544 inter frame, valid;

Which reports:
[vp9 @ 0x55b18d9be280] Invalid ref frame dimensions 1920x1088 for frame size 480x272

- Linjie
Carl Eugen Hoyos March 11, 2020, 1:42 p.m. UTC | #3
Am Mi., 11. März 2020 um 13:44 Uhr schrieb Fu, Linjie <linjie.fu@intel.com>:
>
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Carl Eugen Hoyos
> > Sent: Wednesday, March 11, 2020 18:48
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/vp9: fix reference frame
> > dimensions check
> >
> > Am Mi., 11. März 2020 um 11:44 Uhr schrieb Linjie Fu <linjie.fu@intel.com>:
> > >
> > > With the description in frame size with refs semantics (SPEC 7.2.5),
> > > it is a requirement of bitstream conformance that for at least one
> > > reference frame has the valid dimensions.
> > >
> > > Modify the check to make sure the decoder works well in the condition
> > > that not all references frames have valid dimensions.
> > >
> > > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > > ---
> > > Fix the the decoding faiure for frames with dimension-ilegal refs.
> > > Verifying with native vp9 and libvpx-vp9 decoder, the md5 result matches.
> > >
> > https://github.com/webmproject/libvpx/blob/master/vp9/decoder/vp9_de
> > codeframe.c#L1580
> >
> > Did you provide a sample?
> >
> I'd like to, but to be honest, it seems kind of hard to produce such a stream available
> for public (compared with setting TU depth for one frame), hence I could not promise
> but will try. (any hints for this?)
>
> To elaborate more, one of the failure case is a 480x272 inter frame with two refs:
> Ref[0]: 1920x1088 key frame, invalid;
> Ref[1]:  960x 544 inter frame, valid;
>
> Which reports:
> [vp9 @ 0x55b18d9be280] Invalid ref frame dimensions 1920x1088 for frame size 480x272

This should be even more part of the commit message if you cannot
provide a sample.

Carl Eugen
Fu, Linjie March 11, 2020, 3:51 p.m. UTC | #4
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Carl Eugen Hoyos
> Sent: Wednesday, March 11, 2020 21:42
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/vp9: fix reference frame
> dimensions check
> 
> Am Mi., 11. März 2020 um 13:44 Uhr schrieb Fu, Linjie <linjie.fu@intel.com>:
> >
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Carl Eugen Hoyos
> > > Sent: Wednesday, March 11, 2020 18:48
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH] lavc/vp9: fix reference frame
> > > dimensions check
> > >
> > > Am Mi., 11. März 2020 um 11:44 Uhr schrieb Linjie Fu
> <linjie.fu@intel.com>:
> > > >
> > > > With the description in frame size with refs semantics (SPEC 7.2.5),
> > > > it is a requirement of bitstream conformance that for at least one
> > > > reference frame has the valid dimensions.
> > > >
> > > > Modify the check to make sure the decoder works well in the condition
> > > > that not all references frames have valid dimensions.
> > > >
> > > > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > > > ---
> > > > Fix the the decoding faiure for frames with dimension-ilegal refs.
> > > > Verifying with native vp9 and libvpx-vp9 decoder, the md5 result
> matches.
> > > >
> > >
> https://github.com/webmproject/libvpx/blob/master/vp9/decoder/vp9_de
> > > codeframe.c#L1580
> > >
> > > Did you provide a sample?
> > >
> > I'd like to, but to be honest, it seems kind of hard to produce such a stream
> available
> > for public (compared with setting TU depth for one frame), hence I could
> not promise
> > but will try. (any hints for this?)
> >
> > To elaborate more, one of the failure case is a 480x272 inter frame with two
> refs:
> > Ref[0]: 1920x1088 key frame, invalid;
> > Ref[1]:  960x 544 inter frame, valid;
> >
> > Which reports:
> > [vp9 @ 0x55b18d9be280] Invalid ref frame dimensions 1920x1088 for frame
> size 480x272
> 
> This should be even more part of the commit message if you cannot
> provide a sample.
> 
Ok, will elaborate more in the commit message.
Waiting for more comments (if there is any) before doing this, thanks

- Linjie
diff mbox series

Patch

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7aaae9b..61d60ef 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -794,6 +794,7 @@  static int decode_frame_header(AVCodecContext *avctx,
 
     /* check reference frames */
     if (!s->s.h.keyframe && !s->s.h.intraonly) {
+        int valid_ref_frame = 0;
         for (i = 0; i < 3; i++) {
             AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
             int refw = ref->width, refh = ref->height;
@@ -807,18 +808,23 @@  static int decode_frame_header(AVCodecContext *avctx,
             } else if (refw == w && refh == h) {
                 s->mvscale[i][0] = s->mvscale[i][1] = 0;
             } else {
+                /* Check to make sure at least one of frames that */
+                /* this frame references has valid dimensions. */
                 if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * refh) {
-                    av_log(avctx, AV_LOG_ERROR,
+                    av_log(avctx, AV_LOG_WARNING,
                            "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
                            refw, refh, w, h);
-                    return AVERROR_INVALIDDATA;
+                    continue;
                 }
                 s->mvscale[i][0] = (refw << 14) / w;
                 s->mvscale[i][1] = (refh << 14) / h;
                 s->mvstep[i][0] = 16 * s->mvscale[i][0] >> 14;
                 s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
             }
+            valid_ref_frame++;
         }
+        if (!valid_ref_frame)
+            return AVERROR_INVALIDDATA;
     }
 
     if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && s->s.h.resetctx == 3)) {