From patchwork Mon Nov 27 14:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 44830 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp3382680pzb; Mon, 27 Nov 2023 06:10:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeFxtSTnYD0dm65bwrxSLR4eM54zdeLYKw1MycqE92R1pkv9FYQLm5NSmP8LAv/d37uuwc X-Received: by 2002:a17:906:eb01:b0:a00:1acf:6fe5 with SMTP id mb1-20020a170906eb0100b00a001acf6fe5mr7402957ejb.1.1701094258860; Mon, 27 Nov 2023 06:10:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701094258; cv=none; d=google.com; s=arc-20160816; b=qNFCFXFonfPThLRo0zcxf8B9sqRy8dylm+X9o3lZahkSqmYq2anOan/bGIUAagho83 2dGCWCXkDTkeuwtGQ9Ofzl90uQpS+424LL5SBAtrqBZDXLaBJP5FT/PMU54RtDSPPG6t jquwQ3Cx6x9s2O7cLsC9t+lca2afHov/vor60avBuOjxeGG/3tRagyU17KdhJY+XF0d5 oRET3+DRzaohv4m3o9OS75xHzonLNwStIKr3qHZHXBfsHYdF3kCnyRZdrePxOr7iSmk1 yMdHW6pokJNgWxcN3qcnWcVlFK8YysIWcmwytFtUU/c9Ha+ZwAZwpOgraF3hdExz4alX AqMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=iIadya++sH/ZmvJNUQeh119/vuQezm3Z0Os9ErxoGa4=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=onmjo2oReaaAXrOMMxcowhwZtQjF6Ba6ADxJyq4JpY8LvHaFe0t0RwRXuBiBb1Opve 9UY6JwFGCcLIzdrGCoIclBsLvlc2DCM+MuH4Cmp0QrU6wSUp0itHQVb8imFbOWpGnixe 0PdyBwVZmrUChbTHZ8y36Mjaa7EqwMpRU7I/czMse6OwFgYQRWcS+et3AlSzgOGM2byv wZazs3oSkKyUgfUlgHtrJrLwvUc9Yko7fSumUn7R1MuysprpsO6A/AAGUz7LAxohY628 HEBYdnqYNLPCgaUUSDlNPB6mq+plULQhTDTtK7JaHSklsxGmJCnBdkVNcbhuuTiNeFZ9 DpRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=fH8HYKiN; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v12-20020a1709064e8c00b009dd949b754csi4995266eju.174.2023.11.27.06.10.39; Mon, 27 Nov 2023 06:10:58 -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=@gmail.com header.s=20230601 header.b=fH8HYKiN; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A53068CDD7; Mon, 27 Nov 2023 16:10:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA9F968CC52 for ; Mon, 27 Nov 2023 16:10:13 +0200 (EET) Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-67a218d702aso6729996d6.1 for ; Mon, 27 Nov 2023 06:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701094212; x=1701699012; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yI5vuTzgvGu5HmcVrYfSeJvc+FG68GcBjqNNCg+eAIE=; b=fH8HYKiNPHW7ZDSGyfGcJ/FUPryx9mYw/TOXRuJxGYxk+qlWdbkIslXIkgZ4cVOIJ+ g4imZfYatkdxSpyCOt2BV6GbgnFEjxSgM3/P+31oM6COaGhbafHeGB4FHQPq3FJ4Pznm 9M51dZyiakZymlZaD1QBcdDTdVUs/6fe/kx6foFUZajUaqA5T1Iof4yUSXDHexxqyx5f mu81sJPqtEAGnv57PbiDt1yOCJwx4h8hOT8rpCsQRBmzw+SlSsYUR97L0biT9GVe1kfl YSfW1IL/hg3KlwIhWWYWPE65DYle2hQkxltFCWPdoC4ramPSsmyIyiGYmvut7gI5PjYW DZwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701094212; x=1701699012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yI5vuTzgvGu5HmcVrYfSeJvc+FG68GcBjqNNCg+eAIE=; b=jqsqtjDFhHuOolzswnyjtTnrCVjVucYBfTCbXmmoV5/vqnL0L/RRQ8n0RLM0JN0G48 ATPqolCv9uqibkgDQZDXfDG1gY1ztMU6MddZ5TgYNKfFZhP2Wo66lsHwiyS42GPs5NYg CYxJLTtv7upQ6f3BXgzKzOIAqlj6fexvBOlJeyg3DRl27iHbuvCwNBoFdGqX7y/NQbZ1 CjjXp46C35xbcpaSNik/h09AbCEqt6q9Ib2Ci5VB/cRe+Yw3MqZTA+S715IgX7oIE993 WNTJ9wu3GqRWxxFVSgNikGhsiQ6OFuDVFBMu9KCKPbwOCGZz0b/4V9n2X9X7dOdEdh5q k3Wg== X-Gm-Message-State: AOJu0YzUCq+GtHx+erDZ0pgl321pfv37oykqZ4zQVq4OfrnXWiXRNELs /wykPAyicjhU6vNe4M0/Ejbiafdb2/o= X-Received: by 2002:ad4:4982:0:b0:67a:14fe:f3b0 with SMTP id u2-20020ad44982000000b0067a14fef3b0mr11142499qvx.0.1701094212553; Mon, 27 Nov 2023 06:10:12 -0800 (PST) Received: from gauss.local (c-68-56-149-176.hsd1.mi.comcast.net. [68.56.149.176]) by smtp.gmail.com with ESMTPSA id tp13-20020a05620a3c8d00b0077d72f820adsm3699365qkn.115.2023.11.27.06.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:10:12 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Nov 2023 09:10:06 -0500 Message-ID: <20231127141008.183621-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231127141008.183621-1-leo.izen@gmail.com> References: <20231127141008.183621-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/3] avcodec/jpegxl_parse{, r}: use correct ISOBMFF extended size location 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 Cc: Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lYBEUjnWt1N5 According to ISO/IEC 14996-12, size == 1 means a 64-bit extended-size field occurs *after* the 32-bit box type, not before. This fix should allow correct parsing of JXL files with extended-size boxes. Signed-off-by: Leo Izen --- libavcodec/jpegxl_parse.c | 6 +++--- libavcodec/jpegxl_parser.c | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/jpegxl_parse.c b/libavcodec/jpegxl_parse.c index eb28e80867..7cfdd3e7d5 100644 --- a/libavcodec/jpegxl_parse.c +++ b/libavcodec/jpegxl_parse.c @@ -462,8 +462,10 @@ int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_l return AVERROR_BUFFER_TOO_SMALL; size = bytestream2_get_be32(&gb); + tag = bytestream2_get_le32(&gb); + if (size == 1) { - if (bytestream2_get_bytes_left(&gb) < 12) + if (bytestream2_get_bytes_left(&gb) < 8) return AVERROR_BUFFER_TOO_SMALL; size = bytestream2_get_be64(&gb); head_size = 16; @@ -474,8 +476,6 @@ int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_l if (size) size -= head_size; - tag = bytestream2_get_le32(&gb); - if (tag == MKTAG('j','x','l','p')) { uint32_t idx; if (bytestream2_get_bytes_left(&gb) < 4) diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c index 630fc8a60b..750872f17f 100644 --- a/libavcodec/jpegxl_parser.c +++ b/libavcodec/jpegxl_parser.c @@ -1342,7 +1342,7 @@ static int skip_boxes(JXLParseContext *ctx, const uint8_t *buf, int buf_size) while (1) { uint64_t size; - int head_size = 4; + int head_size = 8; if (bytestream2_peek_le16(&gb) == FF_JPEGXL_CODESTREAM_SIGNATURE_LE) break; @@ -1353,16 +1353,17 @@ static int skip_boxes(JXLParseContext *ctx, const uint8_t *buf, int buf_size) return AVERROR_BUFFER_TOO_SMALL; size = bytestream2_get_be32(&gb); + bytestream2_skip(&gb, 4); // tag if (size == 1) { - if (bytestream2_get_bytes_left(&gb) < 12) + if (bytestream2_get_bytes_left(&gb) < 8) return AVERROR_BUFFER_TOO_SMALL; size = bytestream2_get_be64(&gb); - head_size = 12; + head_size = 16; } if (!size) return AVERROR_INVALIDDATA; /* invalid ISOBMFF size */ - if (size <= head_size + 4 || size > INT_MAX - ctx->skip) + if (size <= head_size || size > INT_MAX - ctx->skip) return AVERROR_INVALIDDATA; ctx->skip += size;