From patchwork Tue Apr 23 20:32:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 12877 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 7F58E447629 for ; Tue, 23 Apr 2019 23:36:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 631AF6883B3; Tue, 23 Apr 2019 23:36:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5424680328 for ; Tue, 23 Apr 2019 23:36:03 +0300 (EEST) Received: by mail-wm1-f54.google.com with SMTP id y197so1766052wmd.0 for ; Tue, 23 Apr 2019 13:36:03 -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=7KwUMHZ0JdvayQoOf+vMSNxW6Hft7XZI6IaXMuuRsYQ=; b=ujal1sDqF2MQ74SkX8cFjX0016/NSLF8szA+zTowAyRbivNA/f7zzUvv7cy8XrWHN5 dWDtrQLxr28hBrPkNRF0fNCIjBk5ZCE8VDxNbymIiUrOm99OulZdQ/pFyHFeFxqHzEsC aPG3klQMsBMQZIevRSSYPO0OVzoLi0+zob0jd8AXlTxjT4EqpdsuxWkiTgiXl0b8PxZI J7UNlNiqlx1WsG/xilNQZ4wLVcHr1IzhnpDDIEbcJHoP+LfKYfIMhPCyMRO/364SKNFH eK+SxMJGYPDx6+BgM1r+xue/JKzqpmFLh0TbbN2DtIKc0MczW6ruptUobkaUrKm7pIbi eUVA== 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=7KwUMHZ0JdvayQoOf+vMSNxW6Hft7XZI6IaXMuuRsYQ=; b=ZGrMlnrpePLnuQ9Ai0LYTTn8xBBRcBkxLLwkm6c4CtMCDV4tevM1lLj4JyVd+Lfftr hS0DwkQ0njOVtA61lWmRHzrDG/Y7ZzJhmJZ6j0Z7gyaBT469FRoOH/Sx5D6adtpKwMh9 wYy5Gr7rPfsl6Q/BUtU86o1oQ96AMIvKu1GYTIMHm9eH9Xp6KnT9kkW6rNgaRtsLbtDA VmjSq/snGfDSgMKDtM7NK6qFL5UFZqif11yMtNrSDf5esvvXlWs1qbh/YP8Sivk1QLfb KEY+WjfuryQ0C3jJr7ojKMdouvlbU3GJS2b4FvIPVwU0/mg+/z0JqCLsuJY8y/DCatta pMVQ== X-Gm-Message-State: APjAAAWx1tKzIiafrqUGF6887TVXhyXy0ptChfGxMG2WqIE5Z7YbeY3V AvJ/6VmNwdggK0dJJTpa/JZlJaXN X-Google-Smtp-Source: APXvYqy5uoLBL6Kr49WtA+GBptuNjNh9ZpccYSMwsVC63A7xxehk1ga9hlilQbEGCCswV/0tna3OtQ== X-Received: by 2002:a1c:7d42:: with SMTP id y63mr3847809wmc.113.1556051762851; Tue, 23 Apr 2019 13:36:02 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.gmail.com with ESMTPSA id b8sm11193133wrf.21.2019.04.23.13.36.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 13:36:02 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Apr 2019 22:32:28 +0200 Message-Id: <20190423203230.4742-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423203230.4742-1-andreas.rheinhardt@gmail.com> References: <20190421140404.17418-1-andreas.rheinhardt@gmail.com> <20190423203230.4742-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] cbs_mpeg2: Improve checks for invalid values 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" horizontal/vertical_size_value (containing the twelve least significant bits of the frame size) mustn't be zero according to the specifications; and the value 0 is forbidden for the colour_description elements. Signed-off-by: Andreas Rheinhardt --- Given that xui is directly used in the syntax template, I had the options a) to add xuir (as I did in my earlier attempt), b) to change xui to accept ranges and change the syntax template (add the ranges equaling "no custom range") or c) change xui and add a new macro for what xui currently does. I opted for c). The new macro is named xuib, b in analogy to your proposal for cbs_h2645. Unfortunately, the naming of ui is inconsistent with this, but changing this would basically touch every line in the syntax template. libavcodec/cbs_mpeg2.c | 17 ++++++++++------- libavcodec/cbs_mpeg2_syntax_template.c | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index cdde68ea38..4025812531 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -41,20 +41,23 @@ #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) #define ui(width, name) \ - xui(width, name, current->name, 0) + xuib(width, name, current->name, 0) +#define uir(width, name, range_min, range_max) \ + xui(width, name, current->name, range_min, range_max, 0) #define uis(width, name, subs, ...) \ - xui(width, name, current->name, subs, __VA_ARGS__) - + xuib(width, name, current->name, subs, __VA_ARGS__) +#define xuib(width, name, var, subs, ...) \ + xui(width, name, var, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) #define READ #define READWRITE read #define RWContext GetBitContext -#define xui(width, name, var, subs, ...) do { \ +#define xui(width, name, var, range_min, range_max, subs, ...) do { \ uint32_t value = 0; \ CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \ SUBSCRIPTS(subs, __VA_ARGS__), \ - &value, 0, (1 << width) - 1)); \ + &value, range_min, range_max)); \ var = value; \ } while (0) @@ -81,10 +84,10 @@ #define READWRITE write #define RWContext PutBitContext -#define xui(width, name, var, subs, ...) do { \ +#define xui(width, name, var, range_min, range_max, subs, ...) do { \ CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \ SUBSCRIPTS(subs, __VA_ARGS__), \ - var, 0, (1 << width) - 1)); \ + var, range_min, range_max)); \ } while (0) #define marker_bit() do { \ diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index 10aaea7734..73bfeae29e 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -26,8 +26,8 @@ static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw, ui(8, sequence_header_code); - ui(12, horizontal_size_value); - ui(12, vertical_size_value); + uir(12, horizontal_size_value, 1, 4095); + uir(12, vertical_size_value, 1, 4095); mpeg2->horizontal_size = current->horizontal_size_value; mpeg2->vertical_size = current->vertical_size_value; @@ -79,7 +79,7 @@ static int FUNC(user_data)(CodedBitstreamContext *ctx, RWContext *rw, #endif for (k = 0; k < current->user_data_length; k++) - xui(8, user_data, current->user_data[k], 0); + xuib(8, user_data, current->user_data[k], 0); return 0; } @@ -125,9 +125,9 @@ static int FUNC(sequence_display_extension)(CodedBitstreamContext *ctx, RWContex ui(1, colour_description); if (current->colour_description) { - ui(8, colour_primaries); - ui(8, transfer_characteristics); - ui(8, matrix_coefficients); + uir(8, colour_primaries, 1, 255); + uir(8, transfer_characteristics, 1, 255); + uir(8, matrix_coefficients, 1, 255); } ui(14, display_horizontal_size); @@ -366,16 +366,16 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw, if (!current->extra_information) return AVERROR(ENOMEM); for (k = 0; k < current->extra_information_length; k++) { - xui(1, extra_bit_slice, bit, 0); - xui(8, extra_information_slice[k], - current->extra_information[k], 1, k); + xuib(1, extra_bit_slice, bit, 0); + xuib(8, extra_information_slice[k], + current->extra_information[k], 1, k); } } #else for (k = 0; k < current->extra_information_length; k++) { - xui(1, extra_bit_slice, 1, 0); - xui(8, extra_information_slice[k], - current->extra_information[k], 1, k); + xuib(1, extra_bit_slice, 1, 0); + xuib(8, extra_information_slice[k], + current->extra_information[k], 1, k); } #endif }