From patchwork Thu Jun 8 14:26:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42011 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp438417pzb; Thu, 8 Jun 2023 07:27:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51vX8b2Dn6UH54qYBhknOt8bDfkLXyJ+rbvvGPupWwWeiEdMW4/CmVpQWZBhNwvzKhtc+y X-Received: by 2002:aa7:d343:0:b0:514:77f5:d77c with SMTP id m3-20020aa7d343000000b0051477f5d77cmr8314561edr.1.1686234421374; Thu, 08 Jun 2023 07:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234421; cv=none; d=google.com; s=arc-20160816; b=OyX8oBraKHUeLj18Z9K+2QSObTixBlCcLAqAPCju0KmRGcPq1JcCn8juRTbfa9qU0/ OJtGuplwle9PY7lHZHbEG78ZVUcwQzTjSyzOQ0NjCfpSSchN+oUvEKCR8YkZXPdYn7tB ibQatLHm+157gaQhbmGxmkK5JgpBJ8768kAFaae+q7wU+MzHCANZ9cZnqVEJbjP+5pjS iGZ7N6ksDwfKj16saU1t8uKJZD/uB6HHoJg21e4F4ujSdBxwa0k4r9AJtW94/9O1fSa/ 8WP32UjwLCaRIZJHpPcLyeM0N+arLQM4M7YFFOv+6Cwh0eyicFFfM7QwdWct0qjWYxPC SsOA== 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=1NwNMIfknQ5bd8oULK3Ngmh9DkCIbu25QsFmu+lGaF8=; b=iai27tBlNlegIemkO4C0Y8RFxfssc8N/XdwqQvPsFqrSK4c8LTW/CPB0FFUo8AE4ms gZ/+5IFj5H2a47awXhl6QgMgRHieUh8KJh+8fTnTnNLpswBB2To7bb+O5CkuQZG3Zj1r EvrsoDwvhxze4R9uY8ij7j0Zpp5RIuDP5C6PgkGJ1DLEIDEuF/7cpR3NmxCoKGyM5Jxb RL11Nv7JJjAqAWfMZd/y60xkbBUtL4g+pKiaoL1o6WSpAl/iK4Myeu6gd0u5/9K2i744 47/qwvHvgv7gndpG9zmJY0/j+kgXD6O1V9XATVU7DLNMZkOsB/VYvA5y7eEYfGVaK1MY AJMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=gk9tzN4L; 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 y9-20020a50eb09000000b00514a0265c39si892815edp.74.2023.06.08.07.27.01; Thu, 08 Jun 2023 07:27: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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=gk9tzN4L; 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 71B7368C2F9; Thu, 8 Jun 2023 17:26:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A287E68C2E6 for ; Thu, 8 Jun 2023 17:26:41 +0300 (EEST) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-568fa2d6771so428167b3.0 for ; Thu, 08 Jun 2023 07:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686234400; x=1688826400; 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=Ry3EMcaKguEgGtHqGaPzJkQMLb11Hnko/T5CHG6dWCM=; b=gk9tzN4Lca8M9d/4sJjdRMpMZiOiRaz3+7FwhS0UCjshv7kv++wF9f6b6A21ThWRRB V08QHyL3yr+7kIDhQL+sy7+K4WAkZPDfBqg7fJaddUgxeuERYjD7cZ2dO82hhnh8v2Ka YisQX1H17nmB4fXfu+LfUftCylAdDptWE7dPyttppKqfV857NM2j+/81dXY+jSQpG/bI TdkD3hufT8vVAdraDwZVisAw22P4gygFPU/tuHEqe+OpTCOnYe9OZLwa9rakQSVFK1Ui n4piFWS5tZ7kbDYtKSCr3wTWVUA8Pec8VnQHModahRzUq8VhGYeYesw/z+fp/GUiF9G1 jnnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234400; x=1688826400; 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=Ry3EMcaKguEgGtHqGaPzJkQMLb11Hnko/T5CHG6dWCM=; b=GlqsfjsKBBtMS/kIKaRnG1L4b9qEJexxtY5T48xGp3r7ZtKzeT5CynNR+wYEW4S+Tv nDqRhc2EHtT1xIPeW+ib3UhMmRlMU9ZBfH9Ntpt8pDuUZhHe8SjZGi3p3Dp0SE27V8DP /t7mmyQBrCX/qkiIRs+iNbVPna79AirNLZYEYcL0oAcySaw5kPblxfRADrVjrvBFc7/K kxeF7DtaC3U9fWuUzrBxPhvJDBY1Lci5krZnjfLzYcC5Xt8/FGy+lebyAOSwmfJ8IPLk gUbS0lLKPOkF7oOAE1NsU5ywIgsqHRpZCtblfpXV9HaeqnktBhhJfX0aJbOoC5LvooCJ W8xg== X-Gm-Message-State: AC+VfDzarC2wbxD4HQDi8WEwZ8cNA3uAWf3WtHndWeh1bc6Yc+k+1zOq tR/c7sacIgI0FnVqsMDdXOMS5T7sLlk= X-Received: by 2002:a81:994b:0:b0:565:afae:f3fb with SMTP id q72-20020a81994b000000b00565afaef3fbmr8429531ywg.2.1686234399742; Thu, 08 Jun 2023 07:26:39 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id b206-20020a0dd9d7000000b0056943d9cf8fsm414589ywe.9.2023.06.08.07.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:26:39 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Jun 2023 10:26:33 -0400 Message-Id: <20230608142637.45033-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230608142637.45033-1-leo.izen@gmail.com> References: <20230608142637.45033-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avformat/jpegxl_probe: Remove intermediate macro obfuscation around get_bits*() 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: Michael Niedermayer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UxxqThAuaYle From: Michael Niedermayer Signed-off-by: Michael Niedermayer --- libavformat/jpegxl_probe.c | 169 +++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 84 deletions(-) diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c index a3845b037d..1d9c014f19 100644 --- a/libavformat/jpegxl_probe.c +++ b/libavformat/jpegxl_probe.c @@ -57,49 +57,50 @@ enum JpegXLPrimaries { FF_JPEGXL_PR_P3 = 11, }; -#define jxl_bits(n) get_bits_long(gb, (n)) -#define jxl_bits_skip(n) skip_bits_long(gb, (n)) -#define jxl_u32(c0, c1, c2, c3, u0, u1, u2, u3) jpegxl_u32(gb, \ - (const uint32_t[]){c0, c1, c2, c3}, (const uint32_t[]){u0, u1, u2, u3}) -#define jxl_u64() jpegxl_u64(gb) -#define jxl_enum() jxl_u32(0, 1, 2, 18, 0, 0, 4, 6) - /* read a U32(c_i + u(u_i)) */ -static uint32_t jpegxl_u32(GetBitContext *gb, - const uint32_t constants[4], const uint32_t ubits[4]) +static av_always_inline uint32_t jxl_u32(GetBitContext *gb, + uint32_t c0, uint32_t c1, uint32_t c2, uint32_t c3, + uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) { - uint32_t ret, choice = jxl_bits(2); + const uint32_t constants[4] = {c0, c1, c2, c3}; + const uint32_t ubits [4] = {u0, u1, u2, u3}; + uint32_t ret, choice = get_bits(gb, 2); ret = constants[choice]; if (ubits[choice]) - ret += jxl_bits(ubits[choice]); + ret += get_bits_long(gb, ubits[choice]); return ret; } +static av_always_inline uint32_t jxl_enum(GetBitContext *gb) +{ + return jxl_u32(gb, 0, 1, 2, 18, 0, 0, 4, 6); +} + /* read a U64() */ static uint64_t jpegxl_u64(GetBitContext *gb) { uint64_t shift = 12, ret; - switch (jxl_bits(2)) { + switch (get_bits(gb, 2)) { case 0: ret = 0; break; case 1: - ret = 1 + jxl_bits(4); + ret = 1 + get_bits(gb, 4); break; case 2: - ret = 17 + jxl_bits(8); + ret = 17 + get_bits(gb, 8); break; case 3: - ret = jxl_bits(12); - while (jxl_bits(1)) { + ret = get_bits(gb, 12); + while (get_bits1(gb)) { if (shift < 60) { - ret |= (uint64_t)jxl_bits(8) << shift; + ret |= (uint64_t)get_bits(gb, 8) << shift; shift += 8; } else { - ret |= (uint64_t)jxl_bits(4) << shift; + ret |= (uint64_t)get_bits(gb, 4) << shift; break; } } @@ -142,18 +143,18 @@ static int jpegxl_read_size_header(GetBitContext *gb) { uint32_t width, height; - if (jxl_bits(1)) { + if (get_bits1(gb)) { /* small size header */ - height = (jxl_bits(5) + 1) << 3; - width = jpegxl_width_from_ratio(height, jxl_bits(3)); + height = (get_bits(gb, 5) + 1) << 3; + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); if (!width) - width = (jxl_bits(5) + 1) << 3; + width = (get_bits(gb, 5) + 1) << 3; } else { /* large size header */ - height = 1 + jxl_u32(0, 0, 0, 0, 9, 13, 18, 30); - width = jpegxl_width_from_ratio(height, jxl_bits(3)); + height = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30); + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); if (!width) - width = 1 + jxl_u32(0, 0, 0, 0, 9, 13, 18, 30); + width = 1 + jxl_u32(gb, 0, 0, 0, 0, 9, 13, 18, 30); } if (width > (1 << 18) || height > (1 << 18) || (width >> 4) * (height >> 4) > (1 << 20)) @@ -170,18 +171,18 @@ static int jpegxl_read_preview_header(GetBitContext *gb) { uint32_t width, height; - if (jxl_bits(1)) { + if (get_bits1(gb)) { /* coded height and width divided by eight */ - height = jxl_u32(16, 32, 1, 33, 0, 0, 5, 9) << 3; - width = jpegxl_width_from_ratio(height, jxl_bits(3)); + height = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3; + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); if (!width) - width = jxl_u32(16, 32, 1, 33, 0, 0, 5, 9) << 3; + width = jxl_u32(gb, 16, 32, 1, 33, 0, 0, 5, 9) << 3; } else { /* full height and width coded */ - height = jxl_u32(1, 65, 321, 1345, 6, 8, 10, 12); - width = jpegxl_width_from_ratio(height, jxl_bits(3)); + height = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12); + width = jpegxl_width_from_ratio(height, get_bits(gb, 3)); if (!width) - width = jxl_u32(1, 65, 321, 1345, 6, 8, 10, 12); + width = jxl_u32(gb, 1, 65, 321, 1345, 6, 8, 10, 12); } if (width > 4096 || height > 4096) return -1; @@ -194,13 +195,13 @@ static int jpegxl_read_preview_header(GetBitContext *gb) */ static void jpegxl_skip_bit_depth(GetBitContext *gb) { - if (jxl_bits(1)) { + if (get_bits1(gb)) { /* float samples */ - jxl_u32(32, 16, 24, 1, 0, 0, 0, 6); /* mantissa */ - jxl_bits_skip(4); /* exponent */ + jxl_u32(gb, 32, 16, 24, 1, 0, 0, 0, 6); /* mantissa */ + skip_bits_long(gb, 4); /* exponent */ } else { /* integer samples */ - jxl_u32(8, 10, 12, 1, 0, 0, 0, 6); + jxl_u32(gb, 8, 10, 12, 1, 0, 0, 0, 6); } } @@ -210,34 +211,34 @@ static void jpegxl_skip_bit_depth(GetBitContext *gb) */ static int jpegxl_read_extra_channel_info(GetBitContext *gb, int validate_level) { - int all_default = jxl_bits(1); + int all_default = get_bits1(gb); uint32_t type, name_len = 0; if (!all_default) { - type = jxl_enum(); + type = jxl_enum(gb); if (type > 63) return -1; /* enum types cannot be 64+ */ if (type == FF_JPEGXL_CT_BLACK && validate_level) return -1; jpegxl_skip_bit_depth(gb); - jxl_u32(0, 3, 4, 1, 0, 0, 0, 3); /* dim-shift */ + jxl_u32(gb, 0, 3, 4, 1, 0, 0, 0, 3); /* dim-shift */ /* max of name_len is 1071 = 48 + 2^10 - 1 */ - name_len = jxl_u32(0, 0, 16, 48, 0, 4, 5, 10); + name_len = jxl_u32(gb, 0, 0, 16, 48, 0, 4, 5, 10); } else { type = FF_JPEGXL_CT_ALPHA; } /* skip over the name */ - jxl_bits_skip(8 * name_len); + skip_bits_long(gb, 8 * name_len); if (!all_default && type == FF_JPEGXL_CT_ALPHA) - jxl_bits_skip(1); + skip_bits1(gb); if (type == FF_JPEGXL_CT_SPOT_COLOR) - jxl_bits_skip(16 * 4); + skip_bits_long(gb, 16 * 4); if (type == FF_JPEGXL_CT_CFA) - jxl_u32(1, 0, 3, 19, 0, 2, 4, 8); + jxl_u32(gb, 1, 0, 3, 19, 0, 2, 4, 8); return 0; } @@ -256,40 +257,40 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid if (ret < 0) return ret; - if (jxl_bits(16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) + if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) return -1; if (jpegxl_read_size_header(gb) < 0 && validate_level) return -1; - all_default = jxl_bits(1); + all_default = get_bits1(gb); if (!all_default) - extra_fields = jxl_bits(1); + extra_fields = get_bits1(gb); if (extra_fields) { - jxl_bits_skip(3); /* orientation */ + skip_bits_long(gb, 3); /* orientation */ /* * intrinstic size * any size header here is valid, but as it * is variable length we have to read it */ - if (jxl_bits(1)) + if (get_bits1(gb)) jpegxl_read_size_header(gb); /* preview header */ - if (jxl_bits(1)) { + if (get_bits1(gb)) { if (jpegxl_read_preview_header(gb) < 0) return -1; } /* animation header */ - if (jxl_bits(1)) { + if (get_bits1(gb)) { animation_offset = get_bits_count(gb); - jxl_u32(100, 1000, 1, 1, 0, 0, 10, 30); - jxl_u32(1, 1001, 1, 1, 0, 0, 8, 10); - jxl_u32(0, 0, 0, 0, 0, 3, 16, 32); - jxl_bits_skip(1); + jxl_u32(gb, 100, 1000, 1, 1, 0, 0, 10, 30); + jxl_u32(gb, 1, 1001, 1, 1, 0, 0, 8, 10); + jxl_u32(gb, 0, 0, 0, 0, 0, 3, 16, 32); + skip_bits_long(gb, 1); } } @@ -297,10 +298,10 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid jpegxl_skip_bit_depth(gb); /* modular_16bit_buffers must equal 1 */ - if (!jxl_bits(1) && validate_level) + if (!get_bits1(gb) && validate_level) return -1; - num_extra_channels = jxl_u32(0, 1, 2, 1, 0, 0, 4, 12); + num_extra_channels = jxl_u32(gb, 0, 1, 2, 1, 0, 0, 4, 12); if (num_extra_channels > 4 && validate_level) return -1; for (uint32_t i = 0; i < num_extra_channels; i++) { @@ -308,85 +309,85 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid return -1; } - xyb_encoded = jxl_bits(1); + xyb_encoded = get_bits1(gb); /* color encoding bundle */ - if (!jxl_bits(1)) { + if (!get_bits1(gb)) { uint32_t color_space; - have_icc_profile = jxl_bits(1); - color_space = jxl_enum(); + have_icc_profile = get_bits1(gb); + color_space = jxl_enum(gb); if (color_space > 63) return -1; if (!have_icc_profile) { if (color_space != FF_JPEGXL_CS_XYB) { - uint32_t white_point = jxl_enum(); + uint32_t white_point = jxl_enum(gb); if (white_point > 63) return -1; if (white_point == FF_JPEGXL_WP_CUSTOM) { /* ux and uy values */ - jxl_u32(0, 524288, 1048576, 2097152, 19, 19, 20, 21); - jxl_u32(0, 524288, 1048576, 2097152, 19, 19, 20, 21); + jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); + jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); } if (color_space != FF_JPEGXL_CS_GRAY) { /* primaries */ - uint32_t primaries = jxl_enum(); + uint32_t primaries = jxl_enum(gb); if (primaries > 63) return -1; if (primaries == FF_JPEGXL_PR_CUSTOM) { /* ux/uy values for r,g,b */ for (int i = 0; i < 6; i++) - jxl_u32(0, 524288, 1048576, 2097152, 19, 19, 20, 21); + jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); } } } /* transfer characteristics */ - if (jxl_bits(1)) { + if (get_bits1(gb)) { /* gamma */ - jxl_bits_skip(24); + skip_bits_long(gb, 24); } else { /* transfer function */ - if (jxl_enum() > 63) + if (jxl_enum(gb) > 63) return -1; } /* rendering intent */ - if (jxl_enum() > 63) + if (jxl_enum(gb) > 63) return -1; } } /* tone mapping bundle */ - if (extra_fields && !jxl_bits(1)) - jxl_bits_skip(16 + 16 + 1 + 16); + if (extra_fields && !get_bits1(gb)) + skip_bits_long(gb, 16 + 16 + 1 + 16); - extensions = jxl_u64(); + extensions = jpegxl_u64(gb); if (extensions) { for (int i = 0; i < 64; i++) { if (extensions & (UINT64_C(1) << i)) - jxl_u64(); + jpegxl_u64(gb); } } } /* default transform */ - if (!jxl_bits(1)) { + if (!get_bits1(gb)) { /* opsin inverse matrix */ - if (xyb_encoded && !jxl_bits(1)) - jxl_bits_skip(16 * 16); + if (xyb_encoded && !get_bits1(gb)) + skip_bits_long(gb, 16 * 16); /* cw_mask and default weights */ - if (jxl_bits(1)) - jxl_bits_skip(16 * 15); - if (jxl_bits(1)) - jxl_bits_skip(16 * 55); - if (jxl_bits(1)) - jxl_bits_skip(16 * 210); + if (get_bits1(gb)) + skip_bits_long(gb, 16 * 15); + if (get_bits1(gb)) + skip_bits_long(gb, 16 * 55); + if (get_bits1(gb)) + skip_bits_long(gb, 16 * 210); } if (!have_icc_profile) { int bits_remaining = 7 - (get_bits_count(gb) - 1) % 8; - if (bits_remaining && jxl_bits(bits_remaining)) + if (bits_remaining && get_bits(gb, bits_remaining)) return -1; } From patchwork Thu Jun 8 14:26:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42012 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp438541pzb; Thu, 8 Jun 2023 07:27:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oRIclx+eEhyL/YuxSg0fGE+Fjff4TMTA7AJIhe0rmqd4mEwPPeI7Dgww+JVX9ADIVpg/8 X-Received: by 2002:aa7:c6c8:0:b0:514:7f39:aa82 with SMTP id b8-20020aa7c6c8000000b005147f39aa82mr6770864eds.27.1686234430805; Thu, 08 Jun 2023 07:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234430; cv=none; d=google.com; s=arc-20160816; b=zhkMNGeaQsCiwleTjv8mnfguesIzIqJ9C21yGEP4/FUuxcRTlR9xz0FwUkjuFGRqzs 01n5EmfExraBaefqBMvMcr0EX6T9EgdLd8ODw4+GSXoey+Fnr5cTX/9CFgDb33MImjv9 S4/hps27Tk7nRCXQ97cC2q2Y/kw7BcSOgIbbTGLcBKc4sEQE5PzcilQ9JJVmqy8JVs3n SzFUeEz2uNaxVkovn+6eNvRv1Mj1YG9laySKfNNJ/JaYxpD2fI25Jvw1aPTDA05r3xc3 f35XWsoNuAULF5T40IR/18iZ4qtY48EV1Fq/QP4XUeXhfnO2jhbWXkmbLgX4xmL6ixnX dEQg== 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=UQTswsygfnYALnV43GnrkFThn7Ge2WBwsYE1NtLXkSw=; b=NlVCOwxDfDPHAKTxebpZ37UdqXHafwyFsVtm6/EWknbMR4LnDvISVHdLEC08kEZXHS PTcqQYou2mttjIHenCfMMtOCEyQM33Sd+sIeBjhJIe63QAv+p5OPqjRTNXoVdFThqZuc 2olLZQ2wQQsyay5S1bEOE6fEMHjqhhJjquP6FLYsdInitnoRbxMe0lS/n4sX/IQkkoCg 4szHfXDoQWeih94x3waOCZOn/qgigJcb4sQZHchFUYOWYvxqKlmQJfGpy0BaqvbLhGJ4 OSHfONa9kuJFjVNOJRm+s7Gs4Oml6dfG9+oOBuN3tZLuOPnjekgR1tY3s4aFr8LftRCR XgSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=ANe0DyGE; 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 v26-20020aa7d81a000000b00516473ad18csi834797edq.119.2023.06.08.07.27.10; Thu, 08 Jun 2023 07:27:10 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=ANe0DyGE; 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 7E78C68C2EA; Thu, 8 Jun 2023 17:26:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2174F68C2F9 for ; Thu, 8 Jun 2023 17:26:42 +0300 (EEST) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-bad035c7123so83417276.1 for ; Thu, 08 Jun 2023 07:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686234400; x=1688826400; 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=H62/oohBrFUFMEnZCek7jsjRdnyrGqUuU+NIarT4Ohw=; b=ANe0DyGEusDo3Wew3DUs9wZ8yFp398QagiYJatmZxKd9DGs687YlJD5ZO4uOszfMiE es54vZK4b2/vd0XVyvGZIuSq3KtIlK8VJ09paUQv//0X9z504GCR+fI1h/mleQULDsCH 1yk3jxftwGOTTniQiIXhDXRBX7Y3jTBgvRy7cXPFPy9L4XXZT/0Y1uHlP1dzq9M20sn3 WGMSsBr2LI26a/qAen+lmCwApCKqWeTik6BPFczHIw1YTAwz+UXMS/yzLxzInQtPhH+v vZnU9F4O9zVia8dnwPxLJPunvfhWZpqW2T0Il5biJwbV9NuMGVoBLj8OLaxEpuwj0VMZ zsaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234400; x=1688826400; 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=H62/oohBrFUFMEnZCek7jsjRdnyrGqUuU+NIarT4Ohw=; b=UT4Q/Woyio6Gr06i0CqhvCVJc03ZgOIQxKUyPtCY/JVNmHzhjTrWeo+g0UXBikCsbK J2fbO1n6r5xzsWStB5c2cqwAw3rZYbF67qzAPHh6GaPpma5ci3A7SAYdD06G4BHEWA5y CKtx7Fw6dKK++9G8cUUvHiYl5+QaV5iGJJ6kdc8JFWigCN5WBRtQkZtgd3FI3P0b/ELl 7MG6FLetLoDi/YJPTz2qZ6pZTIr/CW5YR4zdYifdLB6VM+D47MKhjAns/hHZ804c6HL3 WcbH5hB+puBNw1ACslYDf+hODJZBbFKK02Bks/R9HaLLaZaU6UBks1ugII1x22RTLzqK P7eA== X-Gm-Message-State: AC+VfDy3dgWDMUbhJp3F/XTG2AeaNm3vuvpUeEmljMH06jN6YI/ssNr0 sk2dhV1/uETwWs6zzpBYrWvejZCo4tQ= X-Received: by 2002:a81:574c:0:b0:567:7dc3:2618 with SMTP id l73-20020a81574c000000b005677dc32618mr4247861ywb.1.1686234400312; Thu, 08 Jun 2023 07:26:40 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id b206-20020a0dd9d7000000b0056943d9cf8fsm414589ywe.9.2023.06.08.07.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:26:40 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Jun 2023 10:26:34 -0400 Message-Id: <20230608142637.45033-3-leo.izen@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230608142637.45033-1-leo.izen@gmail.com> References: <20230608142637.45033-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avformat/jpegxl_probe: check length instead of blindly reading 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: Michael Niedermayer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: LOjcLwN0SKrP From: Michael Niedermayer Enable the checked bitreader to avoid overread. Also add a few checks in loops and between blocks so we exit instead of continued execution. Alternatively we could add manual checks so that no overread can happen. This would be slightly faster but a bit more work and a bit more fragile Fixes: Out of array accesses Fixes: 59640/clusterfuzz-testcase-minimized-ffmpeg_dem_JPEGXL_ANIM_fuzzer-6584117345779712 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/jpegxl_probe.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c index 1d9c014f19..e15e9eee49 100644 --- a/libavformat/jpegxl_probe.c +++ b/libavformat/jpegxl_probe.c @@ -21,6 +21,7 @@ #include "jpegxl_probe.h" +#define UNCHECKED_BITSTREAM_READER 0 #define BITSTREAM_READER_LE #include "libavcodec/get_bits.h" @@ -293,6 +294,8 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid skip_bits_long(gb, 1); } } + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; if (!all_default) { jpegxl_skip_bit_depth(gb); @@ -307,6 +310,8 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid for (uint32_t i = 0; i < num_extra_channels; i++) { if (jpegxl_read_extra_channel_info(gb, validate_level) < 0) return -1; + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; } xyb_encoded = get_bits1(gb); @@ -336,8 +341,11 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid return -1; if (primaries == FF_JPEGXL_PR_CUSTOM) { /* ux/uy values for r,g,b */ - for (int i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21); + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; + } } } } @@ -363,10 +371,14 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid skip_bits_long(gb, 16 + 16 + 1 + 16); extensions = jpegxl_u64(gb); + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; if (extensions) { for (int i = 0; i < 64; i++) { if (extensions & (UINT64_C(1) << i)) jpegxl_u64(gb); + if (get_bits_left(gb) < 1) + return AVERROR_INVALIDDATA; } } } From patchwork Thu Jun 8 14:26:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42013 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp438662pzb; Thu, 8 Jun 2023 07:27:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4foCbaodaBy5S6Fy7eWgGqgr8FdPCJjQuP6tx0/IDrbHR0Bpjb6HF/h70eOlTBcaOlmTil X-Received: by 2002:a17:906:6a20:b0:96f:c988:941 with SMTP id qw32-20020a1709066a2000b0096fc9880941mr10372485ejc.15.1686234439626; Thu, 08 Jun 2023 07:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234439; cv=none; d=google.com; s=arc-20160816; b=dyLZ9clxUg1coA6mQFuN7tRWR0amxo+dkoCr0U1JBU2XNKeki75tjs6qotYD1vwfb/ q67ZW7++VdXWotQnssFAJIvb4Uv3aC6XnD+VPx+ymApomOAgtxyqc27SzmzJRKFLdBbk 5LTUTRYwpHpNl06KYbLNcHmLU+QRqtkBhscdeVvT4BTzgeS3auH3PoX6by2jBxPGKICw zSwE2RnYfdPKhKLGfELso0OvmYfclaVUJPSBSlzZZuDcaE2xR3drg1IPZIEA1aOcr6ld ZPwg143AoBeAMAHqRWIj92q21VFK8G/P9J6RTS+Vrf/auNGZ4z/Paitlmn5VpAcI6MAp uC5g== 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=RShdlyggciQJhgH26SivTIuQh+2CZ9ccJxG78I7XDsQ=; b=eC9ouje2zuylOqbkG5jlglY0jcsNVVhP2eltyK054zuhHAhfcyksdm3ZkBQNCkb0q9 PViLG6gTxPk5q/LOPsG0BoO5RzDkmsDe+FAjIpCkloDV53X+yxcmXXEcQBDeKAa6vjgQ 7ySNM0o3z/v9OBTipKS4HaviCKAZ0JRyIDHUoK2yqxg6JMX9wIVB7SJkOG7RbqRYpvJx S0VvW2R8kRafY0cU0LeRmfPCiBhqehBuz8p4BvHWlTilmKqgF7TwPxDHL6mSgB0p69Ti CiH2Kx31eqSpp+vj0lOZzN7zrkf+SdwS9gP1+hUXoNL/rF2LLQFkEpEHNUYSptyvsu+5 WGTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=dXiG3lRZ; 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 w11-20020a17090633cb00b00977e918b23fsi868365eja.449.2023.06.08.07.27.19; Thu, 08 Jun 2023 07:27:19 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=dXiG3lRZ; 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 6FAFA68A5D5; Thu, 8 Jun 2023 17:26:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42A2B68C2EE for ; Thu, 8 Jun 2023 17:26:42 +0300 (EEST) Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-bad035c71bfso56766276.0 for ; Thu, 08 Jun 2023 07:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686234401; x=1688826401; 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=v25hFjFTzwmi1f1DpHj4jeZvUbkBZwQsrUUFPOaJDh8=; b=dXiG3lRZs5a8q/l/MPAm8cQXOgRjmV9CsYgOM1+1G9QZb/YvEO15wvAh11Jt4QCQlm F5hNN0xhYpTv2CuJDFCKT+WpzDGlNZrTALRCPE1Q2AfwujVFK7kxkwfg7ygIsoQR2BIj Thx60neTfR4Sln1Oq5q7fynlL31Kfpw2qQG6QULoHTVBg1VR//f98UQYCLSiacJbAtuG nv37MYXsBIQB92xu7Qd8nfeFhEcTm5rSXA0Psaha6xcCFYRX92K03FiYFaPJRoYZMinl P7DyeFypKA7QcoIHyq+qVAfezjq9m20kCzEBrtGmluOCYjqlkeEhNnSelS+34Y6qJZ2N eMXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234401; x=1688826401; 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=v25hFjFTzwmi1f1DpHj4jeZvUbkBZwQsrUUFPOaJDh8=; b=kuqw/qeXxgj+ytyHMXdb+aU43R+nwqgpPr/NS9Dk2vAvd/KPwT7J+5Sp65et2zN3e/ orUzvaomTiSkIv3XxS6eGZICK2iSGn5sapIMoAvTfooC6Mfsk5QbT/X7IuDBgrZ5C/ky EXajo+BofiXY3DPCwY8lNhvzBDWWw/5SsynqtTU6x2B5CNzu1/x90tGMhWUESnEKmkBn IXWkYPV3LTKwNkfxki+tws6+eFJoCs3ukPMmQHVk/oL3527WkIYXDRdKFY9n73sDKRc7 QiqklB6OPTwzsaT0ZrnfjgFfOrn61fJbv1dvuqvtiXLRtsAf9f6slZySfwUgQxwIj4PK QPVA== X-Gm-Message-State: AC+VfDzOAdqgDkIrVKbzFhkNQZ9HAOsPlztg6P6Sr1Ck/RdXc0wXmqaQ fKvsgKAxdu9T5RUMs6/Qnn56B8w+eh8= X-Received: by 2002:a81:78cf:0:b0:565:a490:b417 with SMTP id t198-20020a8178cf000000b00565a490b417mr4245694ywc.0.1686234400908; Thu, 08 Jun 2023 07:26:40 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id b206-20020a0dd9d7000000b0056943d9cf8fsm414589ywe.9.2023.06.08.07.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:26:40 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Jun 2023 10:26:35 -0400 Message-Id: <20230608142637.45033-4-leo.izen@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230608142637.45033-1-leo.izen@gmail.com> References: <20230608142637.45033-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/jpegxl_probe: Forward error codes 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: Michael Niedermayer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dPq6zkutgIrf From: Michael Niedermayer Signed-off-by: Michael Niedermayer --- libavformat/jpegxl_probe.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c index e15e9eee49..88492cb772 100644 --- a/libavformat/jpegxl_probe.c +++ b/libavformat/jpegxl_probe.c @@ -261,8 +261,8 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) return -1; - if (jpegxl_read_size_header(gb) < 0 && validate_level) - return -1; + if ((ret = jpegxl_read_size_header(gb)) < 0 && validate_level) + return ret; all_default = get_bits1(gb); if (!all_default) @@ -281,8 +281,9 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid /* preview header */ if (get_bits1(gb)) { - if (jpegxl_read_preview_header(gb) < 0) - return -1; + ret = jpegxl_read_preview_header(gb); + if (ret < 0) + return ret; } /* animation header */ @@ -308,8 +309,9 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid if (num_extra_channels > 4 && validate_level) return -1; for (uint32_t i = 0; i < num_extra_channels; i++) { - if (jpegxl_read_extra_channel_info(gb, validate_level) < 0) - return -1; + ret = jpegxl_read_extra_channel_info(gb, validate_level); + if (ret < 0) + return ret; if (get_bits_left(gb) < 1) return AVERROR_INVALIDDATA; } From patchwork Thu Jun 8 14:26:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42014 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp438735pzb; Thu, 8 Jun 2023 07:27:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5v7lUHKd8BCeVjjj34is4XlilSuQ4ShZcrbpXkn5m2yyKoqacb06jTyaT9R/HkZbTH/lc9 X-Received: by 2002:a17:907:6e94:b0:96f:8ea4:a72c with SMTP id sh20-20020a1709076e9400b0096f8ea4a72cmr11063609ejc.62.1686234448415; Thu, 08 Jun 2023 07:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234448; cv=none; d=google.com; s=arc-20160816; b=w33B1v6aaj0Ny4s2hPbncM1pExEwpF3wtMsk2jiV2tBnflPuanj+VUlZkPsj2UQuRJ 7lUKkH6H+uG7ymoPwcuBXBEw1sUtu9vYWArMB20sNOoqp6SUeYvEpDpoUQY+VB2DH9DS 1RTUhK103iIRBSU7cgUErOrssr4xaJDy80tBKCZZ0OXPRm/pN2CJtEV3xAqqqK2bbzR3 keBJsdikt9vrAdOMSAvwA1YcrYubSeOgq2L0ULkI1tMY3XoZZPwMfYXNHVD/zHb3vtFM 3pG7K8wMh72yguM/eNpTQiEPFBw5n6kEYybz98ad2fu/+Oi7M8T2eZ3pQgwy61c1YyWX ZD4w== 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=q4N4EtVZDkqAW7/TNN8Pm4FP36czhqnq5PWud2pWHuI=; b=kRsSpMc+SsTeC8O9gvMKYwBofvqcRFvGebrPu1oHD+T4QB0ZjpF+PqQ2WEvNB9Ldkz kK4JvCrgdRsEmPO2KQvwS6hru4IidZtXVnf3K5tluHsB12acMvFaCdWMLETDqj0pufiA bYliX+kKEFiTS0xjZZR1WnzsNY+yYcKMRPWnkgXg6U+g1UPZoHDuKzTw72/7umMwqSFZ wEOcPE0/PgiOyi2C+FujY2wVe81u5aVOo0BxyiWqZk4Cy1PyIpjkwNskHl+GxNKR/NFB GMJ8bkm0QZTuczwShEajUn9R19yPbW1rPAltWK+dJ+eDQA/AAkcqNj50ZbRRY7lA7eyF ct9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=WiPzql+D; 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 n9-20020a1709065e0900b0096f231529f1si910266eju.870.2023.06.08.07.27.27; Thu, 08 Jun 2023 07:27:28 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=WiPzql+D; 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 6E4D668BE58; Thu, 8 Jun 2023 17:26:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D92268C2F9 for ; Thu, 8 Jun 2023 17:26:43 +0300 (EEST) Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-1a2dd615ddcso69408fac.0 for ; Thu, 08 Jun 2023 07:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686234401; x=1688826401; 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=aKjjomk+rFdZumIhKTMn58gtiv3m+nosMe55iQbYEiw=; b=WiPzql+DytYPNy5hyp4TyZZysHd6JGgz9JBHjX8/Ycn3SI9w1MmB8qiFCCDdvIAfks 1l9swQNoTC+Cb+KyQckleaJOCcXkVRFJeISaVKDXnA9prJRxbx3cx9y9ffJBoUAuB1Yg +lsLauSCMBu0uyVqTbyRMSbF85XVFag1C6qntu+Ve8YmhbjgZi4l6BG32IYoui5R5A4U yMuiAz+aykIJsNzsrQveKtsHSqCP7z1V56yfFJ4bZIYJjuioFXAWQ+kLGjxDMMx1UArf WLUThN+LIIH1GDDyh7Owz9g3m+FtNA7z/vbjJgGIxUVzyo0CpVk+2YMQThdGthFfqC2w rylQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234401; x=1688826401; 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=aKjjomk+rFdZumIhKTMn58gtiv3m+nosMe55iQbYEiw=; b=QaHH8I2Rnuh0FcrsZZKnyyHkECsACfUuHvVq8NZyQ10igBOyexJGxFuGOv3TWIuNnW 2svRJW0jOc9lQJQVNL7DxKIOgpKKno+JskpgtueDQuov3petnheAy4N6wSSvHG/8uQ/H G5v6jj72UoBBPtTdvQ92OSZX2zzpWt+RVAA6W4IlGSizPQCMTb2e/2JZ7x6TJFB0OWQC lPYbyT3tnTLMmzUoU5Mw/qD4z6veGOgZ9gTUW1bd7C1wSIIzGw5wis1fJeIAbuY4HzfU clJ5NKnUi5sw/du4uC9iekyf8YkeE/mE0+TBfpEhKh0XnUaA9j637O46r3S/pK9k+D9q NSzA== X-Gm-Message-State: AC+VfDwtfbIaRJOAs9/4yePDBb0hUFAhVWx87X/+uvFsxipwT0xhD10S tYvWKe4wPQpkrdrK7zJgUgCACbdBcNo= X-Received: by 2002:a05:6870:1694:b0:192:aa8c:e385 with SMTP id j20-20020a056870169400b00192aa8ce385mr3966804oae.5.1686234401611; Thu, 08 Jun 2023 07:26:41 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id b206-20020a0dd9d7000000b0056943d9cf8fsm414589ywe.9.2023.06.08.07.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:26:41 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Jun 2023 10:26:36 -0400 Message-Id: <20230608142637.45033-5-leo.izen@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230608142637.45033-1-leo.izen@gmail.com> References: <20230608142637.45033-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avformat/jpegxl_probe: inline various ret < 0 checks 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: liHUP1vs27DZ Inlines some ret < 0 checks to look like: if ((ret = func()) < 0) return ret; which clarifies code slightly. Signed-off-by: Leo Izen --- libavformat/jpegxl_probe.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c index 88492cb772..b4ab45518a 100644 --- a/libavformat/jpegxl_probe.c +++ b/libavformat/jpegxl_probe.c @@ -254,8 +254,7 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid uint64_t extensions; int ret; - ret = init_get_bits8(gb, buf, buflen); - if (ret < 0) + if ((ret = init_get_bits8(gb, buf, buflen)) < 0) return ret; if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) @@ -281,8 +280,7 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid /* preview header */ if (get_bits1(gb)) { - ret = jpegxl_read_preview_header(gb); - if (ret < 0) + if ((ret = jpegxl_read_preview_header(gb)) < 0) return ret; } @@ -309,8 +307,7 @@ int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid if (num_extra_channels > 4 && validate_level) return -1; for (uint32_t i = 0; i < num_extra_channels; i++) { - ret = jpegxl_read_extra_channel_info(gb, validate_level); - if (ret < 0) + if ((ret = jpegxl_read_extra_channel_info(gb, validate_level)) < 0) return ret; if (get_bits_left(gb) < 1) return AVERROR_INVALIDDATA; From patchwork Thu Jun 8 14:26:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 42015 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp438863pzb; Thu, 8 Jun 2023 07:27:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qbvSN2DF2JvhXWrV66Y1FhEUltmg5Wq+FW3e8w3ibaDP/GoRaHEZdgFqY8mqzciwiwQ8c X-Received: by 2002:a17:907:8a05:b0:973:c070:1b5f with SMTP id sc5-20020a1709078a0500b00973c0701b5fmr9713910ejc.44.1686234457172; Thu, 08 Jun 2023 07:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234457; cv=none; d=google.com; s=arc-20160816; b=dGWgKkeNvRwfcgaT2Cltyp1YXmnN1J7DRsT9KD4BPma/md8Rs0TA08VfavAAb/BCa0 gIIRUb7ybVqYA4dYAexnQaDq29GJjwi19s/utMSWctSFEyC4Z9iCOIhERjkxenw5uYxB q7iFpE6tL+pESPgS7moYh3mXIoOKdLoVjk3DXv49vJom+QqY7XXmNnx6atzyEPRumrum AUjwNfXLypIONSwE15zGnAu33BN+VscvQ4jCYpAVyQc4ig5AHHb+9zhCaJFKw353ce21 jEW+T2JbWrWYVehukHouGxtkWpfKeI7wDWOtKmk7hQZWhiI73p6iqAq8onnsXk2V9LvS ihUQ== 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=iOv2kMWbQdbXlLOwbXeS5DwA8RQCj6g48dvboqUMBE4=; b=Cbo0mzyJn2su89ywhB3UXQlk+ieoAC4cpNDaLVhT32nC9X0VFX3pztWTfzWtXYn1xb LiuyrnVWxLfHQ7zA9TxSLjh1Bd2HmQfxeStTx4gua4D9GV0FmW/pQ0dIp5WTr0qO98ne njd7Ptotbwn45sA3VW3/I+ELvv0uw3Fd7rJ9O+31vqLCaXJ1yQllxDr5AWj8lBFy4viu Rz7ofUeI1ahZ4OCml6VFaMrv5KM1Svep5cYFfb+Vgr49HTn7Ii2Ybw10PHkhYFaVci0R L60ahfUyFuqmGAPzZEEr+Tk8ipbRKfbtYEa/PEHNw5s/lS0qTUZHvM2Qz4mR97otmqDh AQKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=GFsJwT1R; 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 v23-20020aa7cd57000000b00514a0ec9898si798018edw.341.2023.06.08.07.27.36; Thu, 08 Jun 2023 07:27:37 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=GFsJwT1R; 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 441FB68C312; Thu, 8 Jun 2023 17:26:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED0E068C31C for ; Thu, 8 Jun 2023 17:26:43 +0300 (EEST) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-1a2dd615ddcso69412fac.0 for ; Thu, 08 Jun 2023 07:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686234402; x=1688826402; 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=qH7qDCfOBbDDfJXOtXNxTIYw4pquCnC4jVw/+w4a5EA=; b=GFsJwT1RKQORR4zsMNj6HnehlNdUCwXSdDWjRARvWl404ctxnQ9T8Nh+M6dR+zPwky VZgRIwPEYRB0obDDtwPEjuPvrMpUmS23qHSgG+4ydeVCySL30BE3YbnrtM+yPqizBUqP ldez7GZEkzWOgNiUc8pxJkIuowJ4mEeYRc2eGFF9LCYPpGm0wbsJft8X8l9RDfdIZo7s NgSJkM8aU/SJuIUWY2U7RDyIuOcGpFltpWo1SZlztRE83TcOy5URZOd3Vf/T5oESdw4l O8NacHlxjUU6av13/qk6zjsPA1f22/Y2sAGE30JWRKKcHJgrTVDrIEzXGW2+tTRvlpJg VcUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234402; x=1688826402; 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=qH7qDCfOBbDDfJXOtXNxTIYw4pquCnC4jVw/+w4a5EA=; b=FW5F6XfQE+9HsLb62owPS2ZVCAt5esNgCbd7VnmYSyOjahz4tu/899HOiTjcjSKKBv kazLuyqOoY//kBclQgTyrll2kY94nuk5OJ4u7cpCfN4SqbSfsulXTXByT3mi80TajvnJ p9HHYNGdt4Qcd4fVAgjjNNxy4WETIOQQKjjpYXhJ7xxJgNilBRamTirb5s2faj7jQu+9 +iz/WVYIyFBLzvUDeVChW3317cBfc+c4a6eoRR3YLz++4ivBHwEvu+h7EZNVr48Vd1Pb 1WXNKXk7BaqM/5MjIGXreKVUQ8hAOeSIJDMxoLPUYPZMb2dpvZdLKWUgpy6qe2B/RVLA wkYg== X-Gm-Message-State: AC+VfDyOWXtZjyQlIiRiAKJ53Uw044mwHeHltXHoGESI4u+LDTWx7Kic YV7xhQeAP0zxOw8MvLQ/dkhoUYTSCSU= X-Received: by 2002:a05:6870:f5aa:b0:19f:5cb8:b5fa with SMTP id eh42-20020a056870f5aa00b0019f5cb8b5famr4150010oab.3.1686234402239; Thu, 08 Jun 2023 07:26:42 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id b206-20020a0dd9d7000000b0056943d9cf8fsm414589ywe.9.2023.06.08.07.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:26:42 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Jun 2023 10:26:37 -0400 Message-Id: <20230608142637.45033-6-leo.izen@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230608142637.45033-1-leo.izen@gmail.com> References: <20230608142637.45033-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avformat/jpegxl_anim_dec: avoid overrun with jxlp boxes in container 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: 1pnFBwL6PKpj This should avoid overrunning buffers with jxlp boxes if the size is zero or if the size is so small the box is invalid. Signed-off-by: Leo Izen --- libavformat/jpegxl_anim_dec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c index 6ea6c46d8f..c9e4dcd5fc 100644 --- a/libavformat/jpegxl_anim_dec.c +++ b/libavformat/jpegxl_anim_dec.c @@ -76,8 +76,14 @@ static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int inp tag = AV_RL32(b); b += 4; if (tag == MKTAG('j', 'x', 'l', 'p')) { + if (b - input_buffer >= input_len - 4) + break; b += 4; - size -= 4; + if (size) { + if (size < 4) + return AVERROR_INVALIDDATA; + size -= 4; + } } if (tag == MKTAG('j', 'x', 'l', 'c') || tag == MKTAG('j', 'x', 'l', 'p')) {