From patchwork Sun Apr 21 14:04:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 12858 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 5A34D447BE2 for ; Sun, 21 Apr 2019 17:13:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3EF9F68A770; Sun, 21 Apr 2019 17:13:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 00FFC68A0C1 for ; Sun, 21 Apr 2019 17:13:24 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id z11so11696301wmi.0 for ; Sun, 21 Apr 2019 07:13:24 -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=RSPsB86dL4drn3yxhhxUO6DvJ9xDlvqHRSnLbkeEzGg=; b=LNKCjk/amDTgbnDx8YaAtopg+AWzfNIIlTCkJkZtxglHSgBnlBrGloUYnxF9YJHT00 n11jmgNDgJui03lKkSgts67eWvjQSAI34BKzEFxjYtK2Tth9fp9BU+H9cFMm9Gqpy7Ok 7p06JZ2KWw/C8HC1vzJfVozIccKYbcTe4SprCvm6PSQmvX9bmCGIXjEV1t7X9T3hrdgx Qzo6IyYLuggVK7dMpvHTKqUpSjol58cOJfMLsp6LLSygjXRl6g+m6UasnsuPDVn5IcKb JLdn4lnDow8xI7PjKy14cfXHBuCwM2dq3Sbo0l/9q0d4qUKH3kGGPynQF+vYcYnN/Qg0 txlA== 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=RSPsB86dL4drn3yxhhxUO6DvJ9xDlvqHRSnLbkeEzGg=; b=rIjU/L9vi3yIufggWUfdIjkJLHopFy1ThhGPcy9z8Bp06zKWbJIrcqOFysJNzQ/MTf tiOoGiaKNUewiPZ7pGW56RYvieMBf5WZXcET/fX1wFdTutj1oL0OGzHXnwgVToVBzsRq s0wdoJyd70+U0kvJF74i7jT2/sVORi/OBG3wWhdtYOVew5DMqJWp+e8siVMx8obdunIU NA1wGFuTOSKW8RCxwPJA2l9O52e8ldCayH/q0Yk6S3tTTxSMsmX6zpu7aS1GOK7dVDJV MvwmnN3gGQDXz0ZuOm75H8c+SMUsqTliYPXlVOHvIBAZTdEpEva9/l68VVIY3U2Kg2nk vJkQ== X-Gm-Message-State: APjAAAUkyXQK3XyGHHHCnrckLmllPCPk8q8TrAiNDdU/R2YzuY2F6JJR VLjcCcWxhLUA9Cs0aJSDXWTHPMa7 X-Google-Smtp-Source: APXvYqx6Hu9868zSWOpTGJDg3tdn6pvXVJZi1nleFOLI0F22a24I8UrPo7JcA4CPdoo1Lr7cbhrn7Q== X-Received: by 2002:a05:600c:2189:: with SMTP id e9mr8922391wme.4.1555855515715; Sun, 21 Apr 2019 07:05:15 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.gmail.com with ESMTPSA id q24sm8175066wmj.26.2019.04.21.07.05.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Apr 2019 07:05:15 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Apr 2019 16:04:02 +0200 Message-Id: <20190421140404.17418-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190421140404.17418-1-andreas.rheinhardt@gmail.com> References: <20190421140404.17418-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 --- libavcodec/cbs_mpeg2.c | 17 ++++++++++------- libavcodec/cbs_mpeg2_syntax_template.c | 10 +++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 41f16bbabf..066ea83970 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -42,19 +42,22 @@ #define ui(width, name) \ xui(width, name, current->name, 0) +#define uir(width, name, range_min, range_max) \ + xuir(width, name, current->name, range_min, range_max, 0) #define uis(width, name, subs, ...) \ xui(width, name, current->name, subs, __VA_ARGS__) - +#define xui(width, name, var, subs, ...) \ + xuir(width, name, var, 0, (1 << width) - 1, subs, __VA_ARGS__) #define READ #define READWRITE read #define RWContext GetBitContext -#define xui(width, name, var, subs, ...) do { \ +#define xuir(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) @@ -72,7 +75,7 @@ #undef READ #undef READWRITE #undef RWContext -#undef xui +#undef xuir #undef marker_bit #undef nextbits @@ -81,10 +84,10 @@ #define READWRITE write #define RWContext PutBitContext -#define xui(width, name, var, subs, ...) do { \ +#define xuir(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 { \ @@ -98,7 +101,7 @@ #undef READ #undef READWRITE #undef RWContext -#undef xui +#undef xuir #undef marker_bit #undef nextbits diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index 10aaea7734..745a123649 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; @@ -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);