author | prr |
Tue, 31 Jul 2018 14:03:39 -0700 | |
changeset 51304 | 66d9993dd4ad |
parent 48280 | 791d551bcdb8 |
child 57618 | 53154e45385a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* pngset.c - storage of image information into info struct |
|
26 |
* |
|
27 |
* This file is available under and governed by the GNU General Public |
|
28 |
* License version 2 only, as published by the Free Software Foundation. |
|
29 |
* However, the following notice accompanied the original version of this |
|
30 |
* file and, per its terms, should not be removed: |
|
31 |
* |
|
51304 | 32 |
* Last changed in libpng 1.6.35 [July 15, 2018] |
33 |
* Copyright (c) 1998-2018 Glenn Randers-Pehrson |
|
2 | 34 |
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
35 |
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
|
36 |
* |
|
10576 | 37 |
* This code is released under the libpng license. |
38 |
* For conditions of distribution and use, see the disclaimer |
|
39 |
* and license in png.h |
|
40 |
* |
|
2 | 41 |
* The functions here are used during reads to store data from the file |
42 |
* into the info struct, and during writes to store application data |
|
43 |
* into the info struct for writing into the file. This abstracts the |
|
44 |
* info struct and allows us to change the structure in the future. |
|
45 |
*/ |
|
46 |
||
10576 | 47 |
#include "pngpriv.h" |
2 | 48 |
|
49 |
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
|
50 |
||
10576 | 51 |
#ifdef PNG_bKGD_SUPPORTED |
2 | 52 |
void PNGAPI |
29913 | 53 |
png_set_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 54 |
png_const_color_16p background) |
2 | 55 |
{ |
10576 | 56 |
png_debug1(1, "in %s storage function", "bKGD"); |
57 |
||
29913 | 58 |
if (png_ptr == NULL || info_ptr == NULL || background == NULL) |
2 | 59 |
return; |
60 |
||
29913 | 61 |
info_ptr->background = *background; |
2 | 62 |
info_ptr->valid |= PNG_INFO_bKGD; |
63 |
} |
|
64 |
#endif |
|
65 |
||
10576 | 66 |
#ifdef PNG_cHRM_SUPPORTED |
67 |
void PNGFAPI |
|
29913 | 68 |
png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 69 |
png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, |
70 |
png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, |
|
71 |
png_fixed_point blue_x, png_fixed_point blue_y) |
|
2 | 72 |
{ |
29913 | 73 |
png_xy xy; |
74 |
||
10576 | 75 |
png_debug1(1, "in %s storage function", "cHRM fixed"); |
76 |
||
2 | 77 |
if (png_ptr == NULL || info_ptr == NULL) |
78 |
return; |
|
79 |
||
29913 | 80 |
xy.redx = red_x; |
81 |
xy.redy = red_y; |
|
82 |
xy.greenx = green_x; |
|
83 |
xy.greeny = green_y; |
|
84 |
xy.bluex = blue_x; |
|
85 |
xy.bluey = blue_y; |
|
86 |
xy.whitex = white_x; |
|
87 |
xy.whitey = white_y; |
|
88 |
||
89 |
if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy, |
|
90 |
2/* override with app values*/) != 0) |
|
91 |
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; |
|
92 |
||
93 |
png_colorspace_sync_info(png_ptr, info_ptr); |
|
94 |
} |
|
95 |
||
96 |
void PNGFAPI |
|
97 |
png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr, |
|
98 |
png_fixed_point int_red_X, png_fixed_point int_red_Y, |
|
99 |
png_fixed_point int_red_Z, png_fixed_point int_green_X, |
|
100 |
png_fixed_point int_green_Y, png_fixed_point int_green_Z, |
|
101 |
png_fixed_point int_blue_X, png_fixed_point int_blue_Y, |
|
102 |
png_fixed_point int_blue_Z) |
|
103 |
{ |
|
104 |
png_XYZ XYZ; |
|
105 |
||
106 |
png_debug1(1, "in %s storage function", "cHRM XYZ fixed"); |
|
107 |
||
108 |
if (png_ptr == NULL || info_ptr == NULL) |
|
109 |
return; |
|
110 |
||
111 |
XYZ.red_X = int_red_X; |
|
112 |
XYZ.red_Y = int_red_Y; |
|
113 |
XYZ.red_Z = int_red_Z; |
|
114 |
XYZ.green_X = int_green_X; |
|
115 |
XYZ.green_Y = int_green_Y; |
|
116 |
XYZ.green_Z = int_green_Z; |
|
117 |
XYZ.blue_X = int_blue_X; |
|
118 |
XYZ.blue_Y = int_blue_Y; |
|
119 |
XYZ.blue_Z = int_blue_Z; |
|
120 |
||
121 |
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, |
|
122 |
&XYZ, 2) != 0) |
|
123 |
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM; |
|
124 |
||
125 |
png_colorspace_sync_info(png_ptr, info_ptr); |
|
10576 | 126 |
} |
2 | 127 |
|
10576 | 128 |
# ifdef PNG_FLOATING_POINT_SUPPORTED |
129 |
void PNGAPI |
|
29913 | 130 |
png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 131 |
double white_x, double white_y, double red_x, double red_y, |
132 |
double green_x, double green_y, double blue_x, double blue_y) |
|
133 |
{ |
|
134 |
png_set_cHRM_fixed(png_ptr, info_ptr, |
|
43321 | 135 |
png_fixed(png_ptr, white_x, "cHRM White X"), |
136 |
png_fixed(png_ptr, white_y, "cHRM White Y"), |
|
137 |
png_fixed(png_ptr, red_x, "cHRM Red X"), |
|
138 |
png_fixed(png_ptr, red_y, "cHRM Red Y"), |
|
139 |
png_fixed(png_ptr, green_x, "cHRM Green X"), |
|
140 |
png_fixed(png_ptr, green_y, "cHRM Green Y"), |
|
141 |
png_fixed(png_ptr, blue_x, "cHRM Blue X"), |
|
142 |
png_fixed(png_ptr, blue_y, "cHRM Blue Y")); |
|
2 | 143 |
} |
10576 | 144 |
|
29913 | 145 |
void PNGAPI |
146 |
png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, |
|
147 |
double red_Y, double red_Z, double green_X, double green_Y, double green_Z, |
|
148 |
double blue_X, double blue_Y, double blue_Z) |
|
149 |
{ |
|
150 |
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, |
|
43321 | 151 |
png_fixed(png_ptr, red_X, "cHRM Red X"), |
152 |
png_fixed(png_ptr, red_Y, "cHRM Red Y"), |
|
153 |
png_fixed(png_ptr, red_Z, "cHRM Red Z"), |
|
154 |
png_fixed(png_ptr, green_X, "cHRM Green X"), |
|
155 |
png_fixed(png_ptr, green_Y, "cHRM Green Y"), |
|
156 |
png_fixed(png_ptr, green_Z, "cHRM Green Z"), |
|
157 |
png_fixed(png_ptr, blue_X, "cHRM Blue X"), |
|
158 |
png_fixed(png_ptr, blue_Y, "cHRM Blue Y"), |
|
159 |
png_fixed(png_ptr, blue_Z, "cHRM Blue Z")); |
|
29913 | 160 |
} |
161 |
# endif /* FLOATING_POINT */ |
|
162 |
||
163 |
#endif /* cHRM */ |
|
10576 | 164 |
|
48280 | 165 |
#ifdef PNG_eXIf_SUPPORTED |
166 |
void PNGAPI |
|
167 |
png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr, |
|
168 |
const png_bytep eXIf_buf) |
|
169 |
{ |
|
170 |
png_warning(png_ptr, "png_set_eXIf does not work; use png_set_eXIf_1"); |
|
171 |
PNG_UNUSED(info_ptr) |
|
172 |
PNG_UNUSED(eXIf_buf) |
|
173 |
} |
|
174 |
||
175 |
void PNGAPI |
|
176 |
png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr, |
|
177 |
const png_uint_32 num_exif, const png_bytep eXIf_buf) |
|
178 |
{ |
|
179 |
int i; |
|
180 |
||
181 |
png_debug1(1, "in %s storage function", "eXIf"); |
|
182 |
||
183 |
if (png_ptr == NULL || info_ptr == NULL) |
|
184 |
return; |
|
185 |
||
186 |
if (info_ptr->exif) |
|
187 |
{ |
|
188 |
png_free(png_ptr, info_ptr->exif); |
|
189 |
info_ptr->exif = NULL; |
|
190 |
} |
|
191 |
||
192 |
info_ptr->num_exif = num_exif; |
|
193 |
||
194 |
info_ptr->exif = png_voidcast(png_bytep, png_malloc_warn(png_ptr, |
|
195 |
info_ptr->num_exif)); |
|
196 |
||
197 |
if (info_ptr->exif == NULL) |
|
198 |
{ |
|
199 |
png_warning(png_ptr, "Insufficient memory for eXIf chunk data"); |
|
200 |
return; |
|
201 |
} |
|
202 |
||
203 |
info_ptr->free_me |= PNG_FREE_EXIF; |
|
204 |
||
205 |
for (i = 0; i < (int) info_ptr->num_exif; i++) |
|
206 |
info_ptr->exif[i] = eXIf_buf[i]; |
|
207 |
||
208 |
info_ptr->valid |= PNG_INFO_eXIf; |
|
209 |
} |
|
210 |
#endif /* eXIf */ |
|
211 |
||
10576 | 212 |
#ifdef PNG_gAMA_SUPPORTED |
213 |
void PNGFAPI |
|
29913 | 214 |
png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, |
215 |
png_fixed_point file_gamma) |
|
2 | 216 |
{ |
10576 | 217 |
png_debug1(1, "in %s storage function", "gAMA"); |
218 |
||
2 | 219 |
if (png_ptr == NULL || info_ptr == NULL) |
220 |
return; |
|
221 |
||
29913 | 222 |
png_colorspace_set_gamma(png_ptr, &info_ptr->colorspace, file_gamma); |
223 |
png_colorspace_sync_info(png_ptr, info_ptr); |
|
2 | 224 |
} |
225 |
||
10576 | 226 |
# ifdef PNG_FLOATING_POINT_SUPPORTED |
2 | 227 |
void PNGAPI |
29913 | 228 |
png_set_gAMA(png_const_structrp png_ptr, png_inforp info_ptr, double file_gamma) |
2 | 229 |
{ |
10576 | 230 |
png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma, |
231 |
"png_set_gAMA")); |
|
232 |
} |
|
233 |
# endif |
|
234 |
#endif |
|
235 |
||
236 |
#ifdef PNG_hIST_SUPPORTED |
|
237 |
void PNGAPI |
|
29913 | 238 |
png_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr, |
239 |
png_const_uint_16p hist) |
|
10576 | 240 |
{ |
241 |
int i; |
|
242 |
||
243 |
png_debug1(1, "in %s storage function", "hIST"); |
|
244 |
||
2 | 245 |
if (png_ptr == NULL || info_ptr == NULL) |
246 |
return; |
|
247 |
||
10576 | 248 |
if (info_ptr->num_palette == 0 || info_ptr->num_palette |
2 | 249 |
> PNG_MAX_PALETTE_LENGTH) |
250 |
{ |
|
10576 | 251 |
png_warning(png_ptr, |
252 |
"Invalid palette size, hIST allocation skipped"); |
|
253 |
||
254 |
return; |
|
2 | 255 |
} |
256 |
||
257 |
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); |
|
10576 | 258 |
|
259 |
/* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in |
|
260 |
* version 1.2.1 |
|
261 |
*/ |
|
29913 | 262 |
info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr, |
263 |
PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16)))); |
|
10576 | 264 |
|
29913 | 265 |
if (info_ptr->hist == NULL) |
10576 | 266 |
{ |
267 |
png_warning(png_ptr, "Insufficient memory for hIST chunk data"); |
|
35296 | 268 |
|
10576 | 269 |
return; |
270 |
} |
|
2 | 271 |
|
29913 | 272 |
info_ptr->free_me |= PNG_FREE_HIST; |
10576 | 273 |
|
29913 | 274 |
for (i = 0; i < info_ptr->num_palette; i++) |
275 |
info_ptr->hist[i] = hist[i]; |
|
276 |
||
2 | 277 |
info_ptr->valid |= PNG_INFO_hIST; |
278 |
} |
|
279 |
#endif |
|
280 |
||
281 |
void PNGAPI |
|
29913 | 282 |
png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 283 |
png_uint_32 width, png_uint_32 height, int bit_depth, |
284 |
int color_type, int interlace_type, int compression_type, |
|
285 |
int filter_type) |
|
2 | 286 |
{ |
10576 | 287 |
png_debug1(1, "in %s storage function", "IHDR"); |
288 |
||
2 | 289 |
if (png_ptr == NULL || info_ptr == NULL) |
290 |
return; |
|
291 |
||
292 |
info_ptr->width = width; |
|
293 |
info_ptr->height = height; |
|
294 |
info_ptr->bit_depth = (png_byte)bit_depth; |
|
10576 | 295 |
info_ptr->color_type = (png_byte)color_type; |
2 | 296 |
info_ptr->compression_type = (png_byte)compression_type; |
297 |
info_ptr->filter_type = (png_byte)filter_type; |
|
298 |
info_ptr->interlace_type = (png_byte)interlace_type; |
|
10576 | 299 |
|
300 |
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, |
|
301 |
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, |
|
302 |
info_ptr->compression_type, info_ptr->filter_type); |
|
303 |
||
2 | 304 |
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
305 |
info_ptr->channels = 1; |
|
10576 | 306 |
|
29913 | 307 |
else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) |
2 | 308 |
info_ptr->channels = 3; |
10576 | 309 |
|
2 | 310 |
else |
311 |
info_ptr->channels = 1; |
|
10576 | 312 |
|
29913 | 313 |
if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0) |
2 | 314 |
info_ptr->channels++; |
10576 | 315 |
|
2 | 316 |
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); |
317 |
||
29913 | 318 |
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); |
2 | 319 |
} |
320 |
||
10576 | 321 |
#ifdef PNG_oFFs_SUPPORTED |
2 | 322 |
void PNGAPI |
29913 | 323 |
png_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 324 |
png_int_32 offset_x, png_int_32 offset_y, int unit_type) |
2 | 325 |
{ |
10576 | 326 |
png_debug1(1, "in %s storage function", "oFFs"); |
327 |
||
2 | 328 |
if (png_ptr == NULL || info_ptr == NULL) |
329 |
return; |
|
330 |
||
331 |
info_ptr->x_offset = offset_x; |
|
332 |
info_ptr->y_offset = offset_y; |
|
333 |
info_ptr->offset_unit_type = (png_byte)unit_type; |
|
334 |
info_ptr->valid |= PNG_INFO_oFFs; |
|
335 |
} |
|
336 |
#endif |
|
337 |
||
10576 | 338 |
#ifdef PNG_pCAL_SUPPORTED |
2 | 339 |
void PNGAPI |
29913 | 340 |
png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 341 |
png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, |
342 |
int nparams, png_const_charp units, png_charpp params) |
|
2 | 343 |
{ |
51304 | 344 |
size_t length; |
2 | 345 |
int i; |
346 |
||
10576 | 347 |
png_debug1(1, "in %s storage function", "pCAL"); |
348 |
||
29913 | 349 |
if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL |
35296 | 350 |
|| (nparams > 0 && params == NULL)) |
2 | 351 |
return; |
352 |
||
29913 | 353 |
length = strlen(purpose) + 1; |
10576 | 354 |
png_debug1(3, "allocating purpose for info (%lu bytes)", |
355 |
(unsigned long)length); |
|
356 |
||
357 |
/* TODO: validate format of calibration name and unit name */ |
|
358 |
||
359 |
/* Check that the type matches the specification. */ |
|
360 |
if (type < 0 || type > 3) |
|
43321 | 361 |
{ |
362 |
png_chunk_report(png_ptr, "Invalid pCAL equation type", |
|
363 |
PNG_CHUNK_WRITE_ERROR); |
|
364 |
return; |
|
365 |
} |
|
10576 | 366 |
|
29913 | 367 |
if (nparams < 0 || nparams > 255) |
43321 | 368 |
{ |
369 |
png_chunk_report(png_ptr, "Invalid pCAL parameter count", |
|
370 |
PNG_CHUNK_WRITE_ERROR); |
|
371 |
return; |
|
372 |
} |
|
29913 | 373 |
|
10576 | 374 |
/* Validate params[nparams] */ |
375 |
for (i=0; i<nparams; ++i) |
|
29913 | 376 |
{ |
377 |
if (params[i] == NULL || |
|
378 |
!png_check_fp_string(params[i], strlen(params[i]))) |
|
43321 | 379 |
{ |
380 |
png_chunk_report(png_ptr, "Invalid format for pCAL parameter", |
|
381 |
PNG_CHUNK_WRITE_ERROR); |
|
382 |
return; |
|
383 |
} |
|
29913 | 384 |
} |
10576 | 385 |
|
29913 | 386 |
info_ptr->pcal_purpose = png_voidcast(png_charp, |
387 |
png_malloc_warn(png_ptr, length)); |
|
10576 | 388 |
|
2 | 389 |
if (info_ptr->pcal_purpose == NULL) |
10576 | 390 |
{ |
43321 | 391 |
png_chunk_report(png_ptr, "Insufficient memory for pCAL purpose", |
392 |
PNG_CHUNK_WRITE_ERROR); |
|
10576 | 393 |
return; |
394 |
} |
|
2 | 395 |
|
29913 | 396 |
memcpy(info_ptr->pcal_purpose, purpose, length); |
10576 | 397 |
|
398 |
png_debug(3, "storing X0, X1, type, and nparams in info"); |
|
2 | 399 |
info_ptr->pcal_X0 = X0; |
400 |
info_ptr->pcal_X1 = X1; |
|
401 |
info_ptr->pcal_type = (png_byte)type; |
|
402 |
info_ptr->pcal_nparams = (png_byte)nparams; |
|
403 |
||
29913 | 404 |
length = strlen(units) + 1; |
10576 | 405 |
png_debug1(3, "allocating units for info (%lu bytes)", |
43321 | 406 |
(unsigned long)length); |
10576 | 407 |
|
29913 | 408 |
info_ptr->pcal_units = png_voidcast(png_charp, |
43321 | 409 |
png_malloc_warn(png_ptr, length)); |
10576 | 410 |
|
2 | 411 |
if (info_ptr->pcal_units == NULL) |
10576 | 412 |
{ |
413 |
png_warning(png_ptr, "Insufficient memory for pCAL units"); |
|
35296 | 414 |
|
10576 | 415 |
return; |
416 |
} |
|
417 |
||
29913 | 418 |
memcpy(info_ptr->pcal_units, units, length); |
2 | 419 |
|
29913 | 420 |
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, |
51304 | 421 |
(size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp))))); |
10576 | 422 |
|
2 | 423 |
if (info_ptr->pcal_params == NULL) |
10576 | 424 |
{ |
425 |
png_warning(png_ptr, "Insufficient memory for pCAL params"); |
|
35296 | 426 |
|
10576 | 427 |
return; |
428 |
} |
|
2 | 429 |
|
43321 | 430 |
memset(info_ptr->pcal_params, 0, ((unsigned int)nparams + 1) * |
431 |
(sizeof (png_charp))); |
|
2 | 432 |
|
433 |
for (i = 0; i < nparams; i++) |
|
434 |
{ |
|
29913 | 435 |
length = strlen(params[i]) + 1; |
10576 | 436 |
png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, |
437 |
(unsigned long)length); |
|
438 |
||
2 | 439 |
info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); |
10576 | 440 |
|
2 | 441 |
if (info_ptr->pcal_params[i] == NULL) |
10576 | 442 |
{ |
443 |
png_warning(png_ptr, "Insufficient memory for pCAL parameter"); |
|
35296 | 444 |
|
10576 | 445 |
return; |
446 |
} |
|
447 |
||
29913 | 448 |
memcpy(info_ptr->pcal_params[i], params[i], length); |
2 | 449 |
} |
450 |
||
451 |
info_ptr->valid |= PNG_INFO_pCAL; |
|
452 |
info_ptr->free_me |= PNG_FREE_PCAL; |
|
453 |
} |
|
454 |
#endif |
|
455 |
||
10576 | 456 |
#ifdef PNG_sCAL_SUPPORTED |
2 | 457 |
void PNGAPI |
29913 | 458 |
png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 459 |
int unit, png_const_charp swidth, png_const_charp sheight) |
2 | 460 |
{ |
51304 | 461 |
size_t lengthw = 0, lengthh = 0; |
10576 | 462 |
|
463 |
png_debug1(1, "in %s storage function", "sCAL"); |
|
464 |
||
2 | 465 |
if (png_ptr == NULL || info_ptr == NULL) |
466 |
return; |
|
467 |
||
10576 | 468 |
/* Double check the unit (should never get here with an invalid |
469 |
* unit unless this is an API call.) |
|
470 |
*/ |
|
471 |
if (unit != 1 && unit != 2) |
|
472 |
png_error(png_ptr, "Invalid sCAL unit"); |
|
2 | 473 |
|
29913 | 474 |
if (swidth == NULL || (lengthw = strlen(swidth)) == 0 || |
10576 | 475 |
swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw)) |
476 |
png_error(png_ptr, "Invalid sCAL width"); |
|
2 | 477 |
|
29913 | 478 |
if (sheight == NULL || (lengthh = strlen(sheight)) == 0 || |
10576 | 479 |
sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh)) |
480 |
png_error(png_ptr, "Invalid sCAL height"); |
|
2 | 481 |
|
482 |
info_ptr->scal_unit = (png_byte)unit; |
|
483 |
||
10576 | 484 |
++lengthw; |
485 |
||
486 |
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); |
|
487 |
||
29913 | 488 |
info_ptr->scal_s_width = png_voidcast(png_charp, |
43321 | 489 |
png_malloc_warn(png_ptr, lengthw)); |
10576 | 490 |
|
2 | 491 |
if (info_ptr->scal_s_width == NULL) |
492 |
{ |
|
10576 | 493 |
png_warning(png_ptr, "Memory allocation failed while processing sCAL"); |
35296 | 494 |
|
10576 | 495 |
return; |
2 | 496 |
} |
10576 | 497 |
|
29913 | 498 |
memcpy(info_ptr->scal_s_width, swidth, lengthw); |
2 | 499 |
|
10576 | 500 |
++lengthh; |
501 |
||
502 |
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); |
|
503 |
||
29913 | 504 |
info_ptr->scal_s_height = png_voidcast(png_charp, |
43321 | 505 |
png_malloc_warn(png_ptr, lengthh)); |
10576 | 506 |
|
2 | 507 |
if (info_ptr->scal_s_height == NULL) |
508 |
{ |
|
509 |
png_free (png_ptr, info_ptr->scal_s_width); |
|
10576 | 510 |
info_ptr->scal_s_width = NULL; |
511 |
||
512 |
png_warning(png_ptr, "Memory allocation failed while processing sCAL"); |
|
35296 | 513 |
|
10576 | 514 |
return; |
2 | 515 |
} |
10576 | 516 |
|
29913 | 517 |
memcpy(info_ptr->scal_s_height, sheight, lengthh); |
2 | 518 |
|
519 |
info_ptr->valid |= PNG_INFO_sCAL; |
|
520 |
info_ptr->free_me |= PNG_FREE_SCAL; |
|
10576 | 521 |
} |
522 |
||
523 |
# ifdef PNG_FLOATING_POINT_SUPPORTED |
|
524 |
void PNGAPI |
|
29913 | 525 |
png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit, |
526 |
double width, double height) |
|
10576 | 527 |
{ |
528 |
png_debug1(1, "in %s storage function", "sCAL"); |
|
529 |
||
530 |
/* Check the arguments. */ |
|
531 |
if (width <= 0) |
|
532 |
png_warning(png_ptr, "Invalid sCAL width ignored"); |
|
533 |
||
534 |
else if (height <= 0) |
|
535 |
png_warning(png_ptr, "Invalid sCAL height ignored"); |
|
536 |
||
537 |
else |
|
538 |
{ |
|
539 |
/* Convert 'width' and 'height' to ASCII. */ |
|
540 |
char swidth[PNG_sCAL_MAX_DIGITS+1]; |
|
541 |
char sheight[PNG_sCAL_MAX_DIGITS+1]; |
|
542 |
||
29913 | 543 |
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width, |
43321 | 544 |
PNG_sCAL_PRECISION); |
29913 | 545 |
png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height, |
43321 | 546 |
PNG_sCAL_PRECISION); |
10576 | 547 |
|
548 |
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); |
|
549 |
} |
|
2 | 550 |
} |
10576 | 551 |
# endif |
552 |
||
553 |
# ifdef PNG_FIXED_POINT_SUPPORTED |
|
554 |
void PNGAPI |
|
29913 | 555 |
png_set_sCAL_fixed(png_const_structrp png_ptr, png_inforp info_ptr, int unit, |
10576 | 556 |
png_fixed_point width, png_fixed_point height) |
557 |
{ |
|
558 |
png_debug1(1, "in %s storage function", "sCAL"); |
|
559 |
||
560 |
/* Check the arguments. */ |
|
561 |
if (width <= 0) |
|
562 |
png_warning(png_ptr, "Invalid sCAL width ignored"); |
|
563 |
||
564 |
else if (height <= 0) |
|
565 |
png_warning(png_ptr, "Invalid sCAL height ignored"); |
|
566 |
||
567 |
else |
|
568 |
{ |
|
569 |
/* Convert 'width' and 'height' to ASCII. */ |
|
570 |
char swidth[PNG_sCAL_MAX_DIGITS+1]; |
|
571 |
char sheight[PNG_sCAL_MAX_DIGITS+1]; |
|
572 |
||
29913 | 573 |
png_ascii_from_fixed(png_ptr, swidth, (sizeof swidth), width); |
574 |
png_ascii_from_fixed(png_ptr, sheight, (sizeof sheight), height); |
|
10576 | 575 |
|
576 |
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); |
|
577 |
} |
|
578 |
} |
|
579 |
# endif |
|
2 | 580 |
#endif |
581 |
||
10576 | 582 |
#ifdef PNG_pHYs_SUPPORTED |
2 | 583 |
void PNGAPI |
29913 | 584 |
png_set_pHYs(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 585 |
png_uint_32 res_x, png_uint_32 res_y, int unit_type) |
2 | 586 |
{ |
10576 | 587 |
png_debug1(1, "in %s storage function", "pHYs"); |
588 |
||
2 | 589 |
if (png_ptr == NULL || info_ptr == NULL) |
590 |
return; |
|
591 |
||
592 |
info_ptr->x_pixels_per_unit = res_x; |
|
593 |
info_ptr->y_pixels_per_unit = res_y; |
|
594 |
info_ptr->phys_unit_type = (png_byte)unit_type; |
|
595 |
info_ptr->valid |= PNG_INFO_pHYs; |
|
596 |
} |
|
597 |
#endif |
|
598 |
||
599 |
void PNGAPI |
|
29913 | 600 |
png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, |
10576 | 601 |
png_const_colorp palette, int num_palette) |
2 | 602 |
{ |
603 |
||
35296 | 604 |
png_uint_32 max_palette_length; |
605 |
||
10576 | 606 |
png_debug1(1, "in %s storage function", "PLTE"); |
607 |
||
2 | 608 |
if (png_ptr == NULL || info_ptr == NULL) |
609 |
return; |
|
610 |
||
35296 | 611 |
max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? |
612 |
(1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; |
|
613 |
||
614 |
if (num_palette < 0 || num_palette > (int) max_palette_length) |
|
10576 | 615 |
{ |
616 |
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
|
2 | 617 |
png_error(png_ptr, "Invalid palette length"); |
10576 | 618 |
|
619 |
else |
|
620 |
{ |
|
2 | 621 |
png_warning(png_ptr, "Invalid palette length"); |
35296 | 622 |
|
2 | 623 |
return; |
10576 | 624 |
} |
625 |
} |
|
2 | 626 |
|
23903 | 627 |
if ((num_palette > 0 && palette == NULL) || |
628 |
(num_palette == 0 |
|
629 |
# ifdef PNG_MNG_FEATURES_SUPPORTED |
|
630 |
&& (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 |
|
631 |
# endif |
|
632 |
)) |
|
633 |
{ |
|
634 |
png_error(png_ptr, "Invalid palette"); |
|
635 |
} |
|
636 |
||
10576 | 637 |
/* It may not actually be necessary to set png_ptr->palette here; |
2 | 638 |
* we do it for backward compatibility with the way the png_handle_tRNS |
639 |
* function used to do the allocation. |
|
29913 | 640 |
* |
641 |
* 1.6.0: the above statement appears to be incorrect; something has to set |
|
642 |
* the palette inside png_struct on read. |
|
2 | 643 |
*/ |
644 |
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); |
|
645 |
||
646 |
/* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead |
|
35296 | 647 |
* of num_palette entries, in case of an invalid PNG file or incorrect |
648 |
* call to png_set_PLTE() with too-large sample values. |
|
10576 | 649 |
*/ |
29913 | 650 |
png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, |
651 |
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); |
|
10576 | 652 |
|
29913 | 653 |
if (num_palette > 0) |
43321 | 654 |
memcpy(png_ptr->palette, palette, (unsigned int)num_palette * |
655 |
(sizeof (png_color))); |
|
2 | 656 |
info_ptr->palette = png_ptr->palette; |
657 |
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; |
|
658 |
||
659 |
info_ptr->free_me |= PNG_FREE_PLTE; |
|
660 |
||
661 |
info_ptr->valid |= PNG_INFO_PLTE; |
|
662 |
} |
|
663 |
||
10576 | 664 |
#ifdef PNG_sBIT_SUPPORTED |
2 | 665 |
void PNGAPI |
29913 | 666 |
png_set_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 667 |
png_const_color_8p sig_bit) |
2 | 668 |
{ |
10576 | 669 |
png_debug1(1, "in %s storage function", "sBIT"); |
670 |
||
29913 | 671 |
if (png_ptr == NULL || info_ptr == NULL || sig_bit == NULL) |
2 | 672 |
return; |
673 |
||
29913 | 674 |
info_ptr->sig_bit = *sig_bit; |
2 | 675 |
info_ptr->valid |= PNG_INFO_sBIT; |
676 |
} |
|
677 |
#endif |
|
678 |
||
10576 | 679 |
#ifdef PNG_sRGB_SUPPORTED |
2 | 680 |
void PNGAPI |
29913 | 681 |
png_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent) |
2 | 682 |
{ |
10576 | 683 |
png_debug1(1, "in %s storage function", "sRGB"); |
684 |
||
2 | 685 |
if (png_ptr == NULL || info_ptr == NULL) |
686 |
return; |
|
687 |
||
29913 | 688 |
(void)png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent); |
689 |
png_colorspace_sync_info(png_ptr, info_ptr); |
|
2 | 690 |
} |
691 |
||
692 |
void PNGAPI |
|
29913 | 693 |
png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 694 |
int srgb_intent) |
2 | 695 |
{ |
10576 | 696 |
png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); |
697 |
||
2 | 698 |
if (png_ptr == NULL || info_ptr == NULL) |
699 |
return; |
|
700 |
||
29913 | 701 |
if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, |
702 |
srgb_intent) != 0) |
|
703 |
{ |
|
704 |
/* This causes the gAMA and cHRM to be written too */ |
|
705 |
info_ptr->colorspace.flags |= |
|
706 |
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; |
|
707 |
} |
|
2 | 708 |
|
29913 | 709 |
png_colorspace_sync_info(png_ptr, info_ptr); |
2 | 710 |
} |
10576 | 711 |
#endif /* sRGB */ |
2 | 712 |
|
713 |
||
10576 | 714 |
#ifdef PNG_iCCP_SUPPORTED |
2 | 715 |
void PNGAPI |
29913 | 716 |
png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 717 |
png_const_charp name, int compression_type, |
718 |
png_const_bytep profile, png_uint_32 proflen) |
|
2 | 719 |
{ |
720 |
png_charp new_iccp_name; |
|
10576 | 721 |
png_bytep new_iccp_profile; |
51304 | 722 |
size_t length; |
2 | 723 |
|
10576 | 724 |
png_debug1(1, "in %s storage function", "iCCP"); |
725 |
||
2 | 726 |
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) |
727 |
return; |
|
728 |
||
29913 | 729 |
if (compression_type != PNG_COMPRESSION_TYPE_BASE) |
730 |
png_app_error(png_ptr, "Invalid iCCP compression method"); |
|
731 |
||
732 |
/* Set the colorspace first because this validates the profile; do not |
|
733 |
* override previously set app cHRM or gAMA here (because likely as not the |
|
734 |
* application knows better than libpng what the correct values are.) Pass |
|
735 |
* the info_ptr color_type field to png_colorspace_set_ICC because in the |
|
736 |
* write case it has not yet been stored in png_ptr. |
|
737 |
*/ |
|
738 |
{ |
|
739 |
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name, |
|
43321 | 740 |
proflen, profile, info_ptr->color_type); |
29913 | 741 |
|
742 |
png_colorspace_sync_info(png_ptr, info_ptr); |
|
743 |
||
744 |
/* Don't do any of the copying if the profile was bad, or inconsistent. */ |
|
745 |
if (result == 0) |
|
746 |
return; |
|
747 |
||
748 |
/* But do write the gAMA and cHRM chunks from the profile. */ |
|
749 |
info_ptr->colorspace.flags |= |
|
750 |
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM; |
|
751 |
} |
|
752 |
||
753 |
length = strlen(name)+1; |
|
754 |
new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length)); |
|
10576 | 755 |
|
2 | 756 |
if (new_iccp_name == NULL) |
757 |
{ |
|
29913 | 758 |
png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk"); |
35296 | 759 |
|
2 | 760 |
return; |
761 |
} |
|
10576 | 762 |
|
29913 | 763 |
memcpy(new_iccp_name, name, length); |
764 |
new_iccp_profile = png_voidcast(png_bytep, |
|
43321 | 765 |
png_malloc_warn(png_ptr, proflen)); |
10576 | 766 |
|
2 | 767 |
if (new_iccp_profile == NULL) |
768 |
{ |
|
29913 | 769 |
png_free(png_ptr, new_iccp_name); |
770 |
png_benign_error(png_ptr, |
|
10576 | 771 |
"Insufficient memory to process iCCP profile"); |
35296 | 772 |
|
2 | 773 |
return; |
774 |
} |
|
10576 | 775 |
|
29913 | 776 |
memcpy(new_iccp_profile, profile, proflen); |
2 | 777 |
|
778 |
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); |
|
779 |
||
780 |
info_ptr->iccp_proflen = proflen; |
|
781 |
info_ptr->iccp_name = new_iccp_name; |
|
782 |
info_ptr->iccp_profile = new_iccp_profile; |
|
783 |
info_ptr->free_me |= PNG_FREE_ICCP; |
|
784 |
info_ptr->valid |= PNG_INFO_iCCP; |
|
785 |
} |
|
786 |
#endif |
|
787 |
||
10576 | 788 |
#ifdef PNG_TEXT_SUPPORTED |
2 | 789 |
void PNGAPI |
29913 | 790 |
png_set_text(png_const_structrp png_ptr, png_inforp info_ptr, |
791 |
png_const_textp text_ptr, int num_text) |
|
2 | 792 |
{ |
793 |
int ret; |
|
10576 | 794 |
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); |
795 |
||
29913 | 796 |
if (ret != 0) |
10576 | 797 |
png_error(png_ptr, "Insufficient memory to store text"); |
2 | 798 |
} |
799 |
||
800 |
int /* PRIVATE */ |
|
29913 | 801 |
png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 802 |
png_const_textp text_ptr, int num_text) |
2 | 803 |
{ |
804 |
int i; |
|
805 |
||
35296 | 806 |
png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11U : |
29913 | 807 |
(unsigned long)png_ptr->chunk_name); |
2 | 808 |
|
29913 | 809 |
if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) |
2 | 810 |
return(0); |
811 |
||
812 |
/* Make sure we have enough space in the "text" array in info_struct |
|
29913 | 813 |
* to hold all of the incoming text_ptr objects. This compare can't overflow |
814 |
* because max_text >= num_text (anyway, subtract of two positive integers |
|
815 |
* can't overflow in any case.) |
|
2 | 816 |
*/ |
29913 | 817 |
if (num_text > info_ptr->max_text - info_ptr->num_text) |
2 | 818 |
{ |
29913 | 819 |
int old_num_text = info_ptr->num_text; |
820 |
int max_text; |
|
821 |
png_textp new_text = NULL; |
|
2 | 822 |
|
29913 | 823 |
/* Calculate an appropriate max_text, checking for overflow. */ |
824 |
max_text = old_num_text; |
|
825 |
if (num_text <= INT_MAX - max_text) |
|
826 |
{ |
|
827 |
max_text += num_text; |
|
828 |
||
829 |
/* Round up to a multiple of 8 */ |
|
830 |
if (max_text < INT_MAX-8) |
|
831 |
max_text = (max_text + 8) & ~0x7; |
|
10576 | 832 |
|
29913 | 833 |
else |
834 |
max_text = INT_MAX; |
|
10576 | 835 |
|
29913 | 836 |
/* Now allocate a new array and copy the old members in; this does all |
837 |
* the overflow checks. |
|
838 |
*/ |
|
839 |
new_text = png_voidcast(png_textp,png_realloc_array(png_ptr, |
|
43321 | 840 |
info_ptr->text, old_num_text, max_text-old_num_text, |
841 |
sizeof *new_text)); |
|
2 | 842 |
} |
10576 | 843 |
|
29913 | 844 |
if (new_text == NULL) |
2 | 845 |
{ |
29913 | 846 |
png_chunk_report(png_ptr, "too many text chunks", |
43321 | 847 |
PNG_CHUNK_WRITE_ERROR); |
35296 | 848 |
|
29913 | 849 |
return 1; |
2 | 850 |
} |
10576 | 851 |
|
29913 | 852 |
png_free(png_ptr, info_ptr->text); |
853 |
||
854 |
info_ptr->text = new_text; |
|
855 |
info_ptr->free_me |= PNG_FREE_TEXT; |
|
856 |
info_ptr->max_text = max_text; |
|
857 |
/* num_text is adjusted below as the entries are copied in */ |
|
858 |
||
859 |
png_debug1(3, "allocated %d entries for info_ptr->text", max_text); |
|
2 | 860 |
} |
29913 | 861 |
|
2 | 862 |
for (i = 0; i < num_text; i++) |
863 |
{ |
|
29913 | 864 |
size_t text_length, key_len; |
865 |
size_t lang_len, lang_key_len; |
|
2 | 866 |
png_textp textp = &(info_ptr->text[info_ptr->num_text]); |
867 |
||
868 |
if (text_ptr[i].key == NULL) |
|
869 |
continue; |
|
870 |
||
10576 | 871 |
if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE || |
872 |
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) |
|
873 |
{ |
|
29913 | 874 |
png_chunk_report(png_ptr, "text compression mode is out of range", |
43321 | 875 |
PNG_CHUNK_WRITE_ERROR); |
10576 | 876 |
continue; |
877 |
} |
|
878 |
||
29913 | 879 |
key_len = strlen(text_ptr[i].key); |
2 | 880 |
|
10576 | 881 |
if (text_ptr[i].compression <= 0) |
2 | 882 |
{ |
10576 | 883 |
lang_len = 0; |
884 |
lang_key_len = 0; |
|
2 | 885 |
} |
10576 | 886 |
|
2 | 887 |
else |
10576 | 888 |
# ifdef PNG_iTXt_SUPPORTED |
2 | 889 |
{ |
10576 | 890 |
/* Set iTXt data */ |
891 |
||
892 |
if (text_ptr[i].lang != NULL) |
|
29913 | 893 |
lang_len = strlen(text_ptr[i].lang); |
10576 | 894 |
|
895 |
else |
|
896 |
lang_len = 0; |
|
897 |
||
898 |
if (text_ptr[i].lang_key != NULL) |
|
29913 | 899 |
lang_key_len = strlen(text_ptr[i].lang_key); |
10576 | 900 |
|
901 |
else |
|
902 |
lang_key_len = 0; |
|
2 | 903 |
} |
35296 | 904 |
# else /* iTXt */ |
2 | 905 |
{ |
29913 | 906 |
png_chunk_report(png_ptr, "iTXt chunk not supported", |
43321 | 907 |
PNG_CHUNK_WRITE_ERROR); |
10576 | 908 |
continue; |
2 | 909 |
} |
10576 | 910 |
# endif |
2 | 911 |
|
912 |
if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') |
|
913 |
{ |
|
914 |
text_length = 0; |
|
10576 | 915 |
# ifdef PNG_iTXt_SUPPORTED |
916 |
if (text_ptr[i].compression > 0) |
|
2 | 917 |
textp->compression = PNG_ITXT_COMPRESSION_NONE; |
10576 | 918 |
|
2 | 919 |
else |
10576 | 920 |
# endif |
2 | 921 |
textp->compression = PNG_TEXT_COMPRESSION_NONE; |
922 |
} |
|
10576 | 923 |
|
2 | 924 |
else |
925 |
{ |
|
29913 | 926 |
text_length = strlen(text_ptr[i].text); |
2 | 927 |
textp->compression = text_ptr[i].compression; |
928 |
} |
|
929 |
||
29913 | 930 |
textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr, |
931 |
key_len + text_length + lang_len + lang_key_len + 4)); |
|
10576 | 932 |
|
2 | 933 |
if (textp->key == NULL) |
29913 | 934 |
{ |
935 |
png_chunk_report(png_ptr, "text chunk: out of memory", |
|
43321 | 936 |
PNG_CHUNK_WRITE_ERROR); |
35296 | 937 |
|
29913 | 938 |
return 1; |
939 |
} |
|
2 | 940 |
|
10576 | 941 |
png_debug2(2, "Allocated %lu bytes at %p in png_set_text", |
942 |
(unsigned long)(png_uint_32) |
|
943 |
(key_len + lang_len + lang_key_len + text_length + 4), |
|
944 |
textp->key); |
|
945 |
||
29913 | 946 |
memcpy(textp->key, text_ptr[i].key, key_len); |
10576 | 947 |
*(textp->key + key_len) = '\0'; |
948 |
||
2 | 949 |
if (text_ptr[i].compression > 0) |
950 |
{ |
|
10576 | 951 |
textp->lang = textp->key + key_len + 1; |
29913 | 952 |
memcpy(textp->lang, text_ptr[i].lang, lang_len); |
10576 | 953 |
*(textp->lang + lang_len) = '\0'; |
954 |
textp->lang_key = textp->lang + lang_len + 1; |
|
29913 | 955 |
memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); |
10576 | 956 |
*(textp->lang_key + lang_key_len) = '\0'; |
957 |
textp->text = textp->lang_key + lang_key_len + 1; |
|
2 | 958 |
} |
10576 | 959 |
|
2 | 960 |
else |
961 |
{ |
|
962 |
textp->lang=NULL; |
|
963 |
textp->lang_key=NULL; |
|
10576 | 964 |
textp->text = textp->key + key_len + 1; |
2 | 965 |
} |
10576 | 966 |
|
29913 | 967 |
if (text_length != 0) |
968 |
memcpy(textp->text, text_ptr[i].text, text_length); |
|
2 | 969 |
|
10576 | 970 |
*(textp->text + text_length) = '\0'; |
971 |
||
972 |
# ifdef PNG_iTXt_SUPPORTED |
|
973 |
if (textp->compression > 0) |
|
2 | 974 |
{ |
975 |
textp->text_length = 0; |
|
976 |
textp->itxt_length = text_length; |
|
977 |
} |
|
10576 | 978 |
|
2 | 979 |
else |
10576 | 980 |
# endif |
2 | 981 |
{ |
982 |
textp->text_length = text_length; |
|
983 |
textp->itxt_length = 0; |
|
984 |
} |
|
10576 | 985 |
|
2 | 986 |
info_ptr->num_text++; |
10576 | 987 |
png_debug1(3, "transferred text chunk %d", info_ptr->num_text); |
2 | 988 |
} |
29913 | 989 |
|
2 | 990 |
return(0); |
991 |
} |
|
992 |
#endif |
|
993 |
||
10576 | 994 |
#ifdef PNG_tIME_SUPPORTED |
2 | 995 |
void PNGAPI |
29913 | 996 |
png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr, |
997 |
png_const_timep mod_time) |
|
2 | 998 |
{ |
10576 | 999 |
png_debug1(1, "in %s storage function", "tIME"); |
1000 |
||
29913 | 1001 |
if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL || |
1002 |
(png_ptr->mode & PNG_WROTE_tIME) != 0) |
|
2 | 1003 |
return; |
1004 |
||
29913 | 1005 |
if (mod_time->month == 0 || mod_time->month > 12 || |
1006 |
mod_time->day == 0 || mod_time->day > 31 || |
|
1007 |
mod_time->hour > 23 || mod_time->minute > 59 || |
|
1008 |
mod_time->second > 60) |
|
1009 |
{ |
|
1010 |
png_warning(png_ptr, "Ignoring invalid time value"); |
|
35296 | 1011 |
|
29913 | 1012 |
return; |
1013 |
} |
|
1014 |
||
1015 |
info_ptr->mod_time = *mod_time; |
|
2 | 1016 |
info_ptr->valid |= PNG_INFO_tIME; |
1017 |
} |
|
1018 |
#endif |
|
1019 |
||
10576 | 1020 |
#ifdef PNG_tRNS_SUPPORTED |
2 | 1021 |
void PNGAPI |
29913 | 1022 |
png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, |
10576 | 1023 |
png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) |
2 | 1024 |
{ |
10576 | 1025 |
png_debug1(1, "in %s storage function", "tRNS"); |
1026 |
||
2 | 1027 |
if (png_ptr == NULL || info_ptr == NULL) |
35296 | 1028 |
|
2 | 1029 |
return; |
1030 |
||
10576 | 1031 |
if (trans_alpha != NULL) |
2 | 1032 |
{ |
10576 | 1033 |
/* It may not actually be necessary to set png_ptr->trans_alpha here; |
2 | 1034 |
* we do it for backward compatibility with the way the png_handle_tRNS |
1035 |
* function used to do the allocation. |
|
29913 | 1036 |
* |
1037 |
* 1.6.0: The above statement is incorrect; png_handle_tRNS effectively |
|
1038 |
* relies on png_set_tRNS storing the information in png_struct |
|
1039 |
* (otherwise it won't be there for the code in pngrtran.c). |
|
2 | 1040 |
*/ |
10576 | 1041 |
|
2 | 1042 |
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); |
10576 | 1043 |
|
1044 |
if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) |
|
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1045 |
{ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1046 |
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1047 |
info_ptr->trans_alpha = png_voidcast(png_bytep, |
43321 | 1048 |
png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH)); |
51304 | 1049 |
memcpy(info_ptr->trans_alpha, trans_alpha, (size_t)num_trans); |
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1050 |
} |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1051 |
png_ptr->trans_alpha = info_ptr->trans_alpha; |
2 | 1052 |
} |
1053 |
||
10576 | 1054 |
if (trans_color != NULL) |
2 | 1055 |
{ |
35296 | 1056 |
#ifdef PNG_WARNINGS_SUPPORTED |
1057 |
if (info_ptr->bit_depth < 16) |
|
1058 |
{ |
|
1059 |
int sample_max = (1 << info_ptr->bit_depth) - 1; |
|
10576 | 1060 |
|
35296 | 1061 |
if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && |
1062 |
trans_color->gray > sample_max) || |
|
1063 |
(info_ptr->color_type == PNG_COLOR_TYPE_RGB && |
|
1064 |
(trans_color->red > sample_max || |
|
1065 |
trans_color->green > sample_max || |
|
1066 |
trans_color->blue > sample_max))) |
|
1067 |
png_warning(png_ptr, |
|
43321 | 1068 |
"tRNS chunk has out-of-range samples for bit_depth"); |
35296 | 1069 |
} |
1070 |
#endif |
|
10576 | 1071 |
|
29913 | 1072 |
info_ptr->trans_color = *trans_color; |
10576 | 1073 |
|
2 | 1074 |
if (num_trans == 0) |
10576 | 1075 |
num_trans = 1; |
2 | 1076 |
} |
10576 | 1077 |
|
2 | 1078 |
info_ptr->num_trans = (png_uint_16)num_trans; |
10576 | 1079 |
|
1080 |
if (num_trans != 0) |
|
1081 |
{ |
|
1082 |
info_ptr->valid |= PNG_INFO_tRNS; |
|
1083 |
info_ptr->free_me |= PNG_FREE_TRNS; |
|
1084 |
} |
|
2 | 1085 |
} |
1086 |
#endif |
|
1087 |
||
10576 | 1088 |
#ifdef PNG_sPLT_SUPPORTED |
2 | 1089 |
void PNGAPI |
29913 | 1090 |
png_set_sPLT(png_const_structrp png_ptr, |
1091 |
png_inforp info_ptr, png_const_sPLT_tp entries, int nentries) |
|
10576 | 1092 |
/* |
1093 |
* entries - array of png_sPLT_t structures |
|
1094 |
* to be added to the list of palettes |
|
1095 |
* in the info structure. |
|
1096 |
* |
|
1097 |
* nentries - number of palette structures to be |
|
1098 |
* added. |
|
1099 |
*/ |
|
2 | 1100 |
{ |
10576 | 1101 |
png_sPLT_tp np; |
2 | 1102 |
|
29913 | 1103 |
if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL) |
10576 | 1104 |
return; |
2 | 1105 |
|
29913 | 1106 |
/* Use the internal realloc function, which checks for all the possible |
1107 |
* overflows. Notice that the parameters are (int) and (size_t) |
|
1108 |
*/ |
|
1109 |
np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr, |
|
43321 | 1110 |
info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries, |
1111 |
sizeof *np)); |
|
10576 | 1112 |
|
1113 |
if (np == NULL) |
|
1114 |
{ |
|
29913 | 1115 |
/* Out of memory or too many chunks */ |
1116 |
png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR); |
|
35296 | 1117 |
|
2 | 1118 |
return; |
10576 | 1119 |
} |
2 | 1120 |
|
10576 | 1121 |
png_free(png_ptr, info_ptr->splt_palettes); |
29913 | 1122 |
info_ptr->splt_palettes = np; |
1123 |
info_ptr->free_me |= PNG_FREE_SPLT; |
|
2 | 1124 |
|
29913 | 1125 |
np += info_ptr->splt_palettes_num; |
10576 | 1126 |
|
29913 | 1127 |
do |
1128 |
{ |
|
51304 | 1129 |
size_t length; |
10576 | 1130 |
|
29913 | 1131 |
/* Skip invalid input entries */ |
1132 |
if (entries->name == NULL || entries->entries == NULL) |
|
10576 | 1133 |
{ |
29913 | 1134 |
/* png_handle_sPLT doesn't do this, so this is an app error */ |
1135 |
png_app_error(png_ptr, "png_set_sPLT: invalid sPLT"); |
|
1136 |
/* Just skip the invalid entry */ |
|
10576 | 1137 |
continue; |
1138 |
} |
|
2 | 1139 |
|
29913 | 1140 |
np->depth = entries->depth; |
1141 |
||
1142 |
/* In the event of out-of-memory just return - there's no point keeping |
|
1143 |
* on trying to add sPLT chunks. |
|
1144 |
*/ |
|
1145 |
length = strlen(entries->name) + 1; |
|
1146 |
np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length)); |
|
1147 |
||
1148 |
if (np->name == NULL) |
|
1149 |
break; |
|
1150 |
||
1151 |
memcpy(np->name, entries->name, length); |
|
1152 |
||
1153 |
/* IMPORTANT: we have memory now that won't get freed if something else |
|
1154 |
* goes wrong; this code must free it. png_malloc_array produces no |
|
1155 |
* warnings; use a png_chunk_report (below) if there is an error. |
|
1156 |
*/ |
|
1157 |
np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr, |
|
1158 |
entries->nentries, sizeof (png_sPLT_entry))); |
|
1159 |
||
1160 |
if (np->entries == NULL) |
|
1161 |
{ |
|
1162 |
png_free(png_ptr, np->name); |
|
1163 |
np->name = NULL; |
|
1164 |
break; |
|
1165 |
} |
|
10576 | 1166 |
|
29913 | 1167 |
np->nentries = entries->nentries; |
1168 |
/* This multiply can't overflow because png_malloc_array has already |
|
1169 |
* checked it when doing the allocation. |
|
1170 |
*/ |
|
1171 |
memcpy(np->entries, entries->entries, |
|
43321 | 1172 |
(unsigned int)entries->nentries * sizeof (png_sPLT_entry)); |
29913 | 1173 |
|
1174 |
/* Note that 'continue' skips the advance of the out pointer and out |
|
1175 |
* count, so an invalid entry is not added. |
|
1176 |
*/ |
|
1177 |
info_ptr->valid |= PNG_INFO_sPLT; |
|
1178 |
++(info_ptr->splt_palettes_num); |
|
1179 |
++np; |
|
48280 | 1180 |
++entries; |
29913 | 1181 |
} |
48280 | 1182 |
while (--nentries); |
29913 | 1183 |
|
1184 |
if (nentries > 0) |
|
1185 |
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); |
|
1186 |
} |
|
1187 |
#endif /* sPLT */ |
|
1188 |
||
1189 |
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED |
|
1190 |
static png_byte |
|
1191 |
check_location(png_const_structrp png_ptr, int location) |
|
1192 |
{ |
|
1193 |
location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT); |
|
1194 |
||
1195 |
/* New in 1.6.0; copy the location and check it. This is an API |
|
1196 |
* change; previously the app had to use the |
|
1197 |
* png_set_unknown_chunk_location API below for each chunk. |
|
1198 |
*/ |
|
1199 |
if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0) |
|
1200 |
{ |
|
1201 |
/* Write struct, so unknown chunks come from the app */ |
|
1202 |
png_app_warning(png_ptr, |
|
43321 | 1203 |
"png_set_unknown_chunks now expects a valid location"); |
29913 | 1204 |
/* Use the old behavior */ |
1205 |
location = (png_byte)(png_ptr->mode & |
|
43321 | 1206 |
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)); |
10576 | 1207 |
} |
1208 |
||
29913 | 1209 |
/* This need not be an internal error - if the app calls |
1210 |
* png_set_unknown_chunks on a read pointer it must get the location right. |
|
1211 |
*/ |
|
1212 |
if (location == 0) |
|
1213 |
png_error(png_ptr, "invalid location in png_set_unknown_chunks"); |
|
1214 |
||
1215 |
/* Now reduce the location to the top-most set bit by removing each least |
|
1216 |
* significant bit in turn. |
|
1217 |
*/ |
|
1218 |
while (location != (location & -location)) |
|
1219 |
location &= ~(location & -location); |
|
1220 |
||
1221 |
/* The cast is safe because 'location' is a bit mask and only the low four |
|
1222 |
* bits are significant. |
|
1223 |
*/ |
|
1224 |
return (png_byte)location; |
|
2 | 1225 |
} |
1226 |
||
1227 |
void PNGAPI |
|
29913 | 1228 |
png_set_unknown_chunks(png_const_structrp png_ptr, |
43321 | 1229 |
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) |
2 | 1230 |
{ |
10576 | 1231 |
png_unknown_chunkp np; |
2 | 1232 |
|
29913 | 1233 |
if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 || |
35296 | 1234 |
unknowns == NULL) |
10576 | 1235 |
return; |
1236 |
||
29913 | 1237 |
/* Check for the failure cases where support has been disabled at compile |
1238 |
* time. This code is hardly ever compiled - it's here because |
|
1239 |
* STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this |
|
1240 |
* code) but may be meaningless if the read or write handling of unknown |
|
1241 |
* chunks is not compiled in. |
|
1242 |
*/ |
|
1243 |
# if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \ |
|
1244 |
defined(PNG_READ_SUPPORTED) |
|
1245 |
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
|
1246 |
{ |
|
1247 |
png_app_error(png_ptr, "no unknown chunk support on read"); |
|
35296 | 1248 |
|
29913 | 1249 |
return; |
1250 |
} |
|
1251 |
# endif |
|
1252 |
# if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \ |
|
1253 |
defined(PNG_WRITE_SUPPORTED) |
|
1254 |
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) |
|
1255 |
{ |
|
1256 |
png_app_error(png_ptr, "no unknown chunk support on write"); |
|
35296 | 1257 |
|
29913 | 1258 |
return; |
1259 |
} |
|
1260 |
# endif |
|
1261 |
||
1262 |
/* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that |
|
1263 |
* unknown critical chunks could be lost with just a warning resulting in |
|
1264 |
* undefined behavior. Now png_chunk_report is used to provide behavior |
|
1265 |
* appropriate to read or write. |
|
1266 |
*/ |
|
1267 |
np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr, |
|
43321 | 1268 |
info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns, |
1269 |
sizeof *np)); |
|
2 | 1270 |
|
10576 | 1271 |
if (np == NULL) |
1272 |
{ |
|
29913 | 1273 |
png_chunk_report(png_ptr, "too many unknown chunks", |
43321 | 1274 |
PNG_CHUNK_WRITE_ERROR); |
35296 | 1275 |
|
10576 | 1276 |
return; |
1277 |
} |
|
2 | 1278 |
|
29913 | 1279 |
png_free(png_ptr, info_ptr->unknown_chunks); |
1280 |
info_ptr->unknown_chunks = np; /* safe because it is initialized */ |
|
1281 |
info_ptr->free_me |= PNG_FREE_UNKN; |
|
10576 | 1282 |
|
29913 | 1283 |
np += info_ptr->unknown_chunks_num; |
10576 | 1284 |
|
29913 | 1285 |
/* Increment unknown_chunks_num each time round the loop to protect the |
1286 |
* just-allocated chunk data. |
|
1287 |
*/ |
|
1288 |
for (; num_unknowns > 0; --num_unknowns, ++unknowns) |
|
10576 | 1289 |
{ |
29913 | 1290 |
memcpy(np->name, unknowns->name, (sizeof np->name)); |
1291 |
np->name[(sizeof np->name)-1] = '\0'; |
|
1292 |
np->location = check_location(png_ptr, unknowns->location); |
|
2 | 1293 |
|
29913 | 1294 |
if (unknowns->size == 0) |
1295 |
{ |
|
1296 |
np->data = NULL; |
|
1297 |
np->size = 0; |
|
1298 |
} |
|
10576 | 1299 |
|
1300 |
else |
|
1301 |
{ |
|
29913 | 1302 |
np->data = png_voidcast(png_bytep, |
43321 | 1303 |
png_malloc_base(png_ptr, unknowns->size)); |
2 | 1304 |
|
29913 | 1305 |
if (np->data == NULL) |
10576 | 1306 |
{ |
29913 | 1307 |
png_chunk_report(png_ptr, "unknown chunk: out of memory", |
43321 | 1308 |
PNG_CHUNK_WRITE_ERROR); |
29913 | 1309 |
/* But just skip storing the unknown chunk */ |
1310 |
continue; |
|
10576 | 1311 |
} |
2 | 1312 |
|
29913 | 1313 |
memcpy(np->data, unknowns->data, unknowns->size); |
1314 |
np->size = unknowns->size; |
|
10576 | 1315 |
} |
29913 | 1316 |
|
1317 |
/* These increments are skipped on out-of-memory for the data - the |
|
1318 |
* unknown chunk entry gets overwritten if the png_chunk_report returns. |
|
1319 |
* This is correct in the read case (the chunk is just dropped.) |
|
1320 |
*/ |
|
1321 |
++np; |
|
1322 |
++(info_ptr->unknown_chunks_num); |
|
10576 | 1323 |
} |
2 | 1324 |
} |
10576 | 1325 |
|
2 | 1326 |
void PNGAPI |
29913 | 1327 |
png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr, |
10576 | 1328 |
int chunk, int location) |
2 | 1329 |
{ |
29913 | 1330 |
/* This API is pretty pointless in 1.6.0 because the location can be set |
1331 |
* before the call to png_set_unknown_chunks. |
|
1332 |
* |
|
1333 |
* TODO: add a png_app_warning in 1.7 |
|
1334 |
*/ |
|
1335 |
if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && |
|
1336 |
chunk < info_ptr->unknown_chunks_num) |
|
1337 |
{ |
|
1338 |
if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0) |
|
1339 |
{ |
|
1340 |
png_app_error(png_ptr, "invalid unknown chunk location"); |
|
1341 |
/* Fake out the pre 1.6.0 behavior: */ |
|
43321 | 1342 |
if (((unsigned int)location & PNG_HAVE_IDAT) != 0) /* undocumented! */ |
29913 | 1343 |
location = PNG_AFTER_IDAT; |
1344 |
||
1345 |
else |
|
1346 |
location = PNG_HAVE_IHDR; /* also undocumented */ |
|
1347 |
} |
|
1348 |
||
1349 |
info_ptr->unknown_chunks[chunk].location = |
|
1350 |
check_location(png_ptr, location); |
|
1351 |
} |
|
2 | 1352 |
} |
35296 | 1353 |
#endif /* STORE_UNKNOWN_CHUNKS */ |
2 | 1354 |
|
10576 | 1355 |
#ifdef PNG_MNG_FEATURES_SUPPORTED |
2 | 1356 |
png_uint_32 PNGAPI |
29913 | 1357 |
png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features) |
2 | 1358 |
{ |
10576 | 1359 |
png_debug(1, "in png_permit_mng_features"); |
1360 |
||
2 | 1361 |
if (png_ptr == NULL) |
29913 | 1362 |
return 0; |
10576 | 1363 |
|
29913 | 1364 |
png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES; |
10576 | 1365 |
|
29913 | 1366 |
return png_ptr->mng_features_permitted; |
2 | 1367 |
} |
1368 |
#endif |
|
1369 |
||
10576 | 1370 |
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
29913 | 1371 |
static unsigned int |
1372 |
add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep) |
|
1373 |
{ |
|
1374 |
unsigned int i; |
|
1375 |
||
1376 |
/* Utility function: update the 'keep' state of a chunk if it is already in |
|
1377 |
* the list, otherwise add it to the list. |
|
1378 |
*/ |
|
1379 |
for (i=0; i<count; ++i, list += 5) |
|
1380 |
{ |
|
1381 |
if (memcmp(list, add, 4) == 0) |
|
1382 |
{ |
|
1383 |
list[4] = (png_byte)keep; |
|
35296 | 1384 |
|
29913 | 1385 |
return count; |
1386 |
} |
|
1387 |
} |
|
1388 |
||
1389 |
if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT) |
|
1390 |
{ |
|
1391 |
++count; |
|
1392 |
memcpy(list, add, 4); |
|
1393 |
list[4] = (png_byte)keep; |
|
1394 |
} |
|
1395 |
||
1396 |
return count; |
|
1397 |
} |
|
1398 |
||
2 | 1399 |
void PNGAPI |
29913 | 1400 |
png_set_keep_unknown_chunks(png_structrp png_ptr, int keep, |
1401 |
png_const_bytep chunk_list, int num_chunks_in) |
|
2 | 1402 |
{ |
29913 | 1403 |
png_bytep new_list; |
1404 |
unsigned int num_chunks, old_num_chunks; |
|
1405 |
||
10576 | 1406 |
if (png_ptr == NULL) |
1407 |
return; |
|
1408 |
||
29913 | 1409 |
if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST) |
10576 | 1410 |
{ |
29913 | 1411 |
png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep"); |
35296 | 1412 |
|
29913 | 1413 |
return; |
1414 |
} |
|
1415 |
||
1416 |
if (num_chunks_in <= 0) |
|
1417 |
{ |
|
1418 |
png_ptr->unknown_default = keep; |
|
1419 |
||
1420 |
/* '0' means just set the flags, so stop here */ |
|
1421 |
if (num_chunks_in == 0) |
|
1422 |
return; |
|
1423 |
} |
|
10576 | 1424 |
|
29913 | 1425 |
if (num_chunks_in < 0) |
1426 |
{ |
|
1427 |
/* Ignore all unknown chunks and all chunks recognized by |
|
1428 |
* libpng except for IHDR, PLTE, tRNS, IDAT, and IEND |
|
1429 |
*/ |
|
1430 |
static PNG_CONST png_byte chunks_to_ignore[] = { |
|
1431 |
98, 75, 71, 68, '\0', /* bKGD */ |
|
1432 |
99, 72, 82, 77, '\0', /* cHRM */ |
|
48280 | 1433 |
101, 88, 73, 102, '\0', /* eXIf */ |
29913 | 1434 |
103, 65, 77, 65, '\0', /* gAMA */ |
1435 |
104, 73, 83, 84, '\0', /* hIST */ |
|
1436 |
105, 67, 67, 80, '\0', /* iCCP */ |
|
1437 |
105, 84, 88, 116, '\0', /* iTXt */ |
|
1438 |
111, 70, 70, 115, '\0', /* oFFs */ |
|
1439 |
112, 67, 65, 76, '\0', /* pCAL */ |
|
1440 |
112, 72, 89, 115, '\0', /* pHYs */ |
|
1441 |
115, 66, 73, 84, '\0', /* sBIT */ |
|
1442 |
115, 67, 65, 76, '\0', /* sCAL */ |
|
1443 |
115, 80, 76, 84, '\0', /* sPLT */ |
|
1444 |
115, 84, 69, 82, '\0', /* sTER */ |
|
1445 |
115, 82, 71, 66, '\0', /* sRGB */ |
|
1446 |
116, 69, 88, 116, '\0', /* tEXt */ |
|
1447 |
116, 73, 77, 69, '\0', /* tIME */ |
|
1448 |
122, 84, 88, 116, '\0' /* zTXt */ |
|
1449 |
}; |
|
2 | 1450 |
|
29913 | 1451 |
chunk_list = chunks_to_ignore; |
1452 |
num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U; |
|
1453 |
} |
|
10576 | 1454 |
|
29913 | 1455 |
else /* num_chunks_in > 0 */ |
1456 |
{ |
|
1457 |
if (chunk_list == NULL) |
|
1458 |
{ |
|
1459 |
/* Prior to 1.6.0 this was silently ignored, now it is an app_error |
|
1460 |
* which can be switched off. |
|
1461 |
*/ |
|
1462 |
png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list"); |
|
35296 | 1463 |
|
29913 | 1464 |
return; |
1465 |
} |
|
10576 | 1466 |
|
43321 | 1467 |
num_chunks = (unsigned int)num_chunks_in; |
29913 | 1468 |
} |
1469 |
||
1470 |
old_num_chunks = png_ptr->num_chunk_list; |
|
1471 |
if (png_ptr->chunk_list == NULL) |
|
1472 |
old_num_chunks = 0; |
|
1473 |
||
1474 |
/* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow. |
|
1475 |
*/ |
|
1476 |
if (num_chunks + old_num_chunks > UINT_MAX/5) |
|
1477 |
{ |
|
1478 |
png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks"); |
|
35296 | 1479 |
|
2 | 1480 |
return; |
10576 | 1481 |
} |
1482 |
||
29913 | 1483 |
/* If these chunks are being reset to the default then no more memory is |
1484 |
* required because add_one_chunk above doesn't extend the list if the 'keep' |
|
1485 |
* parameter is the default. |
|
1486 |
*/ |
|
1487 |
if (keep != 0) |
|
1488 |
{ |
|
1489 |
new_list = png_voidcast(png_bytep, png_malloc(png_ptr, |
|
1490 |
5 * (num_chunks + old_num_chunks))); |
|
10576 | 1491 |
|
29913 | 1492 |
if (old_num_chunks > 0) |
1493 |
memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); |
|
10576 | 1494 |
} |
1495 |
||
29913 | 1496 |
else if (old_num_chunks > 0) |
1497 |
new_list = png_ptr->chunk_list; |
|
1498 |
||
1499 |
else |
|
1500 |
new_list = NULL; |
|
1501 |
||
1502 |
/* Add the new chunks together with each one's handling code. If the chunk |
|
1503 |
* already exists the code is updated, otherwise the chunk is added to the |
|
1504 |
* end. (In libpng 1.6.0 order no longer matters because this code enforces |
|
1505 |
* the earlier convention that the last setting is the one that is used.) |
|
1506 |
*/ |
|
1507 |
if (new_list != NULL) |
|
1508 |
{ |
|
1509 |
png_const_bytep inlist; |
|
1510 |
png_bytep outlist; |
|
1511 |
unsigned int i; |
|
1512 |
||
1513 |
for (i=0; i<num_chunks; ++i) |
|
1514 |
{ |
|
1515 |
old_num_chunks = add_one_chunk(new_list, old_num_chunks, |
|
43321 | 1516 |
chunk_list+5*i, keep); |
29913 | 1517 |
} |
10576 | 1518 |
|
29913 | 1519 |
/* Now remove any spurious 'default' entries. */ |
1520 |
num_chunks = 0; |
|
1521 |
for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5) |
|
1522 |
{ |
|
1523 |
if (inlist[4]) |
|
1524 |
{ |
|
1525 |
if (outlist != inlist) |
|
1526 |
memcpy(outlist, inlist, 5); |
|
1527 |
outlist += 5; |
|
1528 |
++num_chunks; |
|
1529 |
} |
|
1530 |
} |
|
10576 | 1531 |
|
29913 | 1532 |
/* This means the application has removed all the specialized handling. */ |
1533 |
if (num_chunks == 0) |
|
1534 |
{ |
|
1535 |
if (png_ptr->chunk_list != new_list) |
|
1536 |
png_free(png_ptr, new_list); |
|
1537 |
||
1538 |
new_list = NULL; |
|
1539 |
} |
|
1540 |
} |
|
1541 |
||
1542 |
else |
|
1543 |
num_chunks = 0; |
|
1544 |
||
1545 |
png_ptr->num_chunk_list = num_chunks; |
|
1546 |
||
1547 |
if (png_ptr->chunk_list != new_list) |
|
1548 |
{ |
|
1549 |
if (png_ptr->chunk_list != NULL) |
|
1550 |
png_free(png_ptr, png_ptr->chunk_list); |
|
1551 |
||
1552 |
png_ptr->chunk_list = new_list; |
|
1553 |
} |
|
2 | 1554 |
} |
1555 |
#endif |
|
1556 |
||
10576 | 1557 |
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED |
2 | 1558 |
void PNGAPI |
29913 | 1559 |
png_set_read_user_chunk_fn(png_structrp png_ptr, png_voidp user_chunk_ptr, |
10576 | 1560 |
png_user_chunk_ptr read_user_chunk_fn) |
2 | 1561 |
{ |
10576 | 1562 |
png_debug(1, "in png_set_read_user_chunk_fn"); |
1563 |
||
2 | 1564 |
if (png_ptr == NULL) |
1565 |
return; |
|
10576 | 1566 |
|
2 | 1567 |
png_ptr->read_user_chunk_fn = read_user_chunk_fn; |
1568 |
png_ptr->user_chunk_ptr = user_chunk_ptr; |
|
1569 |
} |
|
1570 |
#endif |
|
1571 |
||
10576 | 1572 |
#ifdef PNG_INFO_IMAGE_SUPPORTED |
2 | 1573 |
void PNGAPI |
29913 | 1574 |
png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr, |
1575 |
png_bytepp row_pointers) |
|
2 | 1576 |
{ |
10576 | 1577 |
png_debug1(1, "in %s storage function", "rows"); |
2 | 1578 |
|
1579 |
if (png_ptr == NULL || info_ptr == NULL) |
|
1580 |
return; |
|
1581 |
||
29913 | 1582 |
if (info_ptr->row_pointers != NULL && |
1583 |
(info_ptr->row_pointers != row_pointers)) |
|
2 | 1584 |
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
10576 | 1585 |
|
2 | 1586 |
info_ptr->row_pointers = row_pointers; |
10576 | 1587 |
|
29913 | 1588 |
if (row_pointers != NULL) |
2 | 1589 |
info_ptr->valid |= PNG_INFO_IDAT; |
1590 |
} |
|
1591 |
#endif |
|
1592 |
||
1593 |
void PNGAPI |
|
51304 | 1594 |
png_set_compression_buffer_size(png_structrp png_ptr, size_t size) |
2 | 1595 |
{ |
43321 | 1596 |
if (png_ptr == NULL) |
1597 |
return; |
|
10576 | 1598 |
|
43321 | 1599 |
if (size == 0 || size > PNG_UINT_31_MAX) |
1600 |
png_error(png_ptr, "invalid compression buffer size"); |
|
10576 | 1601 |
|
29913 | 1602 |
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
43321 | 1603 |
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
1604 |
{ |
|
1605 |
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */ |
|
1606 |
return; |
|
1607 |
} |
|
29913 | 1608 |
# endif |
1609 |
||
1610 |
# ifdef PNG_WRITE_SUPPORTED |
|
43321 | 1611 |
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0) |
1612 |
{ |
|
1613 |
if (png_ptr->zowner != 0) |
|
29913 | 1614 |
{ |
43321 | 1615 |
png_warning(png_ptr, |
1616 |
"Compression buffer size cannot be changed because it is in use"); |
|
35296 | 1617 |
|
43321 | 1618 |
return; |
1619 |
} |
|
10576 | 1620 |
|
35296 | 1621 |
#ifndef __COVERITY__ |
43321 | 1622 |
/* Some compilers complain that this is always false. However, it |
1623 |
* can be true when integer overflow happens. |
|
1624 |
*/ |
|
1625 |
if (size > ZLIB_IO_MAX) |
|
1626 |
{ |
|
1627 |
png_warning(png_ptr, |
|
1628 |
"Compression buffer size limited to system maximum"); |
|
1629 |
size = ZLIB_IO_MAX; /* must fit */ |
|
1630 |
} |
|
35296 | 1631 |
#endif |
10576 | 1632 |
|
43321 | 1633 |
if (size < 6) |
1634 |
{ |
|
1635 |
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH |
|
1636 |
* if this is permitted. |
|
1637 |
*/ |
|
1638 |
png_warning(png_ptr, |
|
1639 |
"Compression buffer size cannot be reduced below 6"); |
|
35296 | 1640 |
|
43321 | 1641 |
return; |
1642 |
} |
|
29913 | 1643 |
|
43321 | 1644 |
if (png_ptr->zbuffer_size != size) |
1645 |
{ |
|
1646 |
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list); |
|
1647 |
png_ptr->zbuffer_size = (uInt)size; |
|
29913 | 1648 |
} |
43321 | 1649 |
} |
29913 | 1650 |
# endif |
2 | 1651 |
} |
1652 |
||
1653 |
void PNGAPI |
|
29913 | 1654 |
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask) |
2 | 1655 |
{ |
29913 | 1656 |
if (png_ptr != NULL && info_ptr != NULL) |
43321 | 1657 |
info_ptr->valid &= (unsigned int)(~mask); |
2 | 1658 |
} |
1659 |
||
1660 |
||
1661 |
#ifdef PNG_SET_USER_LIMITS_SUPPORTED |
|
10576 | 1662 |
/* This function was added to libpng 1.2.6 */ |
2 | 1663 |
void PNGAPI |
29913 | 1664 |
png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, |
2 | 1665 |
png_uint_32 user_height_max) |
1666 |
{ |
|
10576 | 1667 |
/* Images with dimensions larger than these limits will be |
1668 |
* rejected by png_set_IHDR(). To accept any PNG datastream |
|
35296 | 1669 |
* regardless of dimensions, set both limits to 0x7fffffff. |
10576 | 1670 |
*/ |
1671 |
if (png_ptr == NULL) |
|
1672 |
return; |
|
1673 |
||
1674 |
png_ptr->user_width_max = user_width_max; |
|
1675 |
png_ptr->user_height_max = user_height_max; |
|
1676 |
} |
|
1677 |
||
1678 |
/* This function was added to libpng 1.4.0 */ |
|
1679 |
void PNGAPI |
|
29913 | 1680 |
png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max) |
10576 | 1681 |
{ |
35296 | 1682 |
if (png_ptr != NULL) |
1683 |
png_ptr->user_chunk_cache_max = user_chunk_cache_max; |
|
10576 | 1684 |
} |
1685 |
||
1686 |
/* This function was added to libpng 1.4.1 */ |
|
1687 |
void PNGAPI |
|
29913 | 1688 |
png_set_chunk_malloc_max (png_structrp png_ptr, |
10576 | 1689 |
png_alloc_size_t user_chunk_malloc_max) |
1690 |
{ |
|
29913 | 1691 |
if (png_ptr != NULL) |
10576 | 1692 |
png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; |
2 | 1693 |
} |
29913 | 1694 |
#endif /* ?SET_USER_LIMITS */ |
2 | 1695 |
|
10576 | 1696 |
|
1697 |
#ifdef PNG_BENIGN_ERRORS_SUPPORTED |
|
1698 |
void PNGAPI |
|
29913 | 1699 |
png_set_benign_errors(png_structrp png_ptr, int allowed) |
10576 | 1700 |
{ |
1701 |
png_debug(1, "in png_set_benign_errors"); |
|
1702 |
||
29913 | 1703 |
/* If allowed is 1, png_benign_error() is treated as a warning. |
1704 |
* |
|
1705 |
* If allowed is 0, png_benign_error() is treated as an error (which |
|
1706 |
* is the default behavior if png_set_benign_errors() is not called). |
|
1707 |
*/ |
|
1708 |
||
1709 |
if (allowed != 0) |
|
1710 |
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN | |
|
1711 |
PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN; |
|
10576 | 1712 |
|
1713 |
else |
|
29913 | 1714 |
png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN | |
1715 |
PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN); |
|
10576 | 1716 |
} |
29913 | 1717 |
#endif /* BENIGN_ERRORS */ |
1718 |
||
1719 |
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED |
|
1720 |
/* Whether to report invalid palette index; added at libng-1.5.10. |
|
1721 |
* It is possible for an indexed (color-type==3) PNG file to contain |
|
1722 |
* pixels with invalid (out-of-range) indexes if the PLTE chunk has |
|
1723 |
* fewer entries than the image's bit-depth would allow. We recover |
|
1724 |
* from this gracefully by filling any incomplete palette with zeros |
|
1725 |
* (opaque black). By default, when this occurs libpng will issue |
|
1726 |
* a benign error. This API can be used to override that behavior. |
|
1727 |
*/ |
|
1728 |
void PNGAPI |
|
1729 |
png_set_check_for_invalid_index(png_structrp png_ptr, int allowed) |
|
1730 |
{ |
|
1731 |
png_debug(1, "in png_set_check_for_invalid_index"); |
|
1732 |
||
1733 |
if (allowed > 0) |
|
1734 |
png_ptr->num_palette_max = 0; |
|
1735 |
||
1736 |
else |
|
1737 |
png_ptr->num_palette_max = -1; |
|
1738 |
} |
|
1739 |
#endif |
|
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1740 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1741 |
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1742 |
defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1743 |
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1744 |
* and if invalid, correct the keyword rather than discarding the entire |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1745 |
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1746 |
* length, forbids leading or trailing whitespace, multiple internal spaces, |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1747 |
* and the non-break space (0x80) from ISO 8859-1. Returns keyword length. |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1748 |
* |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1749 |
* The 'new_key' buffer must be 80 characters in size (for the keyword plus a |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1750 |
* trailing '\0'). If this routine returns 0 then there was no keyword, or a |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1751 |
* valid one could not be generated, and the caller must png_error. |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1752 |
*/ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1753 |
png_uint_32 /* PRIVATE */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1754 |
png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1755 |
{ |
43321 | 1756 |
#ifdef PNG_WARNINGS_SUPPORTED |
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1757 |
png_const_charp orig_key = key; |
43321 | 1758 |
#endif |
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1759 |
png_uint_32 key_len = 0; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1760 |
int bad_character = 0; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1761 |
int space = 1; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1762 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1763 |
png_debug(1, "in png_check_keyword"); |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1764 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1765 |
if (key == NULL) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1766 |
{ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1767 |
*new_key = 0; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1768 |
return 0; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1769 |
} |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1770 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1771 |
while (*key && key_len < 79) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1772 |
{ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1773 |
png_byte ch = (png_byte)*key++; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1774 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1775 |
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/)) |
48280 | 1776 |
{ |
1777 |
*new_key++ = ch; ++key_len; space = 0; |
|
1778 |
} |
|
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1779 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1780 |
else if (space == 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1781 |
{ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1782 |
/* A space or an invalid character when one wasn't seen immediately |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1783 |
* before; output just a space. |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1784 |
*/ |
48280 | 1785 |
*new_key++ = 32; ++key_len; space = 1; |
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1786 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1787 |
/* If the character was not a space then it is invalid. */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1788 |
if (ch != 32) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1789 |
bad_character = ch; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1790 |
} |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1791 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1792 |
else if (bad_character == 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1793 |
bad_character = ch; /* just skip it, record the first error */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1794 |
} |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1795 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1796 |
if (key_len > 0 && space != 0) /* trailing space */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1797 |
{ |
48280 | 1798 |
--key_len; --new_key; |
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1799 |
if (bad_character == 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1800 |
bad_character = 32; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1801 |
} |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1802 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1803 |
/* Terminate the keyword */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1804 |
*new_key = 0; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1805 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1806 |
if (key_len == 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1807 |
return 0; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1808 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1809 |
#ifdef PNG_WARNINGS_SUPPORTED |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1810 |
/* Try to only output one warning per keyword: */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1811 |
if (*key != 0) /* keyword too long */ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1812 |
png_warning(png_ptr, "keyword truncated"); |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1813 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1814 |
else if (bad_character != 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1815 |
{ |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1816 |
PNG_WARNING_PARAMETERS(p) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1817 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1818 |
png_warning_parameter(p, 1, orig_key); |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1819 |
png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character); |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1820 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1821 |
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'"); |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1822 |
} |
43321 | 1823 |
#else /* !WARNINGS */ |
1824 |
PNG_UNUSED(png_ptr) |
|
1825 |
#endif /* !WARNINGS */ |
|
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1826 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1827 |
return key_len; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1828 |
} |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
1829 |
#endif /* TEXT || pCAL || iCCP || sPLT */ |
29913 | 1830 |
#endif /* READ || WRITE */ |