[devel] Align row_buf on 16-byte boundary in memory.
diff --git a/ANNOUNCE b/ANNOUNCE
index c49ead0..69cfb7f 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -694,6 +694,7 @@
version 1.4.0beta103 [November 21, 2009]
Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt
+ Align row_buf on 16-byte boundary in memory.
Restored the PNG_WRITE_FLUSH_AFTER_IEND guard around the call to png_flush()
after png_write_IEND(). See 1.4.0beta32, 1.4.0beta50 changes above
and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES. Someone needs this
diff --git a/CHANGES b/CHANGES
index 9a5ff99..7a3e456 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2381,6 +2381,7 @@
version 1.4.0beta103 [November 21, 2009]
Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt
+ Align row_buf on 16-byte boundary in memory.
Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call
to png_flush() after png_write_IEND(). See 1.4.0beta32, 1.4.0beta50
changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES. Someone
diff --git a/pngrutil.c b/pngrutil.c
index 2ca5948..29425af 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
- * Last changed in libpng 1.4.0 [November 20, 2009]
+ * Last changed in libpng 1.4.0 [November 21, 2009]
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -3281,15 +3281,26 @@
png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
- if (row_bytes + 64 > png_ptr->old_big_row_buf_size)
+ if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
{
png_free(png_ptr, png_ptr->big_row_buf);
+ png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
if (png_ptr->interlaced)
- png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, row_bytes + 64);
- else
- png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64);
+ png_memset(png_ptr->big_row_buf, 0, row_bytes + 48);
+ png_ptr->old_big_row_buf_size = row_bytes + 48;
+
+#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
+ /* Use 16-byte aligned memory for row_buf with at least 16 bytes
+ * of padding before and after row_buf.
+ */
+ png_ptr->row_buf = png_ptr->big_row_buf + 32
+ - (((png_alloc_size_t)&(png_ptr->big_row_buf[0]) + 15) % 16);
+ png_ptr->old_big_row_buf_size = row_bytes + 48;
+#else
+ /* Use 32 bytes of padding before and 16 bytes after row_buf. */
png_ptr->row_buf = png_ptr->big_row_buf + 32;
- png_ptr->old_big_row_buf_size = row_bytes + 64;
+#endif
+ png_ptr->old_big_row_buf_size = row_bytes + 48;
}
#ifdef PNG_MAX_MALLOC_64K