[packages/libpng12] Rel 3. Backport libpng 1.6 security fixes for the 1.2 line.

arekm arekm at pld-linux.org
Sat Nov 28 17:52:52 CET 2026


commit a432c231efb61ed438c337b3a146b2505f5f227c
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Fri Nov 27 16:25:09 2026 +0100

    Rel 3. Backport libpng 1.6 security fixes for the 1.2 line.
    
    Fixes CVE-2026-34757, CVE-2026-33416, CVE-2026-25646,
    CVE-2025-64505.

 libpng12-CVE-2025-64505.patch |  14 +++
 libpng12-CVE-2026-25646.patch |  14 +++
 libpng12-CVE-2026-33416.patch | 193 ++++++++++++++++++++++++++++++++++++++++++
 libpng12-CVE-2026-34757.patch |  65 ++++++++++++++
 libpng12.spec                 |  16 +++-
 5 files changed, 298 insertions(+), 4 deletions(-)
---
diff --git a/libpng12.spec b/libpng12.spec
index 0adadda..ffc58bb 100644
--- a/libpng12.spec
+++ b/libpng12.spec
@@ -2,7 +2,7 @@ Summary:	PNG library version 1.2.x
 Summary(pl.UTF-8):	Biblioteka PNG w wersji 1.2.x
 Name:		libpng12
 Version:	1.2.59
-Release:	2
+Release:	3
 Epoch:		2
 License:	distributable
 Group:		Libraries
@@ -15,6 +15,10 @@ Patch3:		libpng-export_old.patch
 Patch4:		libpng-revert.patch
 Patch5:		http://downloads.sourceforge.net/libpng-apng/libpng-%{version}-apng.patch.gz
 # Patch5-md5:	d8cea50b4e4b248391d26b14f3d5dfd2
+Patch6:		libpng12-CVE-2026-25646.patch
+Patch7:		libpng12-CVE-2025-64505.patch
+Patch8:		libpng12-CVE-2026-33416.patch
+Patch9:		libpng12-CVE-2026-34757.patch
 URL:		http://www.libpng.org/pub/png/libpng.html
 BuildRequires:	rpmbuild(macros) >= 1.213
 BuildRequires:	tar >= 1:1.22
@@ -83,6 +87,10 @@ xzcat -dc %{SOURCE0} | tar xf - -C ..
 %patch -P3 -p1
 %patch -P4 -p1
 %patch -P5 -p1
+%patch -P6 -p1
+%patch -P7 -p1
+%patch -P8 -p1
+%patch -P9 -p1
 
 %build
 %configure
@@ -117,15 +125,15 @@ rm -rf $RPM_BUILD_ROOT
 %doc ANNOUNCE CHANGES KNOWNBUG README LICENSE
 %attr(755,root,root) %{_libdir}/libpng12.so.*.*.*
 %attr(755,root,root) %{_libdir}/libpng.so.*.*.*
-%attr(755,root,root) %ghost %{_libdir}/libpng12.so.0
+%ghost %{_libdir}/libpng12.so.0
 # alternative soname (symlink in PLD, so must be packaged)
-%attr(755,root,root) %{_libdir}/libpng.so.3
+%{_libdir}/libpng.so.3
 
 %files devel
 %defattr(644,root,root,755)
 %doc *.txt
 %attr(755,root,root) %{_bindir}/libpng12-config
-%attr(755,root,root) %{_libdir}/libpng12.so
+%{_libdir}/libpng12.so
 %{_pkgconfigdir}/libpng12.pc
 %{_includedir}/libpng12
 
