From patchwork Mon Jul 27 09:08:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21282 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 19E1744AB7E for ; Mon, 27 Jul 2020 12:14:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EAF6C68B7CA; Mon, 27 Jul 2020 12:14:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2AC4F68B7B9 for ; Mon, 27 Jul 2020 12:14:39 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id dk23so4421235ejb.11 for ; Mon, 27 Jul 2020 02:14:39 -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=X5GJOhR+54Scg2HPqJuF48XpOcutqf4ZgVoKH35w2t4=; b=LIZbahbxpwRARpOnlA+tynFJq6n64nnodd7gMx5dMyjpCRUffk0u8kESN6+gfgt8QO yi29ZMnUkua6zSnxxv+RB87TLBIYIzrv7ICtzmr4LndKZf5DXRxvpiTziIiGqWMelEJi 5HGaGfVg50z8SM1PX/6Mx5gguVGXogYW/BLPDDHRWQmYBUKR5PAd65TduqqmvvZCTmOg faJo22whlfCQRaLBwpgf0Zagy5zs4psEl7V5yzop3XPURZ4SpcJ6sNUzXTuL9ASJpLN2 aWYi0j6d+JKORxWysgoeBV9akIwFH3hcL1Q5NTT/k7CVI8S7VyAtYLsSdyEQ5SxzBTjc INMA== 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=X5GJOhR+54Scg2HPqJuF48XpOcutqf4ZgVoKH35w2t4=; b=Zu38HPgKY6UZp1VHJxsXsVMvgoGYIUo8NYxxBRYbCYHUaDfQRISv+LlSOsP9A/6Suk 7ToYTO2PT0Ne87tUw2xsTiOt1S+TikW95MHQv8KtqCA1pzvLSY8Ex4mKdnh0ySr0hZqZ DDVrVZQpf8BJ/ZWvNK/9bsZpNniGlkS/7CrIGGaad9eh7yS+9Oivypoqer+kSCl29TFs WEzZQVygrI3VRQHpYCo5trt8fgNtEkwKJMNak/N5IOscOMg3gT908qpNB9FH4TZhDZry pD5K49wzEvTzh7Ce+8NuSCtQXQKPoOjrBzRZ7pCsVn0O+s+nXKW0HW1hUhPu9zzZLvZn 36Cg== X-Gm-Message-State: AOAM532y1jVNYy++l/A0wfDd8Q/9pNBfqgV5uAd8H141ZI9Hkq+8pbYo li4ICCdvPE83NmZAwRzboeWuXdGB X-Google-Smtp-Source: ABdhPJxSEalVoQ7szfiEYGEPus6Y3gvmUk3zDPq4lRdmFRCkr6jXaucRW76wuLOdDGj77rgObLs75g== X-Received: by 2002:a50:d9cb:: with SMTP id x11mr19562720edj.93.1595840898057; Mon, 27 Jul 2020 02:08:18 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id ck6sm7080961edb.18.2020.07.27.02.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 02:08:17 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 11:08:06 +0200 Message-Id: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/5] 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: 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 --- No change since last time. Will apply this tomorrow unless there are objections. 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 Mon Jul 27 09:08:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21278 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 7E51E44983A for ; Mon, 27 Jul 2020 12:08:26 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5026F68B7BB; Mon, 27 Jul 2020 12:08:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0641A68B4F3 for ; Mon, 27 Jul 2020 12:08:20 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id a21so16250240ejj.10 for ; Mon, 27 Jul 2020 02:08:19 -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=qeFaOdcmYaCasKQKGB6Rnuqth2HyCAE6c7HbmHwH9jQ=; b=B4HSMt4Cnw6St574ZEAx5OeuF5718eUi+vM2WfdbeL4WENuCDfDGDzBpfb+geDy8Rk m15pxmH23ZzD8Ok4nPSGZr43YbV85BA/3CoPKXPY85xW+jLLrwChYHMZ8hlKV728CmOX fecVjYrMg4hdossdMJYY+72bg3rJI9g6x30MIGrGyRYV5ZU/2gk4mJF/GqzuYQRe91Xz A8OzzVEH6fPhhUPANDQndWj0SL7LkTpQ4tEfPWNed9OGWFWHjRGxVEsLWnMlaTaBm87r ibESO51b2JYZZeenah6RvjZY1HE70RdZ/WsmUCX59on6DOVWsU//PrIrY3JCmEtDp70s 6g7A== 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=qeFaOdcmYaCasKQKGB6Rnuqth2HyCAE6c7HbmHwH9jQ=; b=tFT/tb1r0wzhvNQ0LCifFmEHN/IFxPe2kyNxgGdFPfgXibA0WtUdOfe9v596M0qqvM P5NkjBfZDaHDAwuvY5GHURPxtyzSCVT4FtjyKss9CQ8pBFJauDSmsR8OyGXMWan4RC8l R2/7uWE36oWNsdT+sIbTfY3Cbxt5UxZN8WHceLzt7VkK5Eo7oADqGwX1RRAqSpFO9qG2 vs0KA1p0bnn+WKDgmZyaEDywGDuIFW/OmsxOd7tL/A6a/BT63R5a6D1+p8CAbUvhWruv D7jkR3H3whU1HLqCdrZlvWxrToo9TWBQ0JmTVzMd04qElNVdNRoCWXUKuLIqGT3JO0IE S3Ww== X-Gm-Message-State: AOAM533Ypu1Vaqki7M8giesF1dVSJ7/Dap6DD4AWT99yo4SeggYM8zpp kkZzhoVZiWs6WbimQlMBErrJt1Su X-Google-Smtp-Source: ABdhPJycsMbS5qHZVrDaTeJAxpYJg4j09O4al7V4efYa0AjsmPgODX2YFmDvHsRNR/9nMcdDnmjAgQ== X-Received: by 2002:a17:906:950c:: with SMTP id u12mr19532171ejx.37.1595840899056; Mon, 27 Jul 2020 02:08:19 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id ck6sm7080961edb.18.2020.07.27.02.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 02:08:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 11:08:07 +0200 Message-Id: <20200727090810.23794-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> References: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/5] 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. For consistency with the uncached bitstream reader and for compliance with the documentation, every value not in the 0-8190 range is treated as error although the cached bitstream reader could actually read values in the range 0..65534 without problems. Signed-off-by: Andreas Rheinhardt --- v3: Besides accepting the same range as the uncached version this version also consumes bits in case of error like the uncached version. Unfortunately it is not possible to always consume the same number of bits, because the uncached version will consume 63 bits as soon as all valid bits are zero, whereas the cached version will only consume 63 bits if the next 31 bits are zero. libavcodec/golomb.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index 1f988d74aa..aed9b22471 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -66,9 +66,12 @@ static inline int get_ue_golomb(GetBitContext *gb) return ff_ue_golomb_vlc_code[buf]; } else { int log = 2 * av_log2(buf) - 31; + + skip_bits_long(gb, 32 - log); + if (log < 7) + return AVERROR_INVALIDDATA; buf >>= log; buf--; - skip_bits_long(gb, 32 - log); return buf; } From patchwork Mon Jul 27 09:08:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21279 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 B17C344983A for ; Mon, 27 Jul 2020 12:08:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9366268B7BE; Mon, 27 Jul 2020 12:08:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1FF1568A687 for ; Mon, 27 Jul 2020 12:08:21 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id d6so2451208ejr.5 for ; Mon, 27 Jul 2020 02:08:21 -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=sqYSbh/mhVTX409DUcjRUnynrltIEPg8oMFUI8UAw3Y=; b=sNcVyy0DJPSoDsHvEzEuGy0AhJv6fTq7cSfbmzdjCzbwjTklD6xUbxSGBwTOL1qZyg lVZ7wqVJlzpboSyUO9C9UxZYtgGKQbYxDGng4b5Kdx+8fazgCarlTwn4XQY6yBtEu5BE wfdih93n9m/6vrIOpTc980H8G96o/oDwTxIkN8ik9HPxJs0Ra+M1A8arUpi84xbCUeFm nfmh0t9NhFFU90IhifK77EphhuauJjKuSjA5L5hdBUoaem6zBwworuKnQNTywVxb6Oct LIbqvDtpNRaqOZEifx+0MeyDM+SY4zmorKlwDbB98+ZC9WoJrkFNlrMCGKrE0ImwGCWV FuxQ== 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=sqYSbh/mhVTX409DUcjRUnynrltIEPg8oMFUI8UAw3Y=; b=gdinRYcN7LHbOZX0RSz/QoukN/KXarGi9S6C5lbdnGSr9ZiJ/ZHHAFRAT5G8aEDmHP kFeaRHqfe12aLXXX1sDjf+AwfVfk80i1Pg10z/qs/qu9xebludg+IHmpX+8CuIwjSAuU ZAGMfhyCnQ8Ya0WK2YFBx1/9V2ggez9r7VTDjWja+PCSpXqa9olE/XaQnCgwSESmUUlP wMTuSHiadtJ8TSgwztGxcEDTQsxuiN1b404Y4Oub7t4vn4KenCbXQhjPbmcmWGDD4sAs +WcmLX7viL4TkpZC13VrmCxQlsLAyfarwDvRN3/JMv5srbzsVeArkkcAk+14vO2+JdSm 9ogg== X-Gm-Message-State: AOAM533mKTiZJtoFy1VuH60JHvOoXh9gBdC4UXBLIPneTeek2wvzFTUy fnRjfSeXKDZbeRYq62UsMG88lT51 X-Google-Smtp-Source: ABdhPJx/bxmVQGnaxTWIhbVehqxtlkhjI7LKph/8xWBXGOaNC8qWEkkKxBkheSc9SqAZztAldMb96Q== X-Received: by 2002:a17:906:fcdb:: with SMTP id qx27mr4547988ejb.421.1595840900166; Mon, 27 Jul 2020 02:08:20 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id ck6sm7080961edb.18.2020.07.27.02.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 02:08:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 11:08:08 +0200 Message-Id: <20200727090810.23794-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> References: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/5] avcodec/golomb: Document return value of get_ue_golomb_31 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" get_ue_golomb_31() reads nine bits and an array with 512 entries to parse golomb codes. The longest golomb codes that fit into 9 bits use four leading zeroes and five value bits and can encode numbers in the 0..30 range. 31 meanwhile is encoded on 11 bits and if the nine bits read coincide with the first nine bits of the encoding of 31, get_ue_golomb_31() returns 31 (and skips 11 bits). But looking at the first nine bits only makes it impossible to distinguish 31 from 32..34. Therefore the documentation of get_ue_golomb_31() simply states that the return value is undefined if the value of the encountered exp golomb code was outside the 0..31 range. But actually get_ue_golomb_31() does not behave that bad: If the returned value is in the range of 0..30, then this is the actually encountered value, so that this function can be used without any problems to parse and validate parameters whose legal values are a subset of the 0..30 range. This commit documents this fact. 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 aed9b22471..4d531cf805 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -116,7 +116,8 @@ 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. + * If the value encountered is not in 0..31, the return value + * is outside the range 0..30. */ static inline int get_ue_golomb_31(GetBitContext *gb) { From patchwork Mon Jul 27 09:08:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21281 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 BCB7944AA7E for ; Mon, 27 Jul 2020 12:13:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9723B68B7A4; Mon, 27 Jul 2020 12:13:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E5D668B792 for ; Mon, 27 Jul 2020 12:13:42 +0300 (EEST) Received: by mail-ed1-f68.google.com with SMTP id q4so8349830edv.13 for ; Mon, 27 Jul 2020 02:13:42 -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=8MBKoSebQYtGusOHCtkjnt7+AZG7FG9nd+qXvrc8AJU=; b=m6HUQ3A81mwWqL3IMgmGRmrMtKJhCfIYK6mUqAfcQ435a/Z79uR8UyYrwDiwr4B8Fy sFxEhZ5OCBggqMnUI/yXaA1vjQficAXx8UzM3rNx87UL12CENawJTOVej8L7ArCco/Ww D0b/PBAqGtLhhEPSRnpu+dpfHaDRg5cIDOoquC10M27ubCXHHaHzN81dfWGAFCSTVrd5 36fwcbqEETNvsJbmTyIgDFoE65L+4HTyyjzOY6ewsxvS+vEyzzMctvc7ZZjHXuj3fVX9 aYbe9pxTewa7qIKJFEIHAotunGzW5cFFZCK+/O+LTRBFVtaucodfuj2y1tZmAuL0XCOx mGiQ== 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=8MBKoSebQYtGusOHCtkjnt7+AZG7FG9nd+qXvrc8AJU=; b=o0UFiLoghH9MdWT8+QYMMDpHoBEUNvQH641QwpYz6clLSavWFa3AlOQAOZS6fRYHpL 2+JJ0EiSMcvzg6NUyixAYD/xFcJyXDgbwd3J8kGBtY5shgH+eqc/vDjw3/n2+7cRCDqs kl/RdMPpqawnQsMNXYn2+AObhX8Qze4D0gJfh+SIF9w/CQWbEkceM8LWqI22y8qMPXvL 2//Q1/RoCgfqFS3xgC1XRqzPmyaNwXo03+X+tyCk8Pkfxk18XnzbhU5pN2TJaMMFbkiZ jOfPba9X12m20l2K94lMbLzxxdQ1F+4nGEHo5Vr7ZEsXMWSup7iLHoFd2KcXNqnFpvHt kQUg== X-Gm-Message-State: AOAM531H0YrTw2uqLNSYwMCZOtgyGdFuHw77fQQ0XK/s3c/xt9XddU3f Qgzx5rkHfwFaod1st3xWqEmoI8Tt X-Google-Smtp-Source: ABdhPJwnQXqgTBjb1oqn552ylAlFdD+X8ViyVwH2Sxwjj1PIo+b8JeoN0M40/PdL/r26QhV271AjBw== X-Received: by 2002:a50:cfc6:: with SMTP id i6mr4461927edk.88.1595840901207; Mon, 27 Jul 2020 02:08:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id ck6sm7080961edb.18.2020.07.27.02.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 02:08:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 11:08:09 +0200 Message-Id: <20200727090810.23794-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> References: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 4/5] avcodec/cavsdec, h264*, hevc_parser: Use get_ue_golomb_31 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, leading to more code. Signed-off-by: Andreas Rheinhardt --- libavcodec/cavsdec.c | 2 +- libavcodec/h264_parse.c | 4 ++-- libavcodec/h264_ps.c | 24 ++++++++++++------------ libavcodec/hevc_parser.c | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index aaed807196..9c3825df38 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_31(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..1c1d1c04b0 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_31(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_31(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 e774929e21..e21c2b56ac 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_31(gb) + 1; + get_ue_golomb_31(gb); /* chroma_sample_location_type_bottom_field */ } else sps->chroma_location = AVCHROMA_LOC_LEFT; @@ -224,12 +224,12 @@ 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(gb); /*max_dec_frame_buffering*/ + get_ue_golomb_31(gb); /* max_bytes_per_pic_denom */ + get_ue_golomb_31(gb); /* max_bits_per_mb_denom */ + get_ue_golomb_31(gb); /* log2_max_mv_length_horizontal */ + get_ue_golomb_31(gb); /* log2_max_mv_length_vertical */ + sps->num_reorder_frames = get_ue_golomb_31(gb); + get_ue_golomb_31(gb); /*max_dec_frame_buffering*/ if (get_bits_left(gb) < 0) { sps->num_reorder_frames = 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_31(gb) + 8; + sps->bit_depth_chroma = get_ue_golomb_31(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_31(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_31(gb); if (sps->poc_type == 0) { // FIXME #define - unsigned t = get_ue_golomb(gb); + unsigned t = get_ue_golomb_31(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..463d352055 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_31(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 Mon Jul 27 09:08:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21280 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 0FE7F44983A for ; Mon, 27 Jul 2020 12:08:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F043868B792; Mon, 27 Jul 2020 12:08:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7ED3368B7AB for ; Mon, 27 Jul 2020 12:08:23 +0300 (EEST) Received: by mail-ej1-f46.google.com with SMTP id dk23so4403593ejb.11 for ; Mon, 27 Jul 2020 02:08:23 -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=Zp3OJXlg4oKMAmFqeVcA44tNshHX3A9+YYi5xaxhgGA=; b=VYAg1dogX8u/S4hIaaNFFwHz4SeV4oJY9nf4xn/GpVgTGJKLVdAuwXYy3oc+Xr5s2L XmKXau9LxE+oifmKkQzs5nXBueY1xmA2g5i/jPnnscIpv3CwLI21Id2/hVTEuqIxduUR 5qmhm+Qi9TtnR/QT3+dIiwW8muOXIWgcjdkvKKhS1ExNYegxzc5lORoqFF7zuCD8oJYS T4qlEZ0iZuIBC7yudu2szXzJ3waMm9xCVS9X+tTYrqcEnjgmaCJ7DgNROAxAq05GkKFR Cd98HBd0Bs5AHJwY04YPIRNRdWbtVU2apE/UBiIMCEOtD7uihNsn+wH9F0DdB5a9x0AQ 61LA== 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=Zp3OJXlg4oKMAmFqeVcA44tNshHX3A9+YYi5xaxhgGA=; b=rSq563pG+RTlU8N1PNDgBiOjz07bFFBTaE/t3pAeWCggzSJDTw6etiGWdmXWckwCoD llLf24cTBdgnOn1MiyYAYWtUSlS5lDRO+Qs0ptZLvzlyiSeJzNWuoJlnsJjR9S9P601m BIGPlNFDPU/QNt4ETqybNP7MUSj7sF6lRLkLDRtDa9Fxh5WCOoggCn2RxYwLfCx7XmuQ 8ZbeQgWGbb3mP+6GHUzEihL6LUBoIr+zWGhTpChmhGKyclj5oh0casBFENQYNc88P+qW e+YspuJpvU+4UveDLm/UlCDnVZz76Ok91q7RJJQvYyppbgrSMwJ3aWlMNAlhwHLKfCeI M9EA== X-Gm-Message-State: AOAM533gf0wGICrE/jzasqhkkLLotG+7m8SKuVO1pqUcNAufXlW9jMHD jjD5UnNE7KACKhXMwztAghA9gIdr X-Google-Smtp-Source: ABdhPJw+KPTBo+Aewr5fftg/kspgXhj78mq0IGwlScwacVNLv7oeqIMhLBN8gerszt9G7INVOX7Edg== X-Received: by 2002:a17:906:6852:: with SMTP id a18mr19683900ejs.348.1595840902364; Mon, 27 Jul 2020 02:08:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id ck6sm7080961edb.18.2020.07.27.02.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 02:08:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 11:08:10 +0200 Message-Id: <20200727090810.23794-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> References: <20200727090810.23794-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 5/5] 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_31() and get_ue_golomb() can only parse values within a certain range correctly; if the parsed value is not within said range, the latter function returns AVERROR_INVALIDDATA, while the former returns something different from the encountered value. 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 --- libavcodec/cavsdec.c | 2 +- libavcodec/h264_cavlc.c | 14 +++++++------- libavcodec/h264_parse.c | 4 ++-- libavcodec/h264_parser.c | 2 +- libavcodec/h264_ps.c | 28 +++++++++++++++------------- libavcodec/h264_sei.c | 2 +- libavcodec/h264_slice.c | 2 +- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 9c3825df38..6b5ad587ca 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 6481992e58..137329479c 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_31(&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_31(&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_31(&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_31(&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 1c1d1c04b0..660a922621 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_31(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_31(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 aacd44cf3b..5be7d55081 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 e21c2b56ac..0a500feb82 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -364,7 +364,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps_id = get_ue_golomb_31(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 not in 0-31 range\n"); goto fail; } @@ -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_31(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_31(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_sei.c b/libavcodec/h264_sei.c index 7b8e6bd7ba..3aad7cf9a7 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -323,7 +323,7 @@ static int decode_buffering_period(H264SEIBufferingPeriod *h, GetBitContext *gb, sps_id = get_ue_golomb_31(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..515a796af0 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]) {