From patchwork Fri Apr 29 22:18:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 35519 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp546914pzb; Fri, 29 Apr 2022 15:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXMvShnFC5GTSTsQPOr+4T3fYI7jBIwQTe6CS8kGJI+dw2FYROpF1jvG9jrB0lNzbE/bVh X-Received: by 2002:a05:6402:1813:b0:425:adb9:4abd with SMTP id g19-20020a056402181300b00425adb94abdmr1480952edy.278.1651270741420; Fri, 29 Apr 2022 15:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651270741; cv=none; d=google.com; s=arc-20160816; b=wMUKUjRrwwsklX3biQxbQqi2n8lJ7HKMYXyy1CuwJibszISLT6sUSfNkeky6gp+mX7 ynHH1FE0TQl1/EHZN0w21vpjhjqf4JKwPhgtcsgTyB0XoMsscggiTr6SiI2/SuYVSQSA 89Yu3ywhcd9J8gKsnU3wF93bLadrmzPMJs7qY7o3o9ZhySb4frgy9DDFnETW4lN5V6uZ lIZZpw6MmI1kh4rbIR0pC7GDhrvxEAYd2BrJlEUpyyp2nyeD6RX8Q2Rmq1loInV7c00o otx4LqeRtFbcIQKphyn14TkISB49tat/YbJOXVFiRHFa7/UEic0VEZ0oRabvsR+RaI1k PFhw== 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; bh=cHIqogyZlVQiEZq/ANWXKk51jCsZohBqe2iMPOXUSec=; b=NABY5AQmK8zgm938RZJJyjKaAHgC+XDdo8XhWMLqlyUTejW2sPhmchYTXz3NDNm+It J5U8cDYqyhC9EdBVduGkOxqGJxJUcSYUTPn94hNccx0SsHy71Rq9eyEWorSw+GnI9bn/ vr5s/bRfpToXQM3sALpulh7Z8gsfsQgJfHQa7ygFR8KUMlFwz7tOhV/YAAejObQ68ur5 wdJAF31h375ED5UL3OkKSIiEGrqi9dQLHOd1eFSnTmlgef8RhrOiDCnYYz3MDldIQg/T /iRdP3sGy/pk9pmsu0fIGC77D7v/pt4Wc+0s7KVnEKbDYZQj2FPnvQ9b/OKUnD/pan3v 3f8A== 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 h18-20020a1709067cd200b006df76385cdesi7033655ejp.382.2022.04.29.15.19.00; Fri, 29 Apr 2022 15:19:01 -0700 (PDT) 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 E5CF468B2BE; Sat, 30 Apr 2022 01:18:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at03-1.mx.upcmail.net (vie01a-dmta-at03-1.mx.upcmail.net [62.179.121.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE79168AD28 for ; Sat, 30 Apr 2022 01:18:48 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1nkYwk-0006Oo-1m for ffmpeg-devel@ffmpeg.org; Sat, 30 Apr 2022 00:18:42 +0200 Received: from ren-mail-psmtp-mg02. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id kYwjnoz2sSgGFkYwkn4svr; Sat, 30 Apr 2022 00:18:42 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg02. with ESMTP id kYwVnn6D08eSWkYwVnbn7C; Sat, 30 Apr 2022 00:18:27 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=KKE5sHJo c=1 sm=1 tr=0 ts=626c6442 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=NEAV23lmAAAA:8 a=-VxUsFSZiX51dfajKqAA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 30 Apr 2022 00:18:26 +0200 Message-Id: <20220429221826.31666-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220429221826.31666-1-michael@niedermayer.cc> References: <20220429221826.31666-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfOMfKj6I+DSTz4egdeQZXSHNuH9/kmJghrpNScM5G/6u+B7ZlaLFvKNgGciN1cunC44azSfjLGw6B5ZOuzTtq8B/273mV3B/NWOb/WvpNxhZhra4SorQ gh56AJHT9Zie6oU4WXRz3dRxjT8wOnj9sMEf5Ldfowm4Qf+uDVam56Zw/e1S7QRgkM5ctXbVm/hYbg== Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/h2645_parse: Check HEVC NAL size X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: A7L/G+7LEsNW Fixes: Assertion failure Fixes: 46662/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-4947860854013952 This also results in more frames to be decoded from fate samples Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/h2645_parse.c | 2 +- .../ref/fate/hevc-conformance-NoOutPrior_A_Qualcomm_1 | 10 ++++++++++ tests/ref/fate/hevc-conformance-RAP_B_Bossen_1 | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 03780680c6..78ab22b76e 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -292,7 +292,7 @@ static int hevc_parse_nal_header(H2645NAL *nal, void *logctx) { GetBitContext *gb = &nal->gb; - if (get_bits1(gb) != 0) + if (get_bits_left(gb) < 16 || get_bits1(gb) != 0) return AVERROR_INVALIDDATA; nal->type = get_bits(gb, 6); diff --git a/tests/ref/fate/hevc-conformance-NoOutPrior_A_Qualcomm_1 b/tests/ref/fate/hevc-conformance-NoOutPrior_A_Qualcomm_1 index 0c930f6556..3283925e38 100644 --- a/tests/ref/fate/hevc-conformance-NoOutPrior_A_Qualcomm_1 +++ b/tests/ref/fate/hevc-conformance-NoOutPrior_A_Qualcomm_1 @@ -25,6 +25,16 @@ 0, 19, 19, 1, 599040, 0x4227009b 0, 20, 20, 1, 599040, 0x1bda8be4 0, 21, 21, 1, 599040, 0xd1d5dcb4 +0, 22, 22, 1, 599040, 0x58b2edb3 +0, 23, 23, 1, 599040, 0xd1f795d8 +0, 24, 24, 1, 599040, 0x3331d5e6 +0, 25, 25, 1, 599040, 0x5e5ec2c9 +0, 26, 26, 1, 599040, 0x3b907bf5 +0, 27, 27, 1, 599040, 0xefcbf471 +0, 28, 28, 1, 599040, 0x2769a578 +0, 29, 29, 1, 599040, 0x812ce986 +0, 30, 30, 1, 599040, 0xf07c212c +0, 31, 31, 1, 599040, 0xb5476890 0, 32, 32, 1, 599040, 0x00a0249f 0, 33, 33, 1, 599040, 0x7263f7cf 0, 34, 34, 1, 599040, 0x47054be4 diff --git a/tests/ref/fate/hevc-conformance-RAP_B_Bossen_1 b/tests/ref/fate/hevc-conformance-RAP_B_Bossen_1 index e661ff245e..776267b59c 100644 --- a/tests/ref/fate/hevc-conformance-RAP_B_Bossen_1 +++ b/tests/ref/fate/hevc-conformance-RAP_B_Bossen_1 @@ -70,6 +70,9 @@ 0, 64, 64, 1, 149760, 0x3362678b 0, 65, 65, 1, 149760, 0x6e7fc851 0, 66, 66, 1, 149760, 0x33f96449 +0, 67, 67, 1, 149760, 0xd9d05007 +0, 75, 75, 1, 149760, 0x477f2cf2 +0, 76, 76, 1, 149760, 0xe1f9ccd0 0, 77, 77, 1, 149760, 0xb3ba8cfb 0, 78, 78, 1, 149760, 0x64787995 0, 79, 79, 1, 149760, 0xc10de4c4