aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2023-06-15 11:34:22 -0700
committerCosmin Truta <ctruta@gmail.com>2023-06-20 19:20:38 +0300
commit8be5c147d567bf90553088305208e612abb16768 (patch)
treebd6778500209cdcae339fb62b727dec8c5ba883c
parentf7abe3c4199a0fd98f62193ed2cb5337ae44959b (diff)
downloadlibpng-8be5c147d567bf90553088305208e612abb16768.tar.gz
Don't report a valid tRNS chunk if it was canceled
Add special handling of the PNG_INFO_tRNS flag to png_get_valid() to not report a canceled tRNS chunk as valid. Fix https://github.com/glennrp/libpng/issues/482 Signed-off-by: Cosmin Truta <ctruta@gmail.com>
-rw-r--r--AUTHORS1
-rw-r--r--pngget.c13
2 files changed, 13 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 350a2de5d..60f41e5c6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -41,6 +41,7 @@ Authors, for copyright and licensing purposes.
- Matt Sarett
- Mike Klein
- Sami Boukortt
+ - Wan-Teh Chang
The build projects, the build scripts, the test scripts, and other
files in the "ci", "projects", "scripts" and "tests" directories, have
diff --git a/pngget.c b/pngget.c
index e44933c0d..1490a032e 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,7 +1,7 @@
/* pngget.c - retrieval of values from info struct
*
- * Copyright (c) 2018 Cosmin Truta
+ * Copyright (c) 2018-2023 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -21,7 +21,18 @@ png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_uint_32 flag)
{
if (png_ptr != NULL && info_ptr != NULL)
+ {
+#ifdef PNG_READ_tRNS_SUPPORTED
+ /* png_handle_PLTE() may have canceled a valid tRNS chunk but left the
+ * 'valid' flag for the detection of duplicate chunks. Do not report a
+ * valid tRNS chunk in this case.
+ */
+ if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0)
+ return(0);
+#endif
+
return(info_ptr->valid & flag);
+ }
return(0);
}