From patchwork Wed Apr 10 17:54:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 12693 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DD580448451 for ; Wed, 10 Apr 2019 20:55:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BDDC968AC2C; Wed, 10 Apr 2019 20:55:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8200E68AC1E for ; Wed, 10 Apr 2019 20:54:57 +0300 (EEST) Received: by mail-qk1-f175.google.com with SMTP id k130so1790585qke.3 for ; Wed, 10 Apr 2019 10:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=MOljF1miFCJhma3+3wClm+6nYrJ9ZN7Jr8PAyV5+II0=; b=Oxgj2gYgmTSIDbLZnKAcn3Q3iVFZEe7Wte9UWUssQkZddAp/1kEB5ca2osFxJUghKF aBjwMhEQ3pMNFQfRntniwvzL3XbQgHbXqxrm3srPSOt+MWN0Ah7hrvS7BtlwXikNd0cs r9F53ptAhzNxPwZ8MmLewWUF0LJpnnwsSPCq6nDVNKXRN3sRMzg4uYOD3WNtDJXFwoSC U6o3V1l9AVLfYbWdSRQwnhV1VcgaNJmj3kinKTjubsMDCryV+kSQ1kMzBG7/ps5Q3JSc 91Jeoz7UiYV/u4CYjCRaKBu5Lt7JwBmHJeyRl+GRkHA7YgLYLLbtjTd0ewRVtmqALPf9 vkew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MOljF1miFCJhma3+3wClm+6nYrJ9ZN7Jr8PAyV5+II0=; b=YhINDoLJAQo7bgzyihLQMDX0jHV4tbsdu27WjKQ5PQ4EeHo4ZVDasHoY2U4+knt0wm rUi6x/03etSytLSK80PXQGJ/zcDcV+aNwjrskqhmyFLcu7zCOdgF95jOInAZROzc92iK CKjxGtkG3MiLSmkAl87SujCqYzGtXXpOy8igTVG4mrmuMHbv+4LyD8MFu8ypv3yLDw4O vAJtqwXGDDu/gRClIYxzcTjH8iCAr0VGpq0zf+JiOWyhZsaawXRgbYtmQTdHx/nGrt/Q QJEvgEBOMG2A6/jGIeeBLf9cSpwzUXpGlUq1vxNpHBIkiMz3KoFqSVT1dVhjFPFO9Zd6 94YQ== X-Gm-Message-State: APjAAAW8796Y6xMy8G/JJpeDARnkt/FU9tklCZQ2qyfigwj/v+ZgogHZ nPdj7nVSOCO5iO52bTplV2jK4f7u X-Google-Smtp-Source: APXvYqwzUEugnhjh8QryH3SVG7sJYTBPxiHy9gVqhNwGRGt6uQcui5lyu+wGVsZLNB12AKp0lA0G0w== X-Received: by 2002:a05:620a:15b5:: with SMTP id f21mr35573554qkk.89.1554918895948; Wed, 10 Apr 2019 10:54:55 -0700 (PDT) Received: from localhost.localdomain ([181.23.83.131]) by smtp.gmail.com with ESMTPSA id v4sm18839597qtq.94.2019.04.10.10.54.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 10:54:55 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Apr 2019 14:54:45 -0300 Message-Id: <20190410175445.68-1-jamrial@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190410082419.GW3501@michaelspb> References: <20190410082419.GW3501@michaelspb> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2 v2] avcodec/h264: error out on ff_h264_pred_weight_table() only if strict spec compliance is requested X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes ticket #7174. Signed-off-by: James Almer --- Now using avpriv_request_sample() libavcodec/h264_parse.c | 15 +++++++++------ libavcodec/h264_slice.c | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) 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; }