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) {