• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git a/arm/arm_init.c b/arm/arm_init.c
2index ab22525b3..3a89998ab 100644
3--- a/arm/arm_init.c
4+++ b/arm/arm_init.c
5@@ -31,26 +31,21 @@
6  * has partial support is contrib/arm-neon/linux.c - a generic Linux
7  * implementation which reads /proc/cpufino.
8  */
9-#include <signal.h> /* for sig_atomic_t */
10-
11 #ifndef PNG_ARM_NEON_FILE
12-#  if defined(__aarch64__) || defined(_M_ARM64)
13-     /* ARM Neon is expected to be unconditionally available on ARM64. */
14-#    error "PNG_ARM_NEON_CHECK_SUPPORTED must not be defined on ARM64"
15-#  elif defined(__ARM_NEON__) || defined(__ARM_NEON)
16-     /* ARM Neon is expected to be available on the target CPU architecture. */
17-#    error "PNG_ARM_NEON_CHECK_SUPPORTED must not be defined on this CPU arch"
18-#  elif defined(__linux__)
19-#    define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"
20-#  else
21-#    error "No support for run-time ARM Neon checking; use compile-time options"
22+#ifdef __linux__
23+#define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"
24 #  endif
25 #endif
26
27-static int png_have_neon(png_structp png_ptr);
28 #ifdef PNG_ARM_NEON_FILE
29-#  include PNG_ARM_NEON_FILE
30-#endif
31+
32+#include <signal.h> /* for sig_atomic_t */
33+static int png_have_neon(png_structp png_ptr);
34+#include PNG_ARM_NEON_FILE
35+
36+#else  /* PNG_ARM_NEON_FILE */
37+#  error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"
38+#endif /* PNG_ARM_NEON_FILE */
39 #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
40
41 #ifndef PNG_ALIGNED_MEMORY_SUPPORTED
42diff --git a/arm/palette_neon_intrinsics.c b/arm/palette_neon_intrinsics.c
43index 92c7d6f9f..49909d475 100644
44--- a/arm/palette_neon_intrinsics.c
45+++ b/arm/palette_neon_intrinsics.c
46@@ -65,12 +65,11 @@ png_do_expand_palette_rgba8_neon(png_structrp png_ptr, png_row_infop row_info,
47    png_uint_32 row_width = row_info->width;
48    const png_uint_32 *riffled_palette =
49       (const png_uint_32 *)png_ptr->riffled_palette;
50-   const png_uint_32 pixels_per_chunk = 4;
51-   png_uint_32 i;
52+   const png_int_32 pixels_per_chunk = 4;
53+   int i;
54
55    png_debug(1, "in png_do_expand_palette_rgba8_neon");
56
57-   PNG_UNUSED(row)
58    if (row_width < pixels_per_chunk)
59       return 0;
60
61@@ -110,11 +109,10 @@ png_do_expand_palette_rgb8_neon(png_structrp png_ptr, png_row_infop row_info,
62    png_uint_32 row_width = row_info->width;
63    png_const_bytep palette = (png_const_bytep)png_ptr->palette;
64    const png_uint_32 pixels_per_chunk = 8;
65-   png_uint_32 i;
66+   int i;
67
68    png_debug(1, "in png_do_expand_palette_rgb8_neon");
69
70-   PNG_UNUSED(row)
71    if (row_width <= pixels_per_chunk)
72       return 0;
73
74diff --git a/pngread.c b/pngread.c
75index 5ab922403..8fa7d9f16 100644
76--- a/pngread.c
77+++ b/pngread.c
78@@ -3452,6 +3452,7 @@ png_image_read_background(png_voidp argument)
79
80             for (pass = 0; pass < passes; ++pass)
81             {
82+               png_bytep row = png_voidcast(png_bytep, display->first_row);
83                unsigned int     startx, stepx, stepy;
84                png_uint_32      y;
85
86@@ -3556,6 +3557,8 @@ png_image_read_background(png_voidp argument)
87
88                         inrow += 2; /* gray and alpha channel */
89                      }
90+
91+                     row += display->row_bytes;
92                   }
93                }
94             }
95diff --git a/pngrutil.c b/pngrutil.c
96index ca060dd15..9ac8ec11f 100644
97--- a/pngrutil.c
98+++ b/pngrutil.c
99@@ -2075,22 +2075,21 @@ png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
100       png_byte buf[1];
101       png_crc_read(png_ptr, buf, 1);
102       info_ptr->eXIf_buf[i] = buf[0];
103-      if (i == 1)
104+      if (i == 1 && buf[0] != 'M' && buf[0] != 'I'
105+                 && info_ptr->eXIf_buf[0] != buf[0])
106       {
107-         if ((buf[0] != 'M' && buf[0] != 'I') ||
108-             (info_ptr->eXIf_buf[0] != buf[0]))
109-         {
110-            png_crc_finish(png_ptr, length - 2);
111-            png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
112-            png_free(png_ptr, info_ptr->eXIf_buf);
113-            info_ptr->eXIf_buf = NULL;
114-            return;
115-         }
116+         png_crc_finish(png_ptr, length);
117+         png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
118+         png_free(png_ptr, info_ptr->eXIf_buf);
119+         info_ptr->eXIf_buf = NULL;
120+         return;
121       }
122    }
123
124-   if (png_crc_finish(png_ptr, 0) == 0)
125-      png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
126+   if (png_crc_finish(png_ptr, 0) != 0)
127+      return;
128+
129+   png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
130
131    png_free(png_ptr, info_ptr->eXIf_buf);
132    info_ptr->eXIf_buf = NULL;
133@@ -2126,9 +2125,8 @@ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
134
135    num = length / 2 ;
136
137-   if (length != num * 2 ||
138-       num != (unsigned int)png_ptr->num_palette ||
139-       num > (unsigned int)PNG_MAX_PALETTE_LENGTH)
140+   if (num != (unsigned int) png_ptr->num_palette ||
141+       num > (unsigned int) PNG_MAX_PALETTE_LENGTH)
142    {
143       png_crc_finish(png_ptr, length);
144       png_chunk_benign_error(png_ptr, "invalid");
145@@ -4622,11 +4620,11 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
146        */
147       {
148          png_bytep temp = png_ptr->big_row_buf + 32;
149-         size_t extra = (size_t)temp & 0x0f;
150+         int extra = (int)((temp - (png_bytep)0) & 0x0f);
151          png_ptr->row_buf = temp - extra - 1/*filter byte*/;
152
153          temp = png_ptr->big_prev_row + 32;
154-         extra = (size_t)temp & 0x0f;
155+         extra = (int)((temp - (png_bytep)0) & 0x0f);
156          png_ptr->prev_row = temp - extra - 1/*filter byte*/;
157       }
158 #else
159diff --git a/pngset.c b/pngset.c
160index 8c372cf41..6444c0615 100644
161--- a/pngset.c
162+++ b/pngset.c
163@@ -1008,8 +1008,6 @@ png_set_tRNS(png_structrp png_ptr, png_i
164               png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
165           memcpy(info_ptr->trans_alpha, trans_alpha, (size_t)num_trans);
166
167-          info_ptr->free_me |= PNG_FREE_TRNS;
168-          info_ptr->valid |= PNG_INFO_tRNS;
169        }
170        png_ptr->trans_alpha = info_ptr->trans_alpha;
171    }
172diff --git a/pngwrite.c b/pngwrite.c
173index 06c45d16a..b9a0ca188 100644
174--- a/pngwrite.c
175+++ b/pngwrite.c
176@@ -489,16 +489,6 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
177    png_debug(1, "in png_convert_from_time_t");
178
179    tbuf = gmtime(&ttime);
180-   if (tbuf == NULL)
181-   {
182-      /* TODO: add a safe function which takes a png_ptr argument and raises
183-       * a png_error if the ttime argument is invalid and the call to gmtime
184-       * fails as a consequence.
185-       */
186-      memset(ptime, 0, sizeof(*ptime));
187-      return;
188-   }
189-
190    png_convert_from_struct_tm(ptime, tbuf);
191 }
192 #endif
193diff --git a/png.c b/png.c
194index 8ef8bbd..fd74a39 100644
195--- a/png.c
196+++ b/png.c
197@@ -82,7 +82,7 @@ png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
198    if (png_ptr == NULL)
199       return NULL;
200
201-   if (items >= (~(png_alloc_size_t)0)/size)
202+   if (size != 0 && items >= (~(png_alloc_size_t)0)/size)
203    {
204       png_warning (png_voidcast(png_structrp, png_ptr),
205           "Potential overflow in png_zalloc()");
206
207