summaryrefslogtreecommitdiff
path: root/png/pngmem.c
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-09-07 18:06:14 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-09-07 18:06:39 +0200
commit27e02a1541db180e3d4260732461a080dab593a1 (patch)
tree85b14e9d0937a3c8c615c2c3ddc6644b0c58768a /png/pngmem.c
parent1182cd66ec66cc317af2db44d21c2e56b99536e8 (diff)
Update bundled libpng to version 1.6.50 dated 2025-07-01
Diffstat (limited to 'png/pngmem.c')
-rw-r--r--png/pngmem.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/png/pngmem.c b/png/pngmem.c
index 09ed9c1c9..71e61c99f 100644
--- a/png/pngmem.c
+++ b/png/pngmem.c
@@ -1,7 +1,6 @@
-
/* pngmem.c - stub functions for memory allocation
*
- * Copyright (c) 2018 Cosmin Truta
+ * Copyright (c) 2018-2025 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -73,30 +72,29 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
* to implement a user memory handler. This checks to be sure it isn't
* called with big numbers.
*/
-#ifndef PNG_USER_MEM_SUPPORTED
- PNG_UNUSED(png_ptr)
-#endif
+# ifdef PNG_MAX_MALLOC_64K
+ /* This is support for legacy systems which had segmented addressing
+ * limiting the maximum allocation size to 65536. It takes precedence
+ * over PNG_SIZE_MAX which is set to 65535 on true 16-bit systems.
+ *
+ * TODO: libpng-1.8: finally remove both cases.
+ */
+ if (size > 65536U) return NULL;
+# endif
- /* Some compilers complain that this is always true. However, it
- * can be false when integer overflow happens.
+ /* This is checked too because the system malloc call below takes a (size_t).
*/
- if (size > 0 && size <= PNG_SIZE_MAX
-# ifdef PNG_MAX_MALLOC_64K
- && size <= 65536U
-# endif
- )
- {
-#ifdef PNG_USER_MEM_SUPPORTED
+ if (size > PNG_SIZE_MAX) return NULL;
+
+# ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr != NULL && png_ptr->malloc_fn != NULL)
return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size);
+# else
+ PNG_UNUSED(png_ptr)
+# endif
- else
-#endif
- return malloc((size_t)size); /* checked for truncation above */
- }
-
- else
- return NULL;
+ /* Use the system malloc */
+ return malloc((size_t)/*SAFE*/size); /* checked for truncation above */
}
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\