From patchwork Sat Feb 17 03:20:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 7618 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp1432361jai; Fri, 16 Feb 2018 19:21:31 -0800 (PST) X-Google-Smtp-Source: AH8x22562RnVM2nkk3IDD9kwLSKeRwhHmCVHAJsGrFcIc6iyR38xUCzochEFoQ9G5nfPWvt+3/BE X-Received: by 10.223.128.227 with SMTP id 90mr7820881wrl.50.1518837690977; Fri, 16 Feb 2018 19:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518837690; cv=none; d=google.com; s=arc-20160816; b=KugxSAXJC3Fkq3kJ8pzQtGSPI6oixIQ/nMzl/hRjtHJJ8h9oAbgPmgzlnWWk+F0Jdy cWZhCr2xmUv02dQVLXB9AbxsDs3KrNWOxpKVdlor39FjktA6nYyTOyPyGZ3DgUWmB1lq omvc5s3XgEIiAQzit08BrAcgWOHOJa5HwiAJwmjUhOdsjPn29/PDZDqC0J6PvgMHJzQR sY8dMGBnNneXaPB8dqZHRm5hU/ZwM/p03uwe/pyd2AXHqOVFsapKvcdM2FQ2Rw2SqR7Q MYCoWta8T0Gkd9BST7XT5SkjXK8otP3LTYu1jNnIfKjO8kd/LLNFTgj5+anDNryM4L1O UW4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=/g9Pvgdsn7Vjeo4sdSTX+zjog7RMsn77k/zbyaDE8DA=; b=ncblkTvY/Kdr08FgupaBNCfzVc4KMgGElCVzYBlorz8ssGyCyEcO2i4dJD4lJs9Hq5 fgmkbqWCji4vhkbBY3CK7ICNHRcyOE+Ha6zl/85+zpRapKb0K6yZNBfjn4YXsnK9fRRV PYR3ooRG9fjIv5hyCqfe2PuQckD938yP9LekHTQkIeOTPvFm25k5hMAHFcaC+e+lYCSs iLaEPgThgHRFQvqRlUaE8JPeHbV1UmWcT75h94iiS7i5/ZHUfuK6wnsjBn7LM1zLtPrx mflD1+nn28tH3BMZPv6L+j4Ke/f1rM+EG6vKV6XYkg3wWNhWT3dl1NgCI+bJ8IOZnFd1 F6Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i76si11087581wmc.94.2018.02.16.19.21.30; Fri, 16 Feb 2018 19:21:30 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2FB4868A1FA; Sat, 17 Feb 2018 05:21:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe07-3.mx.upcmail.net (vie01a-dmta-pe07-3.mx.upcmail.net [84.116.36.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1EF0A68A188 for ; Sat, 17 Feb 2018 05:20:54 +0200 (EET) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1emt3i-0006vp-5c for ffmpeg-devel@ffmpeg.org; Sat, 17 Feb 2018 04:21:06 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id BfLx1x0040S5wYM01fLy3p; Sat, 17 Feb 2018 04:20:58 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 17 Feb 2018 04:20:54 +0100 Message-Id: <20180217032054.21778-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180217032054.21778-1-michael@niedermayer.cc> References: <20180217032054.21778-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/h264: Increase field_poc to 64bit in ff_h264_init_poc() to detect overflows 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: Integer overflow Fixes: 5746/clusterfuzz-testcase-minimized-6270097623613440 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/h264_parse.c | 6 +++++- libavcodec/h264_parser.c | 4 +++- libavcodec/h264_slice.c | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index fee28d90d9..6cbef5a13d 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -271,7 +271,7 @@ int ff_h264_init_poc(int pic_field_poc[2], int *pic_poc, int picture_structure, int nal_ref_idc) { const int max_frame_num = 1 << sps->log2_max_frame_num; - int field_poc[2]; + int64_t field_poc[2]; pc->frame_num_offset = pc->prev_frame_num_offset; if (pc->frame_num < pc->prev_frame_num) @@ -337,6 +337,10 @@ int ff_h264_init_poc(int pic_field_poc[2], int *pic_poc, field_poc[1] = poc; } + if ( field_poc[0] != (int)field_poc[0] + || field_poc[1] != (int)field_poc[1]) + return AVERROR_INVALIDDATA; + if (picture_structure != PICT_BOTTOM_FIELD) pic_field_poc[0] = field_poc[0]; if (picture_structure != PICT_TOP_FIELD) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 65d9d44b50..1a9840a62c 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -449,8 +449,10 @@ static inline int parse_nal_units(AVCodecParserContext *s, /* Decode POC of this picture. * The prev_ values needed for decoding POC of the next picture are not set here. */ field_poc[0] = field_poc[1] = INT_MAX; - ff_h264_init_poc(field_poc, &s->output_picture_number, sps, + ret = ff_h264_init_poc(field_poc, &s->output_picture_number, sps, &p->poc, p->picture_structure, nal.ref_idc); + if (ret < 0) + goto fail; /* Continue parsing to check if MMCO_RESET is present. * FIXME: MMCO_RESET could appear in non-first slice. diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index e6b7998834..90e05ed8f1 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1607,8 +1607,10 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); } - ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc, + ret = ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc, h->ps.sps, &h->poc, h->picture_structure, nal->ref_idc); + if (ret < 0) + return ret; memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco)); h->nb_mmco = sl->nb_mmco;