From patchwork Fri Jul 12 19:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 50513 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2298:b0:482:c625:d099 with SMTP id fp24csp1022714vqb; Fri, 12 Jul 2024 12:11:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVVweYdojLrIAxx7bxxqEGCjAKN/EFrexDyexIkSzNbS417Lxi9eI/Q7Dorb8SCaByH0wdOEDregG62lCf1uQ0wR+S0rEmqezvO7A== X-Google-Smtp-Source: AGHT+IEWntXZwxYjN/+urFFPFcNU1KuhdIytmwTQ5lSupIgvDBfOWsSzgPOzmUNxliqpmCZDRM4G X-Received: by 2002:a2e:880a:0:b0:2ec:5fa1:2434 with SMTP id 38308e7fff4ca-2eeb30bbad9mr78863241fa.9.1720811506617; Fri, 12 Jul 2024 12:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720811506; cv=none; d=google.com; s=arc-20160816; b=sy7vsK+1Qa6+Hllr51hK/E15We3u52ppej3D5J3sKm14jiTVJXx+QT0nH3OOuzd9m5 qNG/i3GnZx3Wk3Z48iwxwwpc/w7LRGzgGerBzUm5UKr2BVvuzkLWWT2zSTUT2ssbVPTZ DuHY4uuR1olmiz9TqmlnEetU/wcW8M0Dg5RIVFgDue6oylXz7JvAdSCW2/tDW9NZ1P2E Pwnd4Ng3GTrZvcGdutowWYGw601MlNr/2we46sOHwvnZDZ59wkh+fP+HLzbMohMA2HFA PzXxzhbVo/XFbi1MxfvM+r3RuMkcciFSddQ3diefU4reVzOyy2J75gJaGkAIO19dTxm6 il5A== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=c7f1NWzJavmGUUYjHNX6T4uhntuEWIyxc3cSgjzHrd0=; fh=wbRw4dmpm5HLdLOi49E3B1xR6OR4JvuzzqZfDAQQ2R4=; b=kapBMvBrM3SMIFWFGR7X3GbPzJT6C5GtiFgXU5/V8aHroAYZ0OdEooDC4odT8/RpyB wjjeIL+3lgOWR4El5N6H19EU0ByXwNycRpDKN9l4DXN5VUTlYZYI3GzWVdiwnM4a13hw CreLMnEI+nQvOf2R3I9E4VtULJZsXrLbd7uIiXz73jStwoKWnh6ZxmqGkSvJ+825o07j WSOCMN7Yuz/nKqC3IhElk+u5DLcAuIgzXe0HrdxIAQNZeBFzJpT+5fMLniKBWNeUZmBq IiH6u9iLuMLcFZ0Wc8RlASFHd9c7AJFshtcg4XAu+VxAU665Z4bij2J34NwNDWdEtw7c geYw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=T1D8X6rY; 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 38308e7fff4ca-2eeb348a17csi22945461fa.379.2024.07.12.12.11.46; Fri, 12 Jul 2024 12:11:46 -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=20230601 header.b=T1D8X6rY; 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 6C14F68D843; Fri, 12 Jul 2024 22:03:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1820368D830 for ; Fri, 12 Jul 2024 22:03:21 +0300 (EEST) Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3d5657327c1so126232b6e.1 for ; Fri, 12 Jul 2024 12:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720810999; x=1721415799; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XwFUeeBL0pQ8vSr6cP3yoFLKJlSd5qXQQuVp7DZ+jdE=; b=T1D8X6rYhsssi0m63qhrFLXeYoFyByVXpsnBn7mxnOUGQZObnUDV1cIWm7tOBb7XAk j/5nqcfBo2t/Tryf/aif7kOun6299iP/aEqec0vpLmaS+YRdWEpRUDQp73aZOaa9jQ0x 9HAa0LAo+pwqMPuqy+SkS4BnbqeZtOiC+iVq+amtbwWbD6+rRon3zwY7mcLZuu/QP4Hy 48rVcfirIPuIsxtBvHZK+kO2B79Ieqmi4W57Ey2pqpikhJlDbNC2VyWlpYPYAo9owPEm E9VziE4qrigVdY/u2lVJh1sANMQjeca27q6PzqXIyCnR1X/vLDkYnrp+BUKBUDp605RH Vxhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720810999; x=1721415799; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XwFUeeBL0pQ8vSr6cP3yoFLKJlSd5qXQQuVp7DZ+jdE=; b=bxP2mu0cb8jwCsEI7e8qoa/hUWvjDYcP/93eTNSetlQ8kgW6taVdeoFf243kcO6Rie KIePIuTi01+w539Uf/JmT30qQ1m4eGdGWW0tdwqy3VVcn/hbRv87eYY/VUi+2HnGpKhw XRK/zsOSeTpRcye9RF/c7l1+GEWX1MiQAz00ko9Fr1kySoCyzPDAcrH/ld8qe9RwAgVp MBw3ril36neJNrWG5urImctDMwCu30sPzNj2m0I0GYyp9KEgO+irABiU43XbWvDLwEtJ bb2yUb2PGcd5DUFyinjvacopwu+p1VlUpBuKhO55/IFBc/HHJivwPt8SYolbVll53P/i XN+Q== X-Gm-Message-State: AOJu0YynbHu77FovmIA79mri90hO79I23YL9T+6ilsQ5qWRrt3aCUtnj BAvG+g9S57oIgcxZHywIxva1Jv0nuM87ZZNGGm8StVYI2ESY9TPdfN5kAw== X-Received: by 2002:a05:6830:63c1:b0:708:b80d:f3f with SMTP id 46e09a7af769-708b80d1cb2mr1744841a34.4.1720810999254; Fri, 12 Jul 2024 12:03:19 -0700 (PDT) Received: from gauss.local (c-68-56-149-176.hsd1.mi.comcast.net. [68.56.149.176]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-447f9bd266fsm43447141cf.77.2024.07.12.12.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 12:03:18 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Jul 2024 15:03:16 -0400 Message-ID: <20240712190317.294917-1-leo.izen@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/pngdec: avoid erroring with sBIT on indexed-color images 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: Ramiro Polla , Leo Izen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AYPUDeJ7iUrw Indexed color images use three colors for sBIT, but the function ff_png_get_nb_channels returns 1 in this case. We should avoid erroring out on valid files in this scenario. Signed-off-by: Leo Izen Reported-by: Ramiro Polla --- libavcodec/pngdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 180806e5e1..b0d02c97dd 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1084,7 +1084,7 @@ static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_INVALIDDATA; } - channels = ff_png_get_nb_channels(s->color_type); + channels = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type); if (bytestream2_get_bytes_left(gb) != channels) return AVERROR_INVALIDDATA; From patchwork Fri Jul 12 19:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 50514 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2298:b0:482:c625:d099 with SMTP id fp24csp1027205vqb; Fri, 12 Jul 2024 12:21:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXiktyzM5zcETJhwbJlzrmm7Ytt+bUZpZ7gNroF/cBSVhDXSj5nB9E2nMfp4zU1utpU1i63yZYnmsw1MZJWwTe96dyl3NxxlfbHvA== X-Google-Smtp-Source: AGHT+IFPXqxHI0hm3X/dOl7Mz/omrazONzF43r8o7wmyr9x77HSwKkzOIkEhkzYjXnS5Z8TR4V2c X-Received: by 2002:a2e:8710:0:b0:2ee:6cda:6380 with SMTP id 38308e7fff4ca-2eeb30e3cbbmr82500271fa.18.1720812111023; Fri, 12 Jul 2024 12:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720812111; cv=none; d=google.com; s=arc-20160816; b=hvCMlm7qpHVG319aRq183HwWQx72GPclJCbO+pQBacnolpRiYoU6zFGHeJ3fhYjVki P7YPQj8zYdYX5wqrEa4ARIq/3WAjFM32LsnrG2NKraUDE9nxg67ocEhyW6g8fL/BAUZY SwppFcaOEseZAYphzWo5t5nTcltNF2wVNchTvCAKi95WCmd0g2MBVC3GWkjUVrnNaxAh AP7fDjky+6teozcqg3uq6SOrTqsV8lxOpAPDW+BzVqCknfRJ6sKzE8sQ8EBZ2wM5WjLD EK/zRIvoY1EEYiZlBZUnArweTQQ5OCgOVrDOEopRxbDZaKhIIV9aabjo6EYi9wXIo6a9 Si2Q== 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=sskqIk1UaLlx3PeEZAMyNn4/EqQqyVtbMIIt9xJCIec=; fh=+bdjGe20eEUjtjncwA1dnEEVYNfJL4vyhV+sIRR4l+g=; b=LKW36A20cbxaJ3VI0BXT3BRfY5PTZhe9TdTWDWT0PH8TLd5/JL6SxE9xgdLbjjUmZk WBb8LKoq/Zsgv4fH2Cfgj/P8KOZe8Umol3iTZKXElS7VLLXgxFcan6bm0JIG/AntQQx5 ZAHZH/ryWvg/IhfKjVCaIRBb0CI3slS7LHM/9UWb/L9iH1awNlG/9UOiKWvUv0FxukQ8 UpqWyskBzjFi2UxDN/TIJB6iFxRe27nguGs7QsK5dI18Rywcf7iacMdKmksr1spzBmrn y+ZxgoWt7LhbKhI+eLJH44s/2tMfnANY0rafxkF+CvhGY/CG/sDKt8Bn4HfEsYYzvRLk Eiew==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=XJK+1MMH; 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 38308e7fff4ca-2eeb348c10dsi23982471fa.395.2024.07.12.12.21.47; Fri, 12 Jul 2024 12:21:50 -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=20230601 header.b=XJK+1MMH; 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 C330B68DADB; Fri, 12 Jul 2024 22:03:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 48BB968D830 for ; Fri, 12 Jul 2024 22:03:21 +0300 (EEST) Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-44e19c8bf96so160151cf.2 for ; Fri, 12 Jul 2024 12:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720811000; x=1721415800; 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=TXnqrPOc/9x490ugY3dI/gSeA08kyT8CMmkMPqHaXRo=; b=XJK+1MMHEvJOvqISH9pmJOj8fjOg0X89vOQsgo0EzDGSNNFl4KQU3Bv6hh1YGw5a8U E1J15krrfneww5xA6gERp8q6e9oGaaijZQt5+geuUY0Gdx9NHx6fwQUEGZuln3L8VVp+ P41RZKB8yN9y/xG8Sm8suq+ZqSmRSuNCavjEBuR/sEe/L47betqCCqYkuMFn0ytO+9vX OKMzuOsVg4/1bRKdaq/Nwxht8dhhc7S7Ffl/k6Nplwtfbw+jfZo0E3AfNJrTyIpWIEvs +vsN/FdzeZCRDsZL1X/BMMjFFzuFYVr6uaJi+p4yRFBw2zuMF5Mx7qDjLNn55rw7XmaS km3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720811000; x=1721415800; 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=TXnqrPOc/9x490ugY3dI/gSeA08kyT8CMmkMPqHaXRo=; b=p+kKOULaMWiMJyz5a/rYLOgEfE1AR5vj6s0WsKedMH+XJq2HZGBSQM/NJw2ItitoaN Loegwzi4Mhwr8bqzXkRi7IJyG5bRKP8n0ZJRlRUmepEtfPv0tDCyWlL4mz3ov8JyfsxP TONpT7ZZzzT5MruZna2IUz/JU/2VeefTRUhdz/eJ/xtbhdUkZHqe9DTthCTcc4aM+GBA 17SBUxZMUXQcvDr+OElbhgCOt/xTG83uLHVHf1sW15WHwgr5mhPtcvufDM3yX7ISHs9L uyINOF4IR5kkCv6GSMAFVfMtxRd6Wkqyah5TfGz693DWhGKKBXvklqtXuvrWxHMp6TnH EkQg== X-Gm-Message-State: AOJu0Yw+xnOYw1gjNW3MeGDckxvBJGkFOc/3E3jroCNMQhyDzxWfFrm4 eABjpIw/wL3K0I9cO3UFmUgg/Qtx+RpJkMKgZXGUaRCmAw/B7m8e15qNlg== X-Received: by 2002:ac8:4c81:0:b0:447:f8ba:950d with SMTP id d75a77b69052e-44cfe9ae673mr52276071cf.5.1720810999923; Fri, 12 Jul 2024 12:03:19 -0700 (PDT) Received: from gauss.local (c-68-56-149-176.hsd1.mi.comcast.net. [68.56.149.176]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-447f9bd266fsm43447141cf.77.2024.07.12.12.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 12:03:19 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Jul 2024 15:03:17 -0400 Message-ID: <20240712190317.294917-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712190317.294917-1-leo.izen@gmail.com> References: <20240712190317.294917-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/png: more informative error message for invalid sBIT size 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: OsOcqHzRD/qK If the sBIT chunk size is invalid, we should print a more informative error message rather than return an error and print nothing. Signed-off-by: Leo Izen --- libavcodec/pngdec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index b0d02c97dd..cb861e5f60 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1086,8 +1086,11 @@ static int decode_sbit_chunk(AVCodecContext *avctx, PNGDecContext *s, channels = s->color_type & PNG_COLOR_MASK_PALETTE ? 3 : ff_png_get_nb_channels(s->color_type); - if (bytestream2_get_bytes_left(gb) != channels) + if (bytestream2_get_bytes_left(gb) != channels) { + av_log(avctx, AV_LOG_ERROR, "Invalid sBIT size: %d, expected: %d\n", + bytestream2_get_bytes_left(gb), channels); return AVERROR_INVALIDDATA; + } for (int i = 0; i < channels; i++) { int b = bytestream2_get_byteu(gb);