From patchwork Thu Nov 23 23:45:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 44779 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp930319pzb; Thu, 23 Nov 2023 15:45:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEshu4i5yt13Zw0Nhq2HawMiAqRzfus8CY1fb5sisb89hOqpkAtZibTamin62Ftx+sJefo4 X-Received: by 2002:a17:906:f0c7:b0:9fd:49c4:81f1 with SMTP id dk7-20020a170906f0c700b009fd49c481f1mr600871ejb.47.1700783157954; Thu, 23 Nov 2023 15:45:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700783157; cv=none; d=google.com; s=arc-20160816; b=OyOIyqJnFyJAYbKRMRUo3Kpm6+5zjEMVutYM/I2nJnqEnQpolxMdtG+YXcnSwlMMaF 36EgCyNjsJaPWNCBBkaCwZdkrhqKqtKXvM42eu+ayszMabx+BedqG0QwO8nVFJLVUxBd jaqUrh3UT94Wm8+IizGQ2RiHWUTF4Bklw5cS8y4WQWW7hO2ti5dCjuRE9cczxdEIZ7jw A/K5Ihleq9oPZPMuMRN/UPHFsoaNGQWdKwX/wrFxt6tvgVTsjqaT0USCIP4demB7XYy0 U4fO/08Ad3QEevdvCZ54El2mzsWwc8ZxrDx91V2JxNRQM+bViD/bDgY9MgFfU3/ohN0q ZSaA== 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=q7pR2ASaLjlKKqhPTjNZkd969mdgWGRYSSieMo2QlfTRHIWIau7gGU8J37ciwUm8d+ BeUdYPkI8ZHFZVH4rjVS6jcx1fCQPKoSoHUQpT1OaqB2pkR8OvQJCs0ruhE8bzp+qN3S U7hICSINvcpsO1KHmkCMwBZHOjIM+ijlP1ledBFk7RMf5GKoPT6cCSdL9m8T8BGTV6QC OMU6/0Cl7ARooDNhWm5PKKGwKN7D4n/qwcvRwOSmtdf5sqNm0pvnHOcLQM9JUrwp8u9J SqxBaBP7qrJdHxcdU8G2EvdALQqwXMDGMSwVqrbOnGG018Wxiujz9Dbc5hHd4InRD+pF qTxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=A76tqpkS; 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 gl11-20020a170906e0cb00b00a02609a5c24si1160664ejb.189.2023.11.23.15.45.57; Thu, 23 Nov 2023 15:45:57 -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=A76tqpkS; 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 5F82868CD68; Fri, 24 Nov 2023 01:45:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 13C6D68CB87 for ; Fri, 24 Nov 2023 01:45:46 +0200 (EET) Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-779d0c05959so16078685a.1 for ; Thu, 23 Nov 2023 15:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700783145; x=1701387945; 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=A76tqpkSU2IQSmJCKSZUmYj1QyCJ1VrytfF0dVEQ7Ed6ixcHL+oXxO088MAhhfHosU 8QtCErIlyLu5Iatn+cZl8iAcuQBYo3DvEeVz/xpGhu0fNC+Y8vefJUIts7IRw0Qbplqg EoydFcEJU1pONbqsdvLZP2Y5TP8hb5txhggMoq2A3uUV0ARXofNeVIgu8GG+Lg8LZ4XQ rIHI83CLkig7rNoIe3cn6k/WzH4UkWyL7I/INWTC113SHgcBfAoYngQCCfp+fO/Pn3iH ziiYq9vvcHqstM85iXIgrS2n100Qf8UFB87S3Ir9iH7OIe4SpuKEsArFFIExPYPdrhee dPFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700783145; x=1701387945; 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=NPH2si9dbm/+CNhLrvkQ8azVD07tYGYmJJP7vwWEtleYuPkHQ4nKLBEnqmil4bL104 106wkLDYb+K1jM4AdKyau2gDAvp6f4thWdQqD4ufYjZ2ElBjfHCghnD1LNPrpuN74WJB EmOjCrALompWbrG1XQ8DiAfaOGjwPKvaMnTr0kW/m0UuOqSMSy4BxcjVri5unzfAUdQb 6df98J13Jbkyw5F/dI57PCIpJG5XRt8tkDh98YZSxZKZWX6SLoJN5tU3mHKNtci/E0ow 1dMHvkwJE1PZm3k1g/WP7Sk4ZEVfwSxeDwlvpwIEX8hr2e9fde8RP80AHn11YoSLZch0 oQ3g== X-Gm-Message-State: AOJu0YweQNMgBvoE3uQVNFjScX8Wmno4bnmNOL1avK94yOBDJfIT48rk 4075V7QcpgHYny1aDwTYhe0g8IlTkK4= X-Received: by 2002:a05:6214:e62:b0:679:dfc4:a5b with SMTP id jz2-20020a0562140e6200b00679dfc40a5bmr1107121qvb.5.1700783144620; Thu, 23 Nov 2023 15:45:44 -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 dy20-20020ad44e94000000b0067a14f54f8asm110601qvb.50.2023.11.23.15.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 15:45:44 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Nov 2023 18:45:40 -0500 Message-ID: <20231123234541.41316-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231123234541.41316-1-leo.izen@gmail.com> References: <20231123234541.41316-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] 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: 2jdW2LkYP2yo 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; From patchwork Thu Nov 23 23:45:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 44780 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp930419pzb; Thu, 23 Nov 2023 15:46:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1RG4AGiT0gUGy0WGmOtuEIkH7vgTDDy9U64wZJ2NcMcThm7QXoRILK6ewIbZATuBXCzO4 X-Received: by 2002:a17:906:f807:b0:9d0:51d4:4dc6 with SMTP id kh7-20020a170906f80700b009d051d44dc6mr441614ejb.2.1700783175169; Thu, 23 Nov 2023 15:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700783175; cv=none; d=google.com; s=arc-20160816; b=MlfYaklgy01QiNsvyfVvEZVTSDNBa2FZkki82vez297xesjgJn4fGJdStrqOAHd33/ 0Awd95g4e6nOYHRP7pBwycNZZmoAI16aWSjn41RnhjEA63uSpbQ9N/YvwiTm3vXCzDb5 Vd5vESmFmTgcKL/KiEZVqny0CUD+JMBZF+8leA2LvOO6jmCTlLXK56Zu36jPTWM35YD1 f13vPJ7OHGs8JpcBeBsfh5RoLMwFzoHzjC9xeeEhU4RekFfnEkH/8eO9ZHdXp3jUe+AF PONWYTW+srSR7f+6XpI1btuuB4+M4xQOTeFRb3jMheSzZ1jtDYVIz44jOJ3Sd12hY+sE TrVA== 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=0wkk4zIz98mE01nr+ZihwTL4gYjk7a1bA62pKwUWxJc=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=CEXm6XIpqtGCj8RqiW/RTEq3mgNfzBv0p2WSGOwrRpCpsQuGZ48QlFFR0N5jr7id4j kDJxCHrBwikqDZBTw9qHaejR+QrbQFA7HAPsnivaQKRMesQQ/oC0lVEXFcwIEiKwrLKn kJzE3wWuIw2B1+JjKXYcRgKbVFvS/utDh4hRN6d7qpu4e8cXg3FrUoJd0Fg60QF3sS+N 5Gm/UXF9f/lla83YgN2JEKW7lz/NFYBlQtw4T+/sYbT6xqMGASLaLJmuzMRFC5KQ+Xl0 tERHHn+Gxe80STxNl9wXDG5/rrMTUylvCLo9g3/wuFHwpZ0uXtMOd/W0igSEV2QBekll UnVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=adJqK8qk; 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 j13-20020a170906254d00b0099db0004d5asi1180814ejb.213.2023.11.23.15.46.14; Thu, 23 Nov 2023 15:46:15 -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=adJqK8qk; 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 79FDF68CEED; Fri, 24 Nov 2023 01:45:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F17868CB87 for ; Fri, 24 Nov 2023 01:45:47 +0200 (EET) Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3b2d9a9c824so303736b6e.0 for ; Thu, 23 Nov 2023 15:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700783145; x=1701387945; 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=FBbZANov46ynIfWYgvrkbCcQDXJVS2J3qSQa6VJhbNw=; b=adJqK8qka9lLzSL6KDUnIPhn3BHtDCphe73Uwh23MlgXD4oFAeSJE/Efxvqhp/gu/Y mnP6IrOaOs/ZWlB03GDVdPDX4ILrYkrJorSOWWEomTnWhsy2IVlX8Ainlg4HOGr/JKy1 hltfugUjc8N2Wc0pBBI4qQ1gW974wFZULf6G115hso4F0Ui/JbJSW8oEmAXeEAWXdvH9 cK4DSyk9t/3Bx760evFyCqLLAdPx2clpGTl3m5k3B8PlWDw9pZl8cRD21DHuamGv/Sgf +rPB+ZMxxbq6Ah4Am+aEG0gibYgSpgdKXeA/+FDQpu3/7DiMEui5/j8rMJGRzJxRuN8T GRXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700783145; x=1701387945; 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=FBbZANov46ynIfWYgvrkbCcQDXJVS2J3qSQa6VJhbNw=; b=gshW6xnijBKd3v8eE9CtHnTmXvUpDJWNPgq0J1UbYhVMnq9S1NDa8g0wRJWsX1LSsh UixZVAtJL8n2oI+ateDkHayhbCF+cNy/vy+da75N3Do0aTUMUsV9ZfG8BqwkG4utdLnX 6wQLC/yixz3boaauq8sRipofVPoo5+h5ymu+38icjMgR94jwM1EZ6+mNI0muPhGPRp00 DU2w4SVUZ4dJH99vSTQHQZhCy9O374vyFZKa0BDV+HhCLg/NSF72rZBD4u+HIXMpkKhu Np98+qhsvny+A7VO6uRQim5008v5hfE4u/LFFp1T3KByRI1ktfMDFS0Gyzz1g1Pb67OF kzvg== X-Gm-Message-State: AOJu0YzFOehgs2xyrll0MnHk0nnh8Mk7t9WPD4yC7pnRmrMEvYBN9Sjd kU5hqmXORrb2BkDxxdsffqNNIGPKnpM= X-Received: by 2002:a05:6358:71d:b0:16d:abd9:f29e with SMTP id e29-20020a056358071d00b0016dabd9f29emr712915rwj.2.1700783145362; Thu, 23 Nov 2023 15:45:45 -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 dy20-20020ad44e94000000b0067a14f54f8asm110601qvb.50.2023.11.23.15.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 15:45:45 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Nov 2023 18:45:41 -0500 Message-ID: <20231123234541.41316-3-leo.izen@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231123234541.41316-1-leo.izen@gmail.com> References: <20231123234541.41316-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/jpegxl_parser: fix parsing sequences of extremely small files 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: A14rQZUzNqyN This patch allows the JXL parser to parse sequences of extremely small files concatenated together. (e.g. smaller than the parser buffer) Signed-off-by: Leo Izen --- libavcodec/jpegxl_parser.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c index 750872f17f..006eb6b295 100644 --- a/libavcodec/jpegxl_parser.c +++ b/libavcodec/jpegxl_parser.c @@ -1454,15 +1454,21 @@ static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx, { JXLParseContext *ctx = s->priv_data; int next = END_NOT_FOUND, ret; + const uint8_t *pbuf = ctx->pc.buffer; + int pindex = ctx->pc.index; *poutbuf_size = 0; *poutbuf = NULL; - if (!ctx->pc.index) - goto flush; + if (!ctx->pc.index) { + if (ctx->pc.overread) + goto flush; + pbuf = buf; + pindex = buf_size; + } if ((!ctx->container || !ctx->codestream_length) && !ctx->next) { - ret = try_parse(s, avctx, ctx, ctx->pc.buffer, ctx->pc.index); + ret = try_parse(s, avctx, ctx, pbuf, pindex); if (ret < 0) goto flush; ctx->next = ret; @@ -1471,7 +1477,7 @@ static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx, } if (ctx->container && ctx->next >= 0) { - ret = skip_boxes(ctx, ctx->pc.buffer, ctx->pc.index); + ret = skip_boxes(ctx, pbuf, pindex); if (ret < 0) { if (ret == AVERROR_INVALIDDATA) ctx->next = -1;