From patchwork Tue Apr 23 22:55:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 12881 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 8FBFB447E89 for ; Wed, 24 Apr 2019 01:56:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 70645689AFF; Wed, 24 Apr 2019 01:56:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8ABC4689AFF for ; Wed, 24 Apr 2019 01:56:00 +0300 (EEST) Received: by mail-wm1-f49.google.com with SMTP id j13so2075344wmh.2 for ; Tue, 23 Apr 2019 15:56:00 -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=XU8U5So7jPlD1WnVxLNn8qwkAIoBAseD0vyJStd6riM=; b=hUTSpa/bIBEqmbjcaMmf7wD3suOl0OVUIFeGD1G3PoltspKPUc8HdF4JDuZZS4+f6+ kDzWCzQhv9ukTpgU97A4W0H1l65EEnPhJzDT1fbbeFRVKeaVzYBDSflfrXgnFwb3tDjh Ej5PS53vV93T1hKG3zDig1LNHOhjBnYm14q14ypKIFfNFMiPaVHUMxW0FMxh8H2fgph2 ib0sl0//EDJ7FtS+Mx7aRReZABi67+9TR78s3EIznB/HMtGFvS4DqIg3d8FVmW65VlOO mbhj5Jr3ZwlRGpE2i01Lt95IKbw2W2eQ7ymnVfNYEnvTDZJukIINCd4ErDhp5h73RPN7 1wDg== 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=XU8U5So7jPlD1WnVxLNn8qwkAIoBAseD0vyJStd6riM=; b=ERT2jZYjY4ir1V4DfBBspueVO3Tw2B5jty7XOS2IyEOPjy+aqyXvDF90vF05OXNywM mGO7h+K5QQpOSwfkagOfVSAUpxcvFxIuMYIgB91NeE4EEIR2/gdCzHx4tGTCGb6I+AtW cPyGgZQXEDs33+/sjZUI8dN1KMq5E4uuJHF7aH84ypFHAxwLMvXO9NgrbOCTxSQ6KkM6 Q04Yax/i5pzISjG4X2bbrsxjMrZNiYjPEM8AVplZIbzF3TGbHuXtO3OF5qP6DWiwCdVM 6tiAblGfzvwg5Rznyc3YdZ1H3SaEhjLoUAu3aH5CAc0P4SqwwqerFvlLu4meJxFlPVSU 1rxA== X-Gm-Message-State: APjAAAXALGEL7Mr2TnoNv0y+U4AORJExc8sGo4o21N791lJsAT+aX2qq 1qiLaMSFliDZdwJ2v04KDH5L5QmV X-Google-Smtp-Source: APXvYqzRDNkjslT0ZfP1zgpRhuOBzc0bDBZJJiHDVRG+J2xbR2Uk0OMqieU95Uj3FQJ74ERTkMBwgQ== X-Received: by 2002:a1c:6502:: with SMTP id z2mr3861675wmb.119.1556060159748; Tue, 23 Apr 2019 15:55:59 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.gmail.com with ESMTPSA id q24sm13666648wmj.26.2019.04.23.15.55.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 15:55:58 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Apr 2019 00:55:15 +0200 Message-Id: <20190423225515.54955-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <33b3a319-4c11-1279-4197-7ae7be2cf9f3@gmail.com> References: <33b3a319-4c11-1279-4197-7ae7be2cf9f3@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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 --- The actual function calls after macro expansion are the same as in the earlier versions with the exception of the extra_bit_slice calls. libavcodec/cbs_mpeg2.c | 14 ++++++++------ libavcodec/cbs_mpeg2_syntax_template.c | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index cdde68ea38..fc21745a51 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -41,20 +41,22 @@ #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) #define ui(width, name) \ - xui(width, name, current->name, 0) + xui(width, name, current->name, 0, MAX_UINT_BITS(width), 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__) + xui(width, name, current->name, 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 +83,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..27dcaad316 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); + xui(8, user_data, current->user_data[k], 0, 255, 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(1, extra_bit_slice, bit, 1, 1, 0); xui(8, extra_information_slice[k], - current->extra_information[k], 1, k); + current->extra_information[k], 0, 255, 1, k); } } #else for (k = 0; k < current->extra_information_length; k++) { - xui(1, extra_bit_slice, 1, 0); + xui(1, extra_bit_slice, 1, 1, 1, 0); xui(8, extra_information_slice[k], - current->extra_information[k], 1, k); + current->extra_information[k], 0, 255, 1, k); } #endif }