From patchwork Tue Jul 14 20:19:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21015 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 1C3F844A518 for ; Tue, 14 Jul 2020 23:20:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD73568A616; Tue, 14 Jul 2020 23:20:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E4406882F0 for ; Tue, 14 Jul 2020 23:20:05 +0300 (EEST) Received: by mail-wm1-f47.google.com with SMTP id 17so196561wmo.1 for ; Tue, 14 Jul 2020 13:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MlB6GNz0Rmb88i+2ZPKT9fYiFw2tFn8R3GwjjEVOXrk=; b=Be30jjpr8MDS8LlIMAWI37QoEaaKiJmyEg4oVzYxC1+EdquqqZEVXPLKprbtAuQVcT /RHcwDFI8RPhFdHRN62mbXKv++kdHqoUAxoj2M5R+u4DYrwy9QvINru+92PHomg/vCIR Qu4UEjr7sbvAFkgkSI4UVivqsOH2P8Y6PbgLdeKuhd4eWEXNRd8jCtI7tCNffZaGpFRf rO8UrLV3zWywgJb8rQdOp9dnrEhrkJpRLvR4+G4bU6qtGx1GTXr1bmuLoW3BH9MlzUJd 2zbT+w7R4fPNv4vUrpCJ7UDBLhSP1HvVAxptdsp5JXJ5V8EmeSkdXH8QvPjy/RVBEbRg Va7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MlB6GNz0Rmb88i+2ZPKT9fYiFw2tFn8R3GwjjEVOXrk=; b=BiGtPilHIeND+SLGVtSKGIuTFbfWuYQxQovgPyQRU0fAMvdhqtitSTDtyTWs0E7Etw gjFI6PaGgCpRvaOInNuZPARBA+zH7qnBGmt2dfT5tCjxbHUw7FeSjdh3u+HI4udreEI5 Dssdfrx9WNPURVSoqPVp7SZShfLWhb1Vl6FJotVMfR69ClgfYs50KN2LV5Lpf7VHjuc4 G/tTWUKf0g5Thuaa51qn/wW1LqF8cX14EF/Udb7n5iJP87mR+uW+gtn1nLBSSCzVnErJ h5deaxp+FAxWnO0Cn3IQqQim3wLo1rOPy9ckfnQpU6VBHS7wPUY5HaXsUTY3vZ1xxfyX rlaw== X-Gm-Message-State: AOAM531nWJ0+DFtV1rzbYBEKAKXiqZflMVMwdBw298J1thBJEt7eAHTJ 99lr2poQ/CUpQNApl1jCoNs4rDfM X-Google-Smtp-Source: ABdhPJyXf9Maw5zNfnSgU+msYMDCSMGT/b8GzJ24FMJGvBzgAzILQgix0BDbAJo+xPii02BXV9DKEg== X-Received: by 2002:a1c:1f09:: with SMTP id f9mr5667335wmf.137.1594758003871; Tue, 14 Jul 2020 13:20:03 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id j15sm29462355wrx.69.2020.07.14.13.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 13:20:03 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 22:19:49 +0200 Message-Id: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/6] avcodec/golomb: Don't emit error message in get_ue_golomb 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 Cc: James Almer , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Said error message is not very informative and lacked a proper logging context; furthermore, many callers already provided more descriptive error messages of their own. So just drop this one. Suggested-by: James Almer Signed-off-by: Andreas Rheinhardt --- libavcodec/golomb.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index 7fd46a91bd..1f988d74aa 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -87,10 +87,8 @@ static inline int get_ue_golomb(GetBitContext *gb) int log = 2 * av_log2(buf) - 31; LAST_SKIP_BITS(re, gb, 32 - log); CLOSE_READER(re, gb); - if (log < 7) { - av_log(NULL, AV_LOG_ERROR, "Invalid UE golomb code\n"); + if (log < 7) return AVERROR_INVALIDDATA; - } buf >>= log; buf--; From patchwork Tue Jul 14 20:19:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21016 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 276C744A518 for ; Tue, 14 Jul 2020 23:20:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 110EF68A964; Tue, 14 Jul 2020 23:20:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4103A6897CE for ; Tue, 14 Jul 2020 23:20:28 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id z15so23918wrl.8 for ; Tue, 14 Jul 2020 13:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K4/ln68oOaS1QILrwUv38c92ttSa9wTCJFeMnxOUN5Y=; b=QIKU7YhZ5xx8W3vFsUsiGbE2ydzB6MfSMteyLMraylOMIEsfSynvRZhz6pCJfBnIim o4OmkBXXOWShy43UniwBYOAvrb48qp3FfrAj2IWjZSrqomQE6PSxRfXIBHeW+7PnzicU hB5QviHD2CEWKNH1AxxP/mtgWEXuTGB0nuWR6K0tZo7aRlqW9weBCfug/cX8cOOXAwdG /lDrrVVY+C7qNKE7I7HI4sqaHko6eR632C/FGFhqIqXgjF9IdG6pFLKG11eqwB2g4yBX EBRjGt3kV7Rb5AKHvpco+5DUvxkLxs18z2MdPHTdCkzbxYdgrqifs58qnyhy9o6ihzCh lAOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K4/ln68oOaS1QILrwUv38c92ttSa9wTCJFeMnxOUN5Y=; b=OWQMFWwK7AhGiakFLQfkkLfbUCMNGFrokKa/LaOnZSVjwv6+1amKltmsixQ1JBPvzV Ik3aubmuf1j8txJn79WEhg8q8Cfoidzvvp/mm5tKpw0baqa9T0G1GE3xbQQm51aCo+I9 A9U/WQEvfkuJ/6yq4P3KRrPivR0qVsHBV886YOR42ucTVpTzmePLpWMfaPxeg6tuUvGk UWDbKk2vQM7HeGV4imsGSj79B7MkGagAIy7e4UbPqBVY1t1CgakfCbyHMTtPSXCyMei3 WwqLUyNUFuSvyXwrn9kgsEU+1bTU9B/3+MxfbIuObrFxwYYxNsM3J1ERuwD8T8G2eT7L KkCA== X-Gm-Message-State: AOAM530eD+NMA+S/+Vg8A39Cr4DC8s4S43x0PcNN2pkoC1yxMdoptxZc jeX3aoc+1VV+f5Ac6DBCyZVurjJc X-Google-Smtp-Source: ABdhPJw2KFAvYHfryUk88zUF0HX5aCPoJ/5gQTH3o1wxQRLgUgAoAqJMNtjO/Wch7DAv/oS5gpPBzA== X-Received: by 2002:a5d:69cf:: with SMTP id s15mr7950027wrw.10.1594758027260; Tue, 14 Jul 2020 13:20:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id j15sm29462355wrx.69.2020.07.14.13.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 13:20:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 22:19:50 +0200 Message-Id: <20200714201954.30327-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> References: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/6] avcodec/golomb: Prevent shift by negative number 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This happened in get_ue_golomb() if the cached bitstream reader was in use, because there was no check to handle the case of the read value not being in the supported range. Signed-off-by: Andreas Rheinhardt --- libavcodec/golomb.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index 1f988d74aa..a53486d7cf 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -66,6 +66,8 @@ static inline int get_ue_golomb(GetBitContext *gb) return ff_ue_golomb_vlc_code[buf]; } else { int log = 2 * av_log2(buf) - 31; + if (log < 0) + return AVERROR_INVALIDDATA; buf >>= log; buf--; skip_bits_long(gb, 32 - log); From patchwork Tue Jul 14 20:19:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21017 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 DBAB144A518 for ; Tue, 14 Jul 2020 23:20:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C928468A370; Tue, 14 Jul 2020 23:20:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9699168AD86 for ; Tue, 14 Jul 2020 23:20:29 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id j4so24531566wrp.10 for ; Tue, 14 Jul 2020 13:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9BRaJoc7aYZ0fAvZa8kBaUyUfnWUm87HtjkJmq9EEGQ=; b=LTCgXckKv/lMnEovBQUmZFybTnIocuAJccHpCCJYTp/gd59p5MEd/Lhr271B7w/f2u jRZja+R5dhxJ01wQSWeUhNaPHQY31KrLTB3bwTRFMVWFTLUtxiEOslT5ebXcrJpc0Q6y /7U3gYIw3pCdA4vHKFfQyDZKGZnGa2isRWadx2m8rDYwmq8gfncGxslfyzxkQrvuy1jF F4j/VGNsAL8Rclapn3mpKAe1SeAEC2mFwWdCqJ8kV+iL5jhyT16ydZl3jrrzwyvUJso0 sI0JGfeoFII42965uyixC5gs0BGe5aB57RBTwcGnoLCHXelYCqfN8kWhiPXyOTXZ3s6P +haQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9BRaJoc7aYZ0fAvZa8kBaUyUfnWUm87HtjkJmq9EEGQ=; b=eipRwFRrhNWPqC82oy9PTwtWD+TsdyQbHa91mlRGQmcWX5IcxZFGp/R0VJwA6mu2AG 5FBCBXgy05KPomf0wnbNlL3r05sGvUFO1cGbrVAMg0IA/OwmlACG0eeJPIU85Ee8gB/w f6Tx0Hbd/2oSuPy1V5KfLu8EdfgtIYXKBm/GVyAXBu2F7qo1wwX24IG/62K+P/HMcNPx qQv1Dl3cC89bJvuJlZk+965PpESv1Thu9Ro11igZsNYPxf/JTL/aakaHGkOrbWHET1zA EqMuSLf38ymqefvo/wtSgx209CSRytfWSLb7L4BlcbE7YYFvyQJ27qqTXrKh3Z67PVAx 9krA== X-Gm-Message-State: AOAM5306/odnQxB3cjfePH1L1n3eESZ6i9rTwD8Nn807iY1vu1bjkgg3 6tETE2PoF8xM88lNRO2pE2G4DcJ+ X-Google-Smtp-Source: ABdhPJyAoMzuH1uiVYEd1+ctaQjfopDsl7IgA7+U5ClYpyw/UyhxQmheQni4DcHaYvJEesn48to75A== X-Received: by 2002:adf:e850:: with SMTP id d16mr7946773wrn.426.1594758028445; Tue, 14 Jul 2020 13:20:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id j15sm29462355wrx.69.2020.07.14.13.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 13:20:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 22:19:51 +0200 Message-Id: <20200714201954.30327-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> References: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/6] avcodec/golomb, h264*: Fix get_ue_golomb_31() 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" get_ue_golomb_31() uses a LUT of 512 entries; therefore it can be used to parse exp-golomb codes of length <= 9, i.e. those codes with at most four leading bits that have five effective bits; this implies a range of 0..30 and not 31. In particular, this function must not be used to parse e.g. the H.264 SPS id. This commit renames the function to get_ue_golomb_30() and uses it whereever possible. In places where it is not possible, it has been replaced by get_ue_golomb2(). Given that the returned value of said function can be a negative error code, it is no longer included in av_log() statements (the parsed value can actually also be wrong when using get_ue_golomb30()). Signed-off-by: Andreas Rheinhardt --- libavcodec/golomb.h | 6 +++--- libavcodec/h264_cavlc.c | 14 +++++++------- libavcodec/h264_parser.c | 8 ++++---- libavcodec/h264_ps.c | 18 +++++++++--------- libavcodec/h264_refs.c | 6 +++--- libavcodec/h264_sei.c | 4 ++-- libavcodec/h264_slice.c | 6 +++--- libavformat/mxfenc.c | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index a53486d7cf..775ac9878d 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -114,10 +114,10 @@ static inline unsigned get_ue_golomb_long(GetBitContext *gb) } /** - * read unsigned exp golomb code, constraint to a max of 31. - * the return value is undefined if the stored value exceeds 31. + * Read unsigned exp golomb code, constraint to a max of 30. + * the return value is undefined if the stored value exceeds 30. */ -static inline int get_ue_golomb_31(GetBitContext *gb) +static inline int get_ue_golomb_30(GetBitContext *gb) { unsigned int buf; diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index 6481992e58..48f0f0689d 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -838,7 +838,7 @@ decode_intra_mb: } if(decode_chroma){ pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available, - sl->left_samples_available, get_ue_golomb_31(&sl->gb), 1); + sl->left_samples_available, get_ue_golomb_30(&sl->gb), 1); if(pred_mode < 0) return -1; sl->chroma_pred_mode = pred_mode; @@ -850,7 +850,7 @@ decode_intra_mb: if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { for(i=0; i<4; i++){ - sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb); + sl->sub_mb_type[i] = get_ue_golomb_30(&sl->gb); if(sl->sub_mb_type[i] >=13){ av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y); return -1; @@ -868,7 +868,7 @@ decode_intra_mb: }else{ av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ? for(i=0; i<4; i++){ - sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb); + sl->sub_mb_type[i] = get_ue_golomb_30(&sl->gb); if(sl->sub_mb_type[i] >=4){ av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y); return -1; @@ -889,7 +889,7 @@ decode_intra_mb: }else if(ref_count == 2){ tmp= get_bits1(&sl->gb)^1; }else{ - tmp= get_ue_golomb_31(&sl->gb); + tmp = get_ue_golomb(&sl->gb); if(tmp>=ref_count){ av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); return -1; @@ -965,7 +965,7 @@ decode_intra_mb: } else if (rc == 2) { val= get_bits1(&sl->gb)^1; }else{ - val= get_ue_golomb_31(&sl->gb); + val = get_ue_golomb(&sl->gb); if (val >= rc) { av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; @@ -996,7 +996,7 @@ decode_intra_mb: } else if (rc == 2) { val= get_bits1(&sl->gb)^1; }else{ - val= get_ue_golomb_31(&sl->gb); + val = get_ue_golomb(&sl->gb); if (val >= rc) { av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; @@ -1034,7 +1034,7 @@ decode_intra_mb: } else if (rc == 2) { val= get_bits1(&sl->gb)^1; }else{ - val= get_ue_golomb_31(&sl->gb); + val = get_ue_golomb(&sl->gb); if (val >= rc) { av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index aacd44cf3b..d0269497d5 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -180,7 +180,7 @@ static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb, if (get_bits1(gb)) { int index; for (index = 0; ; index++) { - unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(gb); + unsigned reordering_of_pic_nums_idc = get_ue_golomb_30(gb); if (reordering_of_pic_nums_idc < 3) get_ue_golomb_long(gb); @@ -210,7 +210,7 @@ static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb, if (get_bits1(gb)) { // adaptive_ref_pic_marking_mode_flag int i; for (i = 0; i < MAX_MMCO_COUNT; i++) { - MMCOOpcode opcode = get_ue_golomb_31(gb); + MMCOOpcode opcode = get_ue_golomb_30(gb); if (opcode > (unsigned) MMCO_LONG) { av_log(logctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", @@ -226,7 +226,7 @@ static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb, get_ue_golomb_long(gb); // difference_of_pic_nums_minus1 if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED || opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) - get_ue_golomb_31(gb); + get_ue_golomb(gb); } } @@ -342,7 +342,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, /* fall through */ case H264_NAL_SLICE: get_ue_golomb_long(&nal.gb); // skip first_mb_in_slice - slice_type = get_ue_golomb_31(&nal.gb); + slice_type = get_ue_golomb_30(&nal.gb); s->pict_type = ff_h264_golomb_to_pict_type[slice_type % 5]; if (p->sei.recovery_point.recovery_frame_cnt >= 0) { /* key frame, since recovery_frame_cnt is set */ diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index e774929e21..c1a79bde53 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -108,10 +108,10 @@ static inline int decode_hrd_parameters(GetBitContext *gb, void *logctx, SPS *sps) { int cpb_count, i; - cpb_count = get_ue_golomb_31(gb) + 1; + cpb_count = get_ue_golomb(gb); - if (cpb_count > 32U) { - av_log(logctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); + if (cpb_count++ > 31U) { + av_log(logctx, AV_LOG_ERROR, "cpb_count invalid\n"); return AVERROR_INVALIDDATA; } @@ -361,10 +361,10 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, constraint_set_flags |= get_bits1(gb) << 5; // constraint_set5_flag skip_bits(gb, 2); // reserved_zero_2bits level_idc = get_bits(gb, 8); - sps_id = get_ue_golomb_31(gb); + sps_id = get_ue_golomb(gb); if (sps_id >= MAX_SPS_COUNT) { - av_log(avctx, AV_LOG_ERROR, "sps_id %u out of range\n", sps_id); + av_log(avctx, AV_LOG_ERROR, "sps_id out of range\n"); goto fail; } @@ -391,7 +391,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps->profile_idc == 128 || // Multiview High profile (MVC) sps->profile_idc == 138 || // Multiview Depth High profile (MVCD) sps->profile_idc == 144) { // old High444 profile - sps->chroma_format_idc = get_ue_golomb_31(gb); + sps->chroma_format_idc = get_ue_golomb_30(gb); if (sps->chroma_format_idc > 3U) { avpriv_request_sample(avctx, "chroma_format_idc %u", sps->chroma_format_idc); @@ -438,7 +438,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, } sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4; - sps->poc_type = get_ue_golomb_31(gb); + sps->poc_type = get_ue_golomb_30(gb); if (sps->poc_type == 0) { // FIXME #define unsigned t = get_ue_golomb(gb); @@ -482,7 +482,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, goto fail; } - sps->ref_frame_count = get_ue_golomb_31(gb); + sps->ref_frame_count = get_ue_golomb_30(gb); if (avctx->codec_tag == MKTAG('S', 'M', 'V', '2')) sps->ref_frame_count = FFMAX(2, sps->ref_frame_count); if (sps->ref_frame_count > MAX_DELAYED_PIC_COUNT) { @@ -781,7 +781,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct } memcpy(pps->data, gb->buffer, pps->data_size); - pps->sps_id = get_ue_golomb_31(gb); + pps->sps_id = get_ue_golomb(gb); if ((unsigned)pps->sps_id >= MAX_SPS_COUNT || !ps->sps_list[pps->sps_id]) { av_log(avctx, AV_LOG_ERROR, "sps_id %u out of range\n", pps->sps_id); diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index dae8bd278a..3cba2646e7 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -432,7 +432,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) continue; for (index = 0; ; index++) { - unsigned int op = get_ue_golomb_31(&sl->gb); + unsigned int op = get_ue_golomb_30(&sl->gb); if (op == 3) break; @@ -850,7 +850,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, sl->explicit_ref_marking = get_bits1(gb); if (sl->explicit_ref_marking) { for (i = 0; i < MAX_MMCO_COUNT; i++) { - MMCOOpcode opcode = get_ue_golomb_31(gb); + MMCOOpcode opcode = get_ue_golomb_30(gb); mmco[i].opcode = opcode; if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG) { @@ -860,7 +860,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, } if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED || opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) { - unsigned int long_arg = get_ue_golomb_31(gb); + unsigned int long_arg = get_ue_golomb(gb); if (long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG && long_arg == 16) && diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 7b8e6bd7ba..70d8f284ee 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -320,10 +320,10 @@ static int decode_buffering_period(H264SEIBufferingPeriod *h, GetBitContext *gb, int sched_sel_idx; const SPS *sps; - sps_id = get_ue_golomb_31(gb); + sps_id = get_ue_golomb(gb); if (sps_id > 31 || !ps->sps_list[sps_id]) { av_log(logctx, AV_LOG_ERROR, - "non-existing SPS %d referenced in buffering period\n", sps_id); + "non-existing SPS referenced in buffering period\n"); return sps_id > 31 ? AVERROR_INVALIDDATA : AVERROR_PS_NOT_FOUND; } sps = (const SPS*)ps->sps_list[sps_id]->data; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index c7b2764270..8f4b7ef1ec 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1739,7 +1739,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, sl->first_mb_addr = get_ue_golomb_long(&sl->gb); - slice_type = get_ue_golomb_31(&sl->gb); + slice_type = get_ue_golomb_30(&sl->gb); if (slice_type > 9) { av_log(h->avctx, AV_LOG_ERROR, "slice type %d too large at %d\n", @@ -1874,7 +1874,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, } if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) { - tmp = get_ue_golomb_31(&sl->gb); + tmp = get_ue_golomb_30(&sl->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); return AVERROR_INVALIDDATA; @@ -1902,7 +1902,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, sl->slice_alpha_c0_offset = 0; sl->slice_beta_offset = 0; if (pps->deblocking_filter_parameters_present) { - tmp = get_ue_golomb_31(&sl->gb); + tmp = get_ue_golomb_30(&sl->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 5a3a609bf6..c7ceb40b55 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2223,7 +2223,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, case H264_NAL_SLICE: init_get_bits8(&gb, buf, buf_end - buf); get_ue_golomb_long(&gb); // skip first_mb_in_slice - slice_type = get_ue_golomb_31(&gb); + slice_type = get_ue_golomb_30(&gb); switch (slice_type % 5) { case 0: e->flags |= 0x20; // P Picture From patchwork Tue Jul 14 20:19:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21018 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 872BC44A518 for ; Tue, 14 Jul 2020 23:20:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7311168AF09; Tue, 14 Jul 2020 23:20:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D0BDB68AA4D for ; Tue, 14 Jul 2020 23:20:30 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id z15so24090wrl.8 for ; Tue, 14 Jul 2020 13:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l7NnZ/n35kwcgQbe7d6atG43HnzoPRKNYVdn0aFLZ2A=; b=PUDfidJ54KN0mc21x0P+Txsl/fsSyGsqwyP5BYlgXairzExNmjx+QpGFfhYr1hl5mb 7oqVy3eHINL6ZtINlPw/vogOkeN0O2pnH99AwipcMn1DOw56Z88w/wYJPe5NRUwxMfXx V8xXShI36ckFWcy/bG1J8B1aYQwLNwsg1vRkMZUxAyCBTFu++AFLKORuRpnVcCJau7J+ LwFCVu2CtxFeC4jsvOTr1vjTqCj5JN50tBiw51W2qOZC4/PvSy1UrZ65OWw6VueD8Nv4 aDN0kwa3y4xwcoywDq1PYWOZ/c4f+6JON/TJlgK0IB22gqjytnfi2pG0NS9nSYgcanlk t+uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l7NnZ/n35kwcgQbe7d6atG43HnzoPRKNYVdn0aFLZ2A=; b=ot5X+M6kvYbQRGu5hcH7qEmICtssQHLl6mHHHDufSMWqw/qKk9P2iLsKYU8Z/Eiaym ln+D3YPD3/yY2zmXLHvttHIJ9nRu78ieZ5AL6d4ANvEYFJtm/eD21OS85f3s2TfKk7DF lVJRpN7W7YZNOHpcwDvW28J4VzK4zMAAfaVvMJsVUWCI74yd+kxo55CRN7AxfG7+0kcI 3uv8x5BQ9sjPfq9hcsWOUvXMb8s6szeBO17yBOEn74G3YPHMRl3eUq+My+f5Jpr5gqUi xQf2QCmvhyA96ToW8zXQtZUYaOO1EKqsUiWWn3gceokb03T39BCWNsuAZtn/chaO1EC3 OeiQ== X-Gm-Message-State: AOAM53010iX+1ac9Lje3ZK2M3CNV3PmkatFUtDspux3Mxj3IM8c7b1hS /EAP1a/I8XI+pCsvBWW3RZqim27S X-Google-Smtp-Source: ABdhPJyle2sGxDO3Xf5IDmI62eQksiSgHSLmQjsyYdmnP3LHdrtEHDJIERTtZt7KIzAYhoVkdFkV8w== X-Received: by 2002:adf:9404:: with SMTP id 4mr7551197wrq.367.1594758029984; Tue, 14 Jul 2020 13:20:29 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id j15sm29462355wrx.69.2020.07.14.13.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 13:20:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 22:19:52 +0200 Message-Id: <20200714201954.30327-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> References: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/6] avcodec/golomb: Document return value of get_ue_golomb_30 on error 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If the return value is undefined if the value of the encountered exp golomb code was outside the 0..30 range, said function can't be used anywhere where one wants to check for correctness. So document that in this case the return value is outside the range 0..30 (it currently always returns 32 in this case). Signed-off-by: Andreas Rheinhardt --- libavcodec/golomb.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index 775ac9878d..356df2cd92 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -115,7 +115,8 @@ static inline unsigned get_ue_golomb_long(GetBitContext *gb) /** * Read unsigned exp golomb code, constraint to a max of 30. - * the return value is undefined if the stored value exceeds 30. + * The return value is outside 0..30 if no exp golomb code + * in that range was encountered. */ static inline int get_ue_golomb_30(GetBitContext *gb) { From patchwork Tue Jul 14 20:19:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21019 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 563D844A518 for ; Tue, 14 Jul 2020 23:20:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3ECB868AFA5; Tue, 14 Jul 2020 23:20:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72FFD68AE9A for ; Tue, 14 Jul 2020 23:20:32 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id s10so24479866wrw.12 for ; Tue, 14 Jul 2020 13:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qu/7iX6aHDrEMusTjEo9CWB+90gE4znEsXrcYjijVA0=; b=KH7zwtzZfheUTlpql7F10xnh3Fyq7v/NJd69Lc7pSnAcjS/Kdu8LlrkfnRiMCb9ccW aLAQ+vmkuVaoMad/ZYkgtSH8eAGcsUxTWr+8HN/rWT7NQr11Lag9aTpchsUYh8GdWE3t PsK7OzKT3jI4h27PNeEhALD8ULZ0w4y0eUi6trSivabmxKhOD6K8zMxQaF+iIppf7ZF5 h7FA3GQpobMhOyPmPDlaBL11+Ex2LCrXoM2sTowtm7f2dqL1BIhLv6DeDXr4WRW1H/Ni Apg4ylKHm9MzLSUhcUWzyzVg9r/hLAPk211qSn42eAQDdhIK+L0C2eYHF0vLPbltk7xn QChg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qu/7iX6aHDrEMusTjEo9CWB+90gE4znEsXrcYjijVA0=; b=tASQtWUmULt+lK4V8jYeBLEAHOrm3uYp1Yv+GvlvHWTPt258rL+NvGa9BTfuGpws9t E00gpx00nL6rQyi1RYTiqKLxfLucI/Qtog9UB8b+resWnYAyXzCcBGVIns4gA1Slw6Hz yNM4gN07cZITlFQH1H2e/uhYZyoGvUMDFCgmaq7xfagX16EXSRhyIi/EirodjzuVnAaL 3mISv3HLNcurA5gyHTk9ERlMariMg8v1XzeUJwc59xH8IVlQUEV3uXIwkdENSEIH1IL2 R0Zq1iGmnG8eZfhPF8N9oiMy6gMe9PGDn2L/HstweqENIXgm9A3yXcZk8II1/FJKCVFA 91+Q== X-Gm-Message-State: AOAM533iLIqBK8X718Z6U3uqsTHedmzjgyq3Khi3s6hdKD8C2UUIoh7p uRGdCL1Rdmxm6O8vzXMvqmgIEqIp X-Google-Smtp-Source: ABdhPJy+6JaR5a7LOFNq7HTNRyaDOct+JhyvClp4NO9zZ02jzRLjBnPeqbX5zYyUBDv4wu96lBzGcw== X-Received: by 2002:adf:fa81:: with SMTP id h1mr7873960wrr.266.1594758031428; Tue, 14 Jul 2020 13:20:31 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id j15sm29462355wrx.69.2020.07.14.13.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 13:20:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 22:19:53 +0200 Message-Id: <20200714201954.30327-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> References: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/6] avcodec/cavsdec, h264*, hevc_parser: Use get_ue_golomb_30 where possible 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" instead of get_ue_golomb(). The difference between the two is that the latter also has to take into account the case in which the read code is more than 9 bits (four preceding zeroes + at most five value bits) long. Signed-off-by: Andreas Rheinhardt --- libavcodec/cavsdec.c | 2 +- libavcodec/h264_parse.c | 4 ++-- libavcodec/h264_ps.c | 22 +++++++++++----------- libavcodec/hevc_parser.c | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index aaed807196..3d4b9cdeff 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -676,7 +676,7 @@ static int decode_mb_i(AVSContext *h, int cbp_code) } h->pred_mode_Y[pos] = predpred; } - pred_mode_uv = get_ue_golomb(gb); + pred_mode_uv = get_ue_golomb_30(gb); if (pred_mode_uv > 6) { av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n"); return AVERROR_INVALIDDATA; diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index 352ffea948..53e644da66 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -35,7 +35,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, pwt->use_weight = 0; pwt->use_weight_chroma = 0; - pwt->luma_log2_weight_denom = get_ue_golomb(gb); + pwt->luma_log2_weight_denom = get_ue_golomb_30(gb); 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; @@ -43,7 +43,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, luma_def = 1 << pwt->luma_log2_weight_denom; if (sps->chroma_format_idc) { - pwt->chroma_log2_weight_denom = get_ue_golomb(gb); + pwt->chroma_log2_weight_denom = get_ue_golomb_30(gb); 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; diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index c1a79bde53..57ee74ec32 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -181,8 +181,8 @@ static inline int decode_vui_parameters(GetBitContext *gb, void *logctx, /* chroma_location_info_present_flag */ if (get_bits1(gb)) { /* chroma_sample_location_type_top_field */ - sps->chroma_location = get_ue_golomb(gb) + 1; - get_ue_golomb(gb); /* chroma_sample_location_type_bottom_field */ + sps->chroma_location = get_ue_golomb_30(gb) + 1; + get_ue_golomb_30(gb); /* chroma_sample_location_type_bottom_field */ } else sps->chroma_location = AVCHROMA_LOC_LEFT; @@ -224,11 +224,11 @@ static inline int decode_vui_parameters(GetBitContext *gb, void *logctx, sps->bitstream_restriction_flag = get_bits1(gb); if (sps->bitstream_restriction_flag) { get_bits1(gb); /* motion_vectors_over_pic_boundaries_flag */ - get_ue_golomb(gb); /* max_bytes_per_pic_denom */ - get_ue_golomb(gb); /* max_bits_per_mb_denom */ - get_ue_golomb(gb); /* log2_max_mv_length_horizontal */ - get_ue_golomb(gb); /* log2_max_mv_length_vertical */ - sps->num_reorder_frames = get_ue_golomb(gb); + get_ue_golomb_30(gb); /* max_bytes_per_pic_denom */ + get_ue_golomb_30(gb); /* max_bits_per_mb_denom */ + get_ue_golomb_30(gb); /* log2_max_mv_length_horizontal */ + get_ue_golomb_30(gb); /* log2_max_mv_length_vertical */ + sps->num_reorder_frames = get_ue_golomb_30(gb); get_ue_golomb(gb); /*max_dec_frame_buffering*/ if (get_bits_left(gb) < 0) { @@ -403,8 +403,8 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, goto fail; } } - sps->bit_depth_luma = get_ue_golomb(gb) + 8; - sps->bit_depth_chroma = get_ue_golomb(gb) + 8; + sps->bit_depth_luma = get_ue_golomb_30(gb) + 8; + sps->bit_depth_chroma = get_ue_golomb_30(gb) + 8; if (sps->bit_depth_chroma != sps->bit_depth_luma) { avpriv_request_sample(avctx, "Different chroma and luma bit depth"); @@ -428,7 +428,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps->bit_depth_chroma = 8; } - log2_max_frame_num_minus4 = get_ue_golomb(gb); + log2_max_frame_num_minus4 = get_ue_golomb_30(gb); if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 || log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) { av_log(avctx, AV_LOG_ERROR, @@ -441,7 +441,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps->poc_type = get_ue_golomb_30(gb); if (sps->poc_type == 0) { // FIXME #define - unsigned t = get_ue_golomb(gb); + unsigned t = get_ue_golomb_30(gb); if (t>12) { av_log(avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); goto fail; diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 5af4b788d5..3ec490bd34 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -136,7 +136,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] - slice_type = get_ue_golomb(gb); + slice_type = get_ue_golomb_30(gb); if (!(slice_type == HEVC_SLICE_I || slice_type == HEVC_SLICE_P || slice_type == HEVC_SLICE_B)) { av_log(avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", From patchwork Tue Jul 14 20:19:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21020 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 1575344A518 for ; Tue, 14 Jul 2020 23:20:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F067068AF9D; Tue, 14 Jul 2020 23:20:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EDF6068AEEB for ; Tue, 14 Jul 2020 23:20:33 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id q15so198086wmj.2 for ; Tue, 14 Jul 2020 13:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UkkjiaidesvIEy6meLLbvGVMh8hc1GH42LofMS8WDic=; b=sNqFhsE2eiySDNH7zNUcVP6RdvWNMPRCvL2txhzQb4OTHBJ1JNPlL4MCo84xZ3P3La tI8Cb2CpPXPyxyKvi1iafOrQ9YIOx98qhUpoctn3c4FPYHme2FIyFhSTR9420k3pctiX BGzGdu7EhaaRJvt2GofQKb85l/Uf+OlHh/1J4LB/AEFhTz1Q2ali3NI1FOc9L9QCwFTq fiukifDg8egPVvugr1lqqNMrfOZnuIGoiO7oUAaqs3phCdOJKu6nnfgtdovvXbmxHgYq IQ+y84NUMWuotfEzKu5HQ50AGP0HyYK4nA5YLv44K6CIT0P4R1jtaIiXu7GA7QytWaLy YBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UkkjiaidesvIEy6meLLbvGVMh8hc1GH42LofMS8WDic=; b=JU5AD8/rtaSqmyB9nfSiwBiJLtfnXuVnshL0iRCdF7z6O1NRseJqYXz7FNu/sBtYBl JiQi+ZZmF9gz0pohMSpt7V1l6NmrkopbgzDYREzsiPQVjNdl9Z5z+Lb6cNHptuRSkBmb Yu9Psq4fVn2qgQvqbw74J5Csiwq1GCQ9LPnjUSj43050yOswcuvrQle8Jk4j3jzu21+w vtj9yFKd/vWS8rFVWUNrLzWfYaZzgDBXBKQYcU9VSW75IHhBQwWst7wDKRrauMdUEBgk q2jMjWdd/L4kWmS4MarS81TwdBXR2ZDHfqNOAWEEgo7sqpxBjop9uA2oih70XstKUFyo mSDg== X-Gm-Message-State: AOAM531HrksV4v9HUe1PvgpO/l+ZEbI/BP98hyrZBTTBi1oDcue9PlgC rSYRNLy/b8R6+7borDeS55ClEvbm X-Google-Smtp-Source: ABdhPJxBG7hya5Zp/NSE/xlVIZHYZocYzlbtPXpLd34RmAhnz5vuft8eb+vidYz/yg2gZ3AOHhpK3Q== X-Received: by 2002:a7b:cbc1:: with SMTP id n1mr5529148wmi.18.1594758032712; Tue, 14 Jul 2020 13:20:32 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id j15sm29462355wrx.69.2020.07.14.13.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 13:20:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 22:19:54 +0200 Message-Id: <20200714201954.30327-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> References: <20200714201954.30327-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 6/6] avcodec/h264*: Omit potentially wrong values from log messages 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" get_ue_golomb_30() and get_ue_golomb() (as well as get_ue_golomb2()) can only parse values within a certain range correctly; if the parsed value is not within said range, the latter two functions return AVERROR_INVALIDDATA, while the former returns something outside of said range (currently 32 for a 0-30 range). So the return values are good enough to determine whether an exp golomb code in the desired range has been encountered, but they are not necessarily correct. Therefore they should not be used in error messages stating that a certain value (the return value of these functions) is out-of-range; instead just state the correct range and that the parsed value is not in said range. Signed-off-by: Andreas Rheinhardt --- Is it actually intentional that the SPS.offset_for_ref_frame array has 256 entries, although the specs only allow 255 elements in an SPS? libavcodec/cavsdec.c | 2 +- libavcodec/h264_cavlc.c | 14 +++++++------- libavcodec/h264_parse.c | 4 ++-- libavcodec/h264_parser.c | 2 +- libavcodec/h264_ps.c | 26 ++++++++++++++------------ libavcodec/h264_slice.c | 2 +- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 3d4b9cdeff..2857646438 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -615,7 +615,7 @@ static inline int decode_residual_inter(AVSContext *h) /* get coded block pattern */ int cbp = get_ue_golomb(&h->gb); if (cbp > 63U) { - av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp); + av_log(h->avctx, AV_LOG_ERROR, "Inter cbp not in 0-63 range\n"); return AVERROR_INVALIDDATA; } h->cbp = cbp_tab[cbp][1]; diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index 48f0f0689d..af1a3b1370 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -762,7 +762,7 @@ int ff_h264_decode_mb_cavlc(const H264Context *h, H264SliceContext *sl) mb_type--; decode_intra_mb: if(mb_type > 25){ - av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "mb_type in %c slice too large at %d %d\n", av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y); return -1; } partition_count=0; @@ -891,7 +891,7 @@ decode_intra_mb: }else{ tmp = get_ue_golomb(&sl->gb); if(tmp>=ref_count){ - av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); + av_log(h->avctx, AV_LOG_ERROR, "ref overflow\n"); return -1; } } @@ -967,7 +967,7 @@ decode_intra_mb: }else{ val = get_ue_golomb(&sl->gb); if (val >= rc) { - av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref overflow\n"); return -1; } } @@ -998,7 +998,7 @@ decode_intra_mb: }else{ val = get_ue_golomb(&sl->gb); if (val >= rc) { - av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref overflow\n"); return -1; } } @@ -1036,7 +1036,7 @@ decode_intra_mb: }else{ val = get_ue_golomb(&sl->gb); if (val >= rc) { - av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref overflow\n"); return -1; } } @@ -1071,7 +1071,7 @@ decode_intra_mb: if(decode_chroma){ if(cbp > 47){ - av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cbp >%d at %d %d\n", 47, sl->mb_x, sl->mb_y); return -1; } if (IS_INTRA4x4(mb_type)) @@ -1080,7 +1080,7 @@ decode_intra_mb: cbp = ff_h264_golomb_to_inter_cbp[cbp]; }else{ if(cbp > 15){ - av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cbp >%d at %d %d\n", 15, sl->mb_x, sl->mb_y); return -1; } if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index 53e644da66..fd9b824756 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -37,7 +37,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, pwt->luma_log2_weight_denom = get_ue_golomb_30(gb); 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); + av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom not in 0-7 range\n"); pwt->luma_log2_weight_denom = 0; } luma_def = 1 << pwt->luma_log2_weight_denom; @@ -45,7 +45,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, if (sps->chroma_format_idc) { pwt->chroma_log2_weight_denom = get_ue_golomb_30(gb); 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); + av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom not in 0-7 range\n"); pwt->chroma_log2_weight_denom = 0; } chroma_def = 1 << pwt->chroma_log2_weight_denom; diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index d0269497d5..3dfd1127a1 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -351,7 +351,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, pps_id = get_ue_golomb(&nal.gb); if (pps_id >= MAX_PPS_COUNT) { av_log(avctx, AV_LOG_ERROR, - "pps_id %u out of range\n", pps_id); + "pps_id not in 0-255 range\n"); goto fail; } if (!p->ps.pps_list[pps_id]) { diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index 57ee74ec32..b1285255aa 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -412,8 +412,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, } if (sps->bit_depth_luma < 8 || sps->bit_depth_luma > 14 || sps->bit_depth_chroma < 8 || sps->bit_depth_chroma > 14) { - av_log(avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n", - sps->bit_depth_luma, sps->bit_depth_chroma); + av_log(avctx, AV_LOG_ERROR, "bit depth value outside of 8-14 range\n"); goto fail; } sps->transform_bypass = get_bits1(gb); @@ -443,7 +442,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, if (sps->poc_type == 0) { // FIXME #define unsigned t = get_ue_golomb_30(gb); if (t>12) { - av_log(avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); + av_log(avctx, AV_LOG_ERROR, "log2_max_poc_lsb not in 0-12 range\n"); goto fail; } sps->log2_max_poc_lsb = t + 4; @@ -465,7 +464,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, if ((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)) { av_log(avctx, AV_LOG_ERROR, - "poc_cycle_length overflow %d\n", sps->poc_cycle_length); + "num_ref_frames_in_pic_order_cnt_cycle not in 0-255 range\n"); goto fail; } @@ -478,7 +477,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, } } } else if (sps->poc_type != 2) { - av_log(avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); + av_log(avctx, AV_LOG_ERROR, "illegal POC type\n"); goto fail; } @@ -487,7 +486,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps->ref_frame_count = FFMAX(2, sps->ref_frame_count); if (sps->ref_frame_count > MAX_DELAYED_PIC_COUNT) { av_log(avctx, AV_LOG_ERROR, - "too many reference frames %d\n", sps->ref_frame_count); + "too many reference frames\n"); goto fail; } sps->gaps_in_frame_num_allowed_flag = get_bits1(gb); @@ -758,7 +757,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct int ret; if (pps_id >= MAX_PPS_COUNT) { - av_log(avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id); + av_log(avctx, AV_LOG_ERROR, "pps_id not in 0-255 range\n"); return AVERROR_INVALIDDATA; } @@ -782,9 +781,13 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct memcpy(pps->data, gb->buffer, pps->data_size); pps->sps_id = get_ue_golomb(gb); - if ((unsigned)pps->sps_id >= MAX_SPS_COUNT || - !ps->sps_list[pps->sps_id]) { - av_log(avctx, AV_LOG_ERROR, "sps_id %u out of range\n", pps->sps_id); + if ((unsigned)pps->sps_id >= MAX_SPS_COUNT) { + av_log(avctx, AV_LOG_ERROR, "sps_id not in 0-31 range\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } + if (!ps->sps_list[pps->sps_id]) { + av_log(avctx, AV_LOG_ERROR, "unavailable SPS (id %d) referenced\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto fail; } @@ -798,8 +801,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct if (sps->bit_depth_luma > 14) { av_log(avctx, AV_LOG_ERROR, - "Invalid luma bit depth=%d\n", - sps->bit_depth_luma); + "Invalid luma bit depth > 14\n"); ret = AVERROR_INVALIDDATA; goto fail; } else if (sps->bit_depth_luma == 11 || sps->bit_depth_luma == 13) { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 8f4b7ef1ec..29b57bc305 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1764,7 +1764,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, sl->pps_id = get_ue_golomb(&sl->gb); if (sl->pps_id >= MAX_PPS_COUNT) { - av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id); + av_log(h->avctx, AV_LOG_ERROR, "pps_id not in 0-255 range\n"); return AVERROR_INVALIDDATA; } if (!h->ps.pps_list[sl->pps_id]) {