From patchwork Fri Dec 15 01:48:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 45154 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp5364740pzf; Thu, 14 Dec 2023 17:48:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnYLk/MrTGC3fBSwUs2Hf6uOWOp8q1Msa+sNXtxjC1aHNwh6le8FVUHB9RTl/fPZzd/WqM X-Received: by 2002:a50:9f44:0:b0:552:3553:4546 with SMTP id b62-20020a509f44000000b0055235534546mr3455972edf.4.1702604930705; Thu, 14 Dec 2023 17:48:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702604930; cv=none; d=google.com; s=arc-20160816; b=zHeLp6MM03fPp1txOq3VpUN/Ek3uVXVdEjTNKuEkL/ZSKzu7eB3GWmTKQnEXHmPJiV WfXBV70vfHqI1W0SBJzEwGCC/JfdnG2uBHdhrBESxW5TTYw03qmxZ3HRoSx1bNmJV6xb vDv/+i6H3ZCol+C6CFnZ3DzsWCGhfEU4zixv3cuh2lwR2ruRI/5CQoZ50xgq9VkibVoR RFqhFQGhAzSOLNiF3YtLSdQueW1rpRM+1hNU/Gl/qMMK+pOERpR+ys8nInlEi1YkN9Bg nneJWsWrdk/3yJ2jRH45PdBvM0arN9l+GikGySJOUjZ6+nOmdx+8OVzI0lsLRdfkw9PS 0spQ== 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:dkim-signature:delivered-to; bh=Y55mFkqXcysWQSoocxqfyLUk2SKpSgo5F1vVuFZMqqA=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=YCAs8UNbjU7dIozzxQtpFhuAVdPMSQaghkYdlBc85ITH3L89fPphurQSdtuvWQywP0 NB+YcxhlP1f6K2YTnGjhVO2SZq9Ro2SjfoRGFlLeIGTXqO43IYAMw4OevY4FCSew0hvm FseN/jGROFztyySqGoL/TFZsxTgU2ZnwRGk6UFk2z35OIT+vOT5JSbnG83/B9jJgSelC 0/HJ7P9+yRndDsAqP9xqbPENOaEkeK+WlPnq0acLjLWjZEIc68jAbzAaxefLcItl9amY BZart3sUR5AvYZMHw4z2efIjwniEN6fCwiGQyNAbtHQ0ctO9bZGl1QDU/d6XI/juVdm2 AmEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=GRpGfmWY; 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 g9-20020a056402090900b0055146a5fde4si3635154edz.667.2023.12.14.17.48.50; Thu, 14 Dec 2023 17:48:50 -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; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=GRpGfmWY; 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 F2D1868D230; Fri, 15 Dec 2023 03:48:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B424C68D11B for ; Fri, 15 Dec 2023 03:48:30 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 04BD81BF206 for ; Fri, 15 Dec 2023 01:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1702604910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:in-reply-to:in-reply-to:references:references; bh=mplAQEgUoDnHv2oobyTE8Z/VaVZKurEScLYMRvjzCDM=; b=GRpGfmWYHrOGnzoRuTwLISwg/A4CUHFxbE46fc1fhXS/DNZnwHOfAjLQp1N78qx/osOZG7 oT6zsMTTEHwd28HgC9qqD4ghpa3ObIxS5qQBoYydo6T7xAlpbBh7xvSWuI9kkvCxYAIUCp Hl6kiVhHy9Hz0vDj5ugJlUvI93/QaBPMKsmdOKzNXml8XQM1RqidAZ9zoiqBK/wYjQSLiM 4zRRNhpKQnQ+txwCEEaFvlb02QxRgAu1n2Ot6hlMahqy4syvckkA2h8/btA8Me1rP/v1T8 p4G/4URHkiqkVbsipKilj1zdg951TXcpZpAS9yEcS3qUsyNJRSfVUaXGvxfbNg== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 15 Dec 2023 02:48:27 +0100 Message-Id: <20231215014828.8115-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231215014828.8115-1-michael@niedermayer.cc> References: <20231215014828.8115-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/jpegxl_parser: Add padding to cs_buffer 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: KlJCehi5awcq Fixes: out of array access Fixes: 64081/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6151006496620544 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/jpegxl_parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c index 006eb6b2954..a2f9a053018 100644 --- a/libavcodec/jpegxl_parser.c +++ b/libavcodec/jpegxl_parser.c @@ -162,7 +162,7 @@ typedef struct JXLParseContext { int skipped_icc; int next; - uint8_t cs_buffer[4096]; + uint8_t cs_buffer[4096 + AV_INPUT_BUFFER_PADDING_SIZE]; } JXLParseContext; /* used for reading brotli prefixes */ @@ -1391,7 +1391,7 @@ static int try_parse(AVCodecParserContext *s, AVCodecContext *avctx, JXLParseCon if (ctx->container || AV_RL64(buf) == FF_JPEGXL_CONTAINER_SIGNATURE_LE) { ctx->container = 1; ret = ff_jpegxl_collect_codestream_header(buf, buf_size, ctx->cs_buffer, - sizeof(ctx->cs_buffer), &ctx->copied); + sizeof(ctx->cs_buffer) - AV_INPUT_BUFFER_PADDING_SIZE, &ctx->copied); if (ret < 0) return ret; ctx->collected_size = ret; @@ -1400,7 +1400,7 @@ static int try_parse(AVCodecParserContext *s, AVCodecContext *avctx, JXLParseCon return AVERROR_BUFFER_TOO_SMALL; } cs_buffer = ctx->cs_buffer; - cs_buflen = FFMIN(sizeof(ctx->cs_buffer), ctx->copied); + cs_buflen = FFMIN(sizeof(ctx->cs_buffer) - AV_INPUT_BUFFER_PADDING_SIZE, ctx->copied); } else { cs_buffer = buf; cs_buflen = buf_size;