[FFmpeg-devel,2/2,v2] avcodec/h264: error out on ff_h264_pred_weight_table() only if strict spec compliance is requested

Submitted by James Almer on April 10, 2019, 5:54 p.m.

Details

Message ID 20190410175445.68-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer April 10, 2019, 5:54 p.m.
Fixes ticket #7174.

Signed-off-by: James Almer <jamrial@gmail.com>
---
Now using avpriv_request_sample()

 libavcodec/h264_parse.c | 15 +++++++++------
 libavcodec/h264_slice.c |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 8bdd886000..7842701975 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -31,6 +31,7 @@  int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
 {
     int list, i, j;
     int luma_def, chroma_def;
+    int ret = 0;
 
     pwt->use_weight             = 0;
     pwt->use_weight_chroma      = 0;
@@ -39,6 +40,7 @@  int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
     if (pwt->luma_log2_weight_denom > 7U) {
         av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", pwt->luma_log2_weight_denom);
         pwt->luma_log2_weight_denom = 0;
+        ret = AVERROR_INVALIDDATA;
     }
     luma_def = 1 << pwt->luma_log2_weight_denom;
 
@@ -47,6 +49,7 @@  int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
         if (pwt->chroma_log2_weight_denom > 7U) {
             av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", pwt->chroma_log2_weight_denom);
             pwt->chroma_log2_weight_denom = 0;
+            ret = AVERROR_INVALIDDATA;
         }
         chroma_def = 1 << pwt->chroma_log2_weight_denom;
     }
@@ -63,9 +66,10 @@  int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
                 pwt->luma_weight[i][list][1] = get_se_golomb(gb);
                 if ((int8_t)pwt->luma_weight[i][list][0] != pwt->luma_weight[i][list][0] ||
                     (int8_t)pwt->luma_weight[i][list][1] != pwt->luma_weight[i][list][1]) {
+                    avpriv_request_sample(logctx, "Out of range luma weight");
                     pwt->luma_weight[i][list][0] = luma_def;
                     pwt->luma_weight[i][list][1] = 0;
-                    goto out_range_weight;
+                    ret = AVERROR_INVALIDDATA;
                 }
                 if (pwt->luma_weight[i][list][0] != luma_def ||
                     pwt->luma_weight[i][list][1] != 0) {
@@ -86,9 +90,10 @@  int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
                         pwt->chroma_weight[i][list][j][1] = get_se_golomb(gb);
                         if ((int8_t)pwt->chroma_weight[i][list][j][0] != pwt->chroma_weight[i][list][j][0] ||
                             (int8_t)pwt->chroma_weight[i][list][j][1] != pwt->chroma_weight[i][list][j][1]) {
+                            avpriv_request_sample(logctx, "Out of range chroma weight");
                             pwt->chroma_weight[i][list][j][0] = chroma_def;
                             pwt->chroma_weight[i][list][j][1] = 0;
-                            goto out_range_weight;
+                            ret = AVERROR_INVALIDDATA;
                         }
                         if (pwt->chroma_weight[i][list][j][0] != chroma_def ||
                             pwt->chroma_weight[i][list][j][1] != 0) {
@@ -121,10 +126,8 @@  int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
             break;
     }
     pwt->use_weight = pwt->use_weight || pwt->use_weight_chroma;
-    return 0;
-out_range_weight:
-    avpriv_request_sample(logctx, "Out of range weight");
-    return AVERROR_INVALIDDATA;
+
+    return ret;
 }
 
 /**
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 1c9a270fb6..d3432d7b1f 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1867,7 +1867,7 @@  static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
         ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
                                   sl->slice_type_nos, &sl->pwt,
                                   picture_structure, h->avctx);
-        if (ret < 0)
+        if (ret < 0 && (h->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
             return ret;
     }