diff --git a/libpng12-CVE-2025-64505.patch b/libpng12-CVE-2025-64505.patch
new file mode 100644
index 0000000..7c8a2c4
--- /dev/null
+++ b/libpng12-CVE-2025-64505.patch
@@ -0,0 +1,14 @@
+# png_set_dither: size dither_index for 256 entries, malformed images index past num_palette (upstream 6a528eb, Fedora libpng-1.2-CVE-2025-64505.patch)
+--- a/pngrtran.c
++++ b/pngrtran.c
+@@ -176,8 +176,8 @@
+       int i;
+ 
+       png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
+-         (png_uint_32)(num_palette * png_sizeof(png_byte)));
+-      for (i = 0; i < num_palette; i++)
++         (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_byte)));
++      for (i = 0; i < PNG_MAX_PALETTE_LENGTH; i++)
+          png_ptr->dither_index[i] = (png_byte)i;
+    }
+ 
diff --git a/libpng12-CVE-2026-25646.patch b/libpng12-CVE-2026-25646.patch
new file mode 100644
index 0000000..f41fd24
--- /dev/null
+++ b/libpng12-CVE-2026-25646.patch
@@ -0,0 +1,14 @@
+# png_set_quantize: use original palette indices in the distance hash (upstream 01d03b8, Fedora libpng-1.2-cve-2026-25646.patch)
+--- a/pngrtran.c
++++ b/pngrtran.c
+@@ -371,8 +371,8 @@
+                      if (t == NULL)
+                          break;
+                      t->next = hash[d];
+-                     t->left = (png_byte)i;
+-                     t->right = (png_byte)j;
++                     t->left = png_ptr->palette_to_index[i];
++                     t->right = png_ptr->palette_to_index[j];
+                      hash[d] = t;
+                   }
+                }
diff --git a/libpng12-CVE-2026-33416.patch b/libpng12-CVE-2026-33416.patch
new file mode 100644
index 0000000..101683f
--- /dev/null
+++ b/libpng12-CVE-2026-33416.patch
@@ -0,0 +1,193 @@
+# stop aliasing palette/trans between png_struct and png_info (upstream d5515b5 et al., Fedora libpng-1.2-CVE-2026-33416.patch)
+--- a/pngread.c
++++ b/pngread.c
+@@ -1372,26 +1372,18 @@
+    png_free(png_ptr, png_ptr->gamma_from_1);
+    png_free(png_ptr, png_ptr->gamma_to_1);
+ #endif
+-#ifdef PNG_FREE_ME_SUPPORTED
+-   if (png_ptr->free_me & PNG_FREE_PLTE)
+-      png_zfree(png_ptr, png_ptr->palette);
+-   png_ptr->free_me &= ~PNG_FREE_PLTE;
+-#else
+-   if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
+-      png_zfree(png_ptr, png_ptr->palette);
+-   png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
+-#endif
++   /* png_ptr->palette is always independently allocated (not aliased
++    * with info_ptr->palette), so free it unconditionally.
++    */
++   png_free(png_ptr, png_ptr->palette);
++   png_ptr->palette = NULL;
+ #if defined(PNG_tRNS_SUPPORTED) || \
+     defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+-#ifdef PNG_FREE_ME_SUPPORTED
+-   if (png_ptr->free_me & PNG_FREE_TRNS)
+-      png_free(png_ptr, png_ptr->trans);
+-   png_ptr->free_me &= ~PNG_FREE_TRNS;
+-#else
+-   if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
+-      png_free(png_ptr, png_ptr->trans);
+-   png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
+-#endif
++   /* png_ptr->trans is always independently allocated (not aliased
++    * with info_ptr->trans), so free it unconditionally.
++    */
++   png_free(png_ptr, png_ptr->trans);
++   png_ptr->trans = NULL;
+ #endif
+ #ifdef PNG_READ_hIST_SUPPORTED
+ #ifdef PNG_FREE_ME_SUPPORTED
+--- a/pngrtran.c
++++ b/pngrtran.c
+@@ -471,7 +471,13 @@
+    }
+    if (png_ptr->palette == NULL)
+    {
+-      png_ptr->palette = palette;
++      /* Allocate an owned copy rather than aliasing the caller's pointer,
++       * so that png_read_destroy can free png_ptr->palette unconditionally.
++       */
++      png_ptr->palette = (png_colorp)png_calloc(png_ptr,
++          PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
++      png_memcpy(png_ptr->palette, palette, (unsigned int)num_palette *
++          png_sizeof(png_color));
+    }
+    png_ptr->num_palette = (png_uint_16)num_palette;
+ 
+@@ -1208,6 +1214,17 @@
+ {
+    png_debug(1, "in png_read_transform_info");
+ 
++   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
++       info_ptr->palette != NULL && png_ptr->palette != NULL)
++   {
++      /* Sync info_ptr->palette with png_ptr->palette, which may
++       * have been modified by png_init_read_transformations
++       * (e.g. for gamma correction or background compositing).
++       */
++      png_memcpy(info_ptr->palette, png_ptr->palette,
++          PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
++   }
++
+ #ifdef PNG_READ_EXPAND_SUPPORTED
+    if (png_ptr->transformations & PNG_EXPAND)
+    {
+--- a/pngset.c
++++ b/pngset.c
+@@ -475,10 +475,6 @@
+       }
+    }
+ 
+-   /* It may not actually be necessary to set png_ptr->palette here;
+-    * we do it for backward compatibility with the way the png_handle_tRNS
+-    * function used to do the allocation.
+-    */
+ #ifdef PNG_FREE_ME_SUPPORTED
+    png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
+ #endif
+@@ -486,12 +482,32 @@
+    /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
+     * of num_palette entries, in case of an invalid PNG file or incorrect
+     * call to png_set_PLTE() with too-large sample values.
++    *
++    * Allocate independent buffers for info_ptr and png_ptr so that the
++    * lifetime of png_ptr->palette is decoupled from the lifetime of
++    * info_ptr->palette.  Previously, these two pointers were aliased,
++    * which caused a use-after-free vulnerability if png_free_data freed
++    * info_ptr->palette while png_ptr->palette was still in use by the
++    * row transform functions (e.g. png_do_expand_palette).
++    *
++    * Both buffers are allocated with png_calloc to zero-fill, because
++    * the ARM NEON palette riffle reads all 256 entries unconditionally,
++    * regardless of num_palette.
+     */
++   png_free(png_ptr, png_ptr->palette);
+    png_ptr->palette = (png_colorp)png_calloc(png_ptr,
+-      PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
+-   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
+-   info_ptr->palette = png_ptr->palette;
+-   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
++       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
++   info_ptr->palette = (png_colorp)png_calloc(png_ptr,
++       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
++   png_ptr->num_palette = info_ptr->num_palette = (png_uint_16)num_palette;
++
++   if (num_palette > 0)
++   {
++      png_memcpy(info_ptr->palette, palette, (unsigned int)num_palette *
++          png_sizeof(png_color));
++      png_memcpy(png_ptr->palette, palette, (unsigned int)num_palette *
++          png_sizeof(png_color));
++   }
+ 
+ #ifdef PNG_FREE_ME_SUPPORTED
+    info_ptr->free_me |= PNG_FREE_PLTE;
+@@ -879,20 +895,40 @@
+ 
+    if (trans != NULL)
+    {
+-       /* It may not actually be necessary to set png_ptr->trans here;
+-        * we do it for backward compatibility with the way the png_handle_tRNS
+-        * function used to do the allocation.
+-        */
+-
+ #ifdef PNG_FREE_ME_SUPPORTED
+        png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
+ #endif
+ 
+-       /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
+-       png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
+-           (png_uint_32)PNG_MAX_PALETTE_LENGTH);
+        if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
++       {
++          /* Allocate info_ptr's copy of the transparency data.
++           * Initialize all entries to fully opaque (0xff), then overwrite
++           * the first num_trans entries with the actual values.
++           */
++          info_ptr->trans = (png_bytep)png_malloc(png_ptr,
++              (png_uint_32)PNG_MAX_PALETTE_LENGTH);
++          png_memset(info_ptr->trans, 0xff, PNG_MAX_PALETTE_LENGTH);
+           png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
++
++          /* Allocate an independent copy for png_struct, so that the
++           * lifetime of png_ptr->trans is decoupled from the
++           * lifetime of info_ptr->trans.  Previously these two
++           * pointers were aliased, which caused a use-after-free if
++           * png_free_data freed info_ptr->trans while
++           * png_ptr->trans was still in use by the row transform
++           * functions (e.g. png_do_expand_palette).
++           */
++          png_free(png_ptr, png_ptr->trans);
++          png_ptr->trans = (png_bytep)png_malloc(png_ptr,
++              (png_uint_32)PNG_MAX_PALETTE_LENGTH);
++          png_memset(png_ptr->trans, 0xff, PNG_MAX_PALETTE_LENGTH);
++          png_memcpy(png_ptr->trans, trans, (png_size_t)num_trans);
++       }
++       else
++       {
++          png_free(png_ptr, png_ptr->trans);
++          png_ptr->trans = NULL;
++       }
+    }
+ 
+    if (trans_values != NULL)
+--- a/pngwrite.c
++++ b/pngwrite.c
+@@ -1149,6 +1149,16 @@
+    png_free(png_ptr, png_ptr->time_buffer);
+ #endif
+ 
++#if defined(PNG_tRNS_SUPPORTED)
++   /* Free the independent copy of trans owned by png_struct. */
++   png_free(png_ptr, png_ptr->trans);
++   png_ptr->trans = NULL;
++#endif
++
++   /* Free the independent copy of the palette owned by png_struct. */
++   png_free(png_ptr, png_ptr->palette);
++   png_ptr->palette = NULL;
++
+ #ifdef PNG_SETJMP_SUPPORTED
+    /* Reset structure */
+    png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
diff --git a/libpng12-CVE-2026-34757.patch b/libpng12-CVE-2026-34757.patch
new file mode 100644
index 0000000..710e09e
--- /dev/null
+++ b/libpng12-CVE-2026-34757.patch
@@ -0,0 +1,65 @@
+# snapshot caller's PLTE/tRNS/hIST before freeing, getter-to-setter aliasing (upstream 398cbe3, adapted to 1.2)
+--- a/pngset.c
++++ b/pngset.c
+@@ -181,6 +181,7 @@
+ void PNGAPI
+ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
+ {
++   png_uint_16 safe_hist[PNG_MAX_PALETTE_LENGTH];
+    int i;
+ 
+    png_debug1(1, "in %s storage function", "hIST");
+@@ -196,6 +197,13 @@
+       return;
+    }
+ 
++   /* Snapshot the caller's hist before freeing, in case it points to
++    * info_ptr->hist (getter-to-setter aliasing).
++    */
++   png_memcpy(safe_hist, hist, (unsigned int)info_ptr->num_palette *
++      png_sizeof(png_uint_16));
++   hist = safe_hist;
++
+ #ifdef PNG_FREE_ME_SUPPORTED
+    png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
+ #endif
+@@ -453,7 +461,7 @@
+ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
+    png_colorp palette, int num_palette)
+ {
+-
++   png_color safe_palette[PNG_MAX_PALETTE_LENGTH];
+    png_uint_32 max_palette_length;
+ 
+    png_debug1(1, "in %s storage function", "PLTE");
+@@ -475,6 +483,14 @@
+       }
+    }
+ 
++   /* Snapshot the caller's palette before freeing, in case it points to
++    * info_ptr->palette (getter-to-setter aliasing).
++    */
++   if (num_palette > 0)
++      png_memcpy(safe_palette, palette, (unsigned int)num_palette *
++         png_sizeof(png_color));
++   palette = safe_palette;
++
+ #ifdef PNG_FREE_ME_SUPPORTED
+    png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
+ #endif
+@@ -895,6 +911,15 @@
+ 
+    if (trans != NULL)
+    {
++       /* Snapshot the caller's trans before freeing, in case it points to
++        * info_ptr->trans (getter-to-setter aliasing).
++        */
++       png_byte safe_trans[PNG_MAX_PALETTE_LENGTH];
++
++       if (num_trans > 0)
++          png_memcpy(safe_trans, trans, (png_size_t)num_trans);
++       trans = safe_trans;
++
+ #ifdef PNG_FREE_ME_SUPPORTED
+        png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
+ #endif
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/libpng12.git/commitdiff/a432c231efb61ed438c337b3a146b2505f5f227c



More information about the pld-cvs-commit mailing list