From patchwork Sun Jun 18 21:50:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42212 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp329922pzb; Sun, 18 Jun 2023 15:44:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZTJkwewvrKDQdFM4UWDhfl2w/WkMcauZYL+PLwb1Glbu6uXFeIrdV5HhGvRxd2pWSWkza X-Received: by 2002:a17:907:16a2:b0:982:4abc:97d6 with SMTP id hc34-20020a17090716a200b009824abc97d6mr8020705ejc.4.1687128246303; Sun, 18 Jun 2023 15:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687128246; cv=none; d=google.com; s=arc-20160816; b=GKdR/AfjI7neJbR9NVqGukYZZAMpvCM1G6LN4+EZlWWuy1ZaT0PCDkH07GcwRfojZC rI9viPROl7REWrIFwg3XskcuxDB3Etd9kJc2MD+mE2Tf5xP8+vfcqBw6m1KaJQrxdEsL nw3vlNTPJXaB4rXxPdEyOprISPGfOdp8XZNFX2NCugPzymJhOGdYAnCvXPprwikZctZk F75fLGIBuG24iDiJR+/RrxeTGJxPKNozFXZbLL+lbE4oOCyO+vrvDo/RuUFCIwW31DLi uogNHLYRw53zSI/S38QiYpIGZS0dBlic7qkTwSvtTfDe22IAO1qfAsCnmdIMET3l7ooq zEJQ== 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=HKPr5XIzZZjhzLk95xKndZ4kcDIUyhGv7OXd0SHl5Pk=; b=C/AZ423ILkeQH1IeYw7dmaNMfKia/C+UWrqVb8a7W5HzVulggCCmBwrXH204ausvjU TOV08DAJdWVH00tPwVLT4taOL7oOZyWQvTJ7qj+O7Uxsa4svja7yKMhTedFc6ns79F3j kgvg16x2u28vyUzny/dDXkUmEF5Ro56DVm3PmivkESyFcm5eQQY3xiCoDmBxZx/Iu+Gz VWtpMp+THU81++NHlXdRj2LPNSpLFB0OoGXE/H9UwlH+p3I7KqlppISDs2/5moDzJ5ZH lrIA+Sb/5WdhmW8Q/+1LDL8LtJp5cAa1SPhGE4q114kt/BwLHfVSgTbXZcMod3GCMZ2a W2PA== 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 n2-20020a170906088200b00977d54350c2si10530026eje.916.2023.06.18.15.44.05; Sun, 18 Jun 2023 15:44:06 -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 4FF6F68BF30; Mon, 19 Jun 2023 01:44:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-01-1.mymagenta.at (mail-01-1.mymagenta.at [80.109.253.246]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D55A68ABA6 for ; Mon, 19 Jun 2023 01:43:56 +0300 (EEST) Received: from [192.168.232.136] (helo=ren-mail-psmtp-mg02.) by mail-01.mymagenta.at with esmtp (Exim 4.93) (envelope-from ) id 1qB0Hu-00CHop-HC for ffmpeg-devel@ffmpeg.org; Sun, 18 Jun 2023 23:50:22 +0200 Received: from localhost ([84.115.40.24]) by ren-mail-psmtp-mg02. with ESMTP id B0HwqrzP4bZLDB0HwquNID; Sun, 18 Jun 2023 23:50:24 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 84.115.40.24 X-CNFS-Analysis: v=2.4 cv=Ufwy9IeN c=1 sm=1 tr=0 ts=648f7c20 a=4thelYDX6rwh+ygQwvsI+Q==:117 a=4thelYDX6rwh+ygQwvsI+Q==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=w-GfLOqwoN9W1uoqOhQA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 18 Jun 2023 23:50:18 +0200 Message-Id: <20230618215021.3044-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230618215021.3044-1-michael@niedermayer.cc> References: <20230618215021.3044-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4xfFR2oEi2NtwF8/g5IO6xmSopH4o3DZZit/iK5a3FYxPcKQjdCc1o70STbGewdCTA0y4qAIeDUoBvj3R/I/zkKkQ0nuf8YUgdmauFTkKYnM/70c/iSSJv LoJWzqXj5HCPX5TPTXayV6tcmOl45RINTbBt1iGTU1u8FW9oJxQE2pOSp9NN6nNTz3PJY3MJlLpFPA== Subject: [FFmpeg-devel] [PATCH 3/6] avformat/jpegxl_anim_dec: add FF_JPEGXL_CONTAINER_SIGNATURE_LE 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: m6MTVAAEzcac Fixes: out of array read Fixes: 59828/clusterfuzz-testcase-minimized-ffmpeg_dem_JPEGXL_ANIM_fuzzer-5029813220671488 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/jpegxl_anim_dec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c index c62b596f76..7e4d39385c 100644 --- a/libavformat/jpegxl_anim_dec.c +++ b/libavformat/jpegxl_anim_dec.c @@ -108,7 +108,7 @@ static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int inp static int jpegxl_anim_probe(const AVProbeData *p) { - uint8_t buffer[4096]; + uint8_t buffer[4096 + AV_INPUT_BUFFER_PADDING_SIZE]; int copied; /* this is a raw codestream */ @@ -123,7 +123,7 @@ static int jpegxl_anim_probe(const AVProbeData *p) if (AV_RL64(p->buf) != FF_JPEGXL_CONTAINER_SIGNATURE_LE) return 0; - if (jpegxl_collect_codestream_header(p->buf, p->buf_size, buffer, sizeof(buffer), &copied) <= 0 || copied <= 0) + if (jpegxl_collect_codestream_header(p->buf, p->buf_size, buffer, sizeof(buffer) - AV_INPUT_BUFFER_PADDING_SIZE, &copied) <= 0 || copied <= 0) return 0; if (ff_jpegxl_verify_codestream_header(buffer, copied, 0) >= 1) @@ -138,7 +138,8 @@ static int jpegxl_anim_read_header(AVFormatContext *s) AVIOContext *pb = s->pb; AVStream *st; int offset = 0; - uint8_t head[256]; + uint8_t head[256 + AV_INPUT_BUFFER_PADDING_SIZE]; + const int sizeofhead = sizeof(head) - AV_INPUT_BUFFER_PADDING_SIZE; int headsize = 0; int ctrl; AVRational tb; @@ -147,7 +148,7 @@ static int jpegxl_anim_read_header(AVFormatContext *s) uint64_t sig16 = avio_rl16(pb); if (sig16 == FF_JPEGXL_CODESTREAM_SIGNATURE_LE) { AV_WL16(head, sig16); - headsize = avio_read(s->pb, head + 2, sizeof(head) - 2); + headsize = avio_read(s->pb, head + 2, sizeofhead - 2); if (headsize < 0) return headsize; headsize += 2; @@ -178,10 +179,10 @@ static int jpegxl_anim_read_header(AVFormatContext *s) if (av_buffer_realloc(&ctx->initial, ctx->initial->size + read) < 0) return AVERROR(ENOMEM); } - jpegxl_collect_codestream_header(buf, read, head + headsize, sizeof(head) - headsize, &copied); + jpegxl_collect_codestream_header(buf, read, head + headsize, sizeofhead - headsize, &copied); memcpy(ctx->initial->data + (ctx->initial->size - read), buf, read); headsize += copied; - if (headsize >= sizeof(head) || read < sizeof(buf)) + if (headsize >= sizeofhead || read < sizeof(buf)) break; } }