[FFmpeg-devel] [PATCH v3] libavcodec/vp9: fix ref-frame size judging method

2019-07-08 Thread Yan Cen
From: yancen 

There is no need all reference frame demension is valid in libvpx.

So this change contains three part:
1. Change each judgement's loglevel from "ERROR" to "WARNING"
2. Make sure at least one of frames that this frame references has valid 
dimension.
3. All judgements fail would report "ERROR".

Signed-off-by: Xiang Haihao 
Signed-off-by: Li Zhong 
Signed-off-by: Yan Cen 
---
 libavcodec/vp9.c | 51 +++
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc..58e7312 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -555,11 +555,37 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.signbias[1]= get_bits1(>gb) && !s->s.h.errorres;
 s->s.h.refidx[2]  = get_bits(>gb, 3);
 s->s.h.signbias[2]= get_bits1(>gb) && !s->s.h.errorres;
-if (!s->s.refs[s->s.h.refidx[0]].f->buf[0] ||
-!s->s.refs[s->s.h.refidx[1]].f->buf[0] ||
-!s->s.refs[s->s.h.refidx[2]].f->buf[0]) {
-av_log(avctx, AV_LOG_ERROR, "Not all references are 
available\n");
-return AVERROR_INVALIDDATA;
+if (0 == sizeof(s->s.refs[s->s.h.refidx[0]])) {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[1]].f->buf[0])) {
+if (0 == s->s.refs[s->s.h.refidx[2]].f->buf[0]) {
+av_log(avctx, AV_LOG_ERROR, "All references are 
unavailable\n");
+return AVERROR_INVALIDDATA;
+} else {
+
av_frame_copy(s->s.refs[s->s.h.refidx[1]].f,s->s.refs[s->s.h.refidx[2]].f);
+
av_frame_copy(s->s.refs[s->s.h.refidx[0]].f,s->s.refs[s->s.h.refidx[2]].f);
+}
+} else {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[2]].f->buf[0])) {
+
av_frame_copy(s->s.refs[s->s.h.refidx[0]].f,s->s.refs[s->s.h.refidx[1]].f);
+
av_frame_copy(s->s.refs[s->s.h.refidx[2]].f,s->s.refs[s->s.h.refidx[1]].f);
+} else {
+
av_frame_copy(s->s.refs[s->s.h.refidx[0]].f,s->s.refs[s->s.h.refidx[1]].f);
+}
+}
+} else {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[1]].f->buf[0])) {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[2]].f->buf[0])) {
+s->s.refs[s->s.h.refidx[1]].f = 
s->s.refs[s->s.h.refidx[2]].f = s->s.refs[s->s.h.refidx[0]].f;
+
av_frame_copy(s->s.refs[s->s.h.refidx[1]].f,s->s.refs[s->s.h.refidx[0]].f);
+
av_frame_copy(s->s.refs[s->s.h.refidx[2]].f,s->s.refs[s->s.h.refidx[0]].f);
+} else {
+
av_frame_copy(s->s.refs[s->s.h.refidx[1]].f,s->s.refs[s->s.h.refidx[0]].f);
+}
+} else {
+if (0 == sizeof(s->s.refs[s->s.h.refidx[2]].f->buf[0])) {
+
av_frame_copy(s->s.refs[s->s.h.refidx[2]].f,s->s.refs[s->s.h.refidx[1]].f);
+}
+}
 }
 if (get_bits1(>gb)) {
 w = s->s.refs[s->s.h.refidx[0]].f->width;
@@ -790,6 +816,7 @@ static int decode_frame_header(AVCodecContext *avctx,
 
 /* check reference frames */
 if (!s->s.h.keyframe && !s->s.h.intraonly) {
+int has_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;
@@ -802,12 +829,15 @@ static int decode_frame_header(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 } else if (refw == w && refh == h) {
 s->mvscale[i][0] = s->mvscale[i][1] = 0;
+has_valid_ref_frame = 1;
 } else {
-if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * 
refh) {
-av_log(avctx, AV_LOG_ERROR,
+int is_ref_frame_invalid = (w * 2 < refw || h * 2 < refh || w 
> 16 * refw || h > 16 * refh);
+if (is_ref_frame_invalid) {
+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;
+} else {
+has_valid_ref_frame = 1;
 }

[FFmpeg-devel] [PATCH v2] libavcodec/vp9: fix ref-frame size judging method

2019-05-19 Thread Yan Cen
From: yancen 

There is no need all reference frame demension is valid in libvpx.

So this change contains three part:
1. Change each judgement's loglevel from "ERROR" to "WARNING"
2. Make sure at least one of frames that this frame references has valid 
dimension.
3. All judgements fail would report "ERROR".

Signed-off-by: Xiang Haihao 
Signed-off-by: Li Zhong 
Signed-off-by: Yan Cen 
---
 libavcodec/vp9.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc..849c1a6 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -790,6 +790,7 @@ static int decode_frame_header(AVCodecContext *avctx,
 
 /* check reference frames */
 if (!s->s.h.keyframe && !s->s.h.intraonly) {
+int has_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;
@@ -802,12 +803,15 @@ static int decode_frame_header(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 } else if (refw == w && refh == h) {
 s->mvscale[i][0] = s->mvscale[i][1] = 0;
+has_valid_ref_frame = 1;
 } else {
-if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * 
refh) {
-av_log(avctx, AV_LOG_ERROR,
+int is_ref_frame_invalid = (w * 2 < refw || h * 2 < refh || w 
> 16 * refw || h > 16 * refh);
+if (is_ref_frame_invalid) {
+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;
+} else {
+has_valid_ref_frame = 1;
 }
 s->mvscale[i][0] = (refw << 14) / w;
 s->mvscale[i][1] = (refh << 14) / h;
@@ -815,6 +819,11 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
 }
 }
+if (!has_valid_ref_frame) {
+av_log(avctx, AV_LOG_ERROR,
+   "Referenced frame has invalid size\n");
+return AVERROR_INVALIDDATA;
+}
 }
 
 if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && 
s->s.h.resetctx == 3)) {
-- 
2.7.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-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavcodec/vp9: fix ref-frame size judging method

2019-04-29 Thread Yan Cen
From: Yan Cen 

There is no need all reference frame demension is valid in libvpx.

So this change contains three part:
1. Change each judgement's loglevel from "ERROR" to "WARNING"
2. Make sure at least one of frames that this frame references has valid 
dimension.
3. All judgements fail would report "ERROR".

Signed-off-by: Yan Cen
---
 libavcodec/vp9.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acf3ffc..8dd14e0 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -790,6 +790,7 @@ static int decode_frame_header(AVCodecContext *avctx,
 
 /* check reference frames */
 if (!s->s.h.keyframe && !s->s.h.intraonly) {
+int has_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;
@@ -802,12 +803,14 @@ static int decode_frame_header(AVCodecContext *avctx,
 return AVERROR_INVALIDDATA;
 } else if (refw == w && refh == h) {
 s->mvscale[i][0] = s->mvscale[i][1] = 0;
+has_valid_ref_frame = 1;
 } else {
-if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * 
refh) {
-av_log(avctx, AV_LOG_ERROR,
+int is_ref_frame_invalid = (w * 2 < refw || h * 2 < refh || w 
> 16 * refw || h > 16 * refh);
+has_valid_ref_frame |= !is_ref_frame_invalid;
+if (is_ref_frame_invalid) {
+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;
 }
 s->mvscale[i][0] = (refw << 14) / w;
 s->mvscale[i][1] = (refh << 14) / h;
@@ -815,6 +818,11 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
 }
 }
+if (!has_valid_ref_frame) {
+av_log(avctx, AV_LOG_ERROR,
+   "Referenced frame has invalid size\n");
+return AVERROR_INVALIDDATA;
+}
 }
 
 if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && 
s->s.h.resetctx == 3)) {
-- 
2.7.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-requ...@ffmpeg.org with subject "unsubscribe".