Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1185)

Side by Side Diff: third_party/libpng/pngerror.c

Issue 1591483003: XFA: Upgrade libpng to 1.6.20. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libpng/pngdebug.h ('k') | third_party/libpng/pngget.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
1 /* pngerror.c - stub functions for i/o and memory allocation 2 /* pngerror.c - stub functions for i/o and memory allocation
2 * 3 *
3 * Last changed in libpng 1.6.1 [March 28, 2013] 4 * Last changed in libpng 1.6.15 [November 20, 2014]
4 * Copyright (c) 1998-2013 Glenn Randers-Pehrson 5 * Copyright (c) 1998-2014 Glenn Randers-Pehrson
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7 * 8 *
8 * This code is released under the libpng license. 9 * This code is released under the libpng license.
9 * For conditions of distribution and use, see the disclaimer 10 * For conditions of distribution and use, see the disclaimer
10 * and license in png.h 11 * and license in png.h
11 * 12 *
12 * This file provides a location for all error handling. Users who 13 * This file provides a location for all error handling. Users who
13 * need special error handling are expected to write replacement functions 14 * need special error handling are expected to write replacement functions
14 * and use png_set_error_fn() to use those functions. See the instructions 15 * and use png_set_error_fn() to use those functions. See the instructions
15 * at each function. 16 * at each function.
16 */ 17 */
17 18
18 #include "pngpriv.h" 19 #include "pngpriv.h"
19 20
20 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 21 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
21 22
22 static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr, 23 static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
23 png_const_charp error_message)),PNG_NORETURN); 24 png_const_charp error_message)),PNG_NORETURN);
24 25
25 #ifdef PNG_WARNINGS_SUPPORTED 26 #ifdef PNG_WARNINGS_SUPPORTED
26 static void /* PRIVATE */ 27 static void /* PRIVATE */
27 png_default_warning PNGARG((png_const_structrp png_ptr, 28 png_default_warning PNGARG((png_const_structrp png_ptr,
28 png_const_charp warning_message)); 29 png_const_charp warning_message));
29 #endif /* PNG_WARNINGS_SUPPORTED */ 30 #endif /* WARNINGS */
30 31
31 /* This function is called whenever there is a fatal error. This function 32 /* This function is called whenever there is a fatal error. This function
32 * should not be changed. If there is a need to handle errors differently, 33 * should not be changed. If there is a need to handle errors differently,
33 * you should supply a replacement error function and use png_set_error_fn() 34 * you should supply a replacement error function and use png_set_error_fn()
34 * to replace the error function at run-time. 35 * to replace the error function at run-time.
35 */ 36 */
36 #ifdef PNG_ERROR_TEXT_SUPPORTED 37 #ifdef PNG_ERROR_TEXT_SUPPORTED
37 PNG_FUNCTION(void,PNGAPI 38 PNG_FUNCTION(void,PNGAPI
38 png_error,(png_const_structrp png_ptr, png_const_charp error_message), 39 png_error,(png_const_structrp png_ptr, png_const_charp error_message),
39 PNG_NORETURN) 40 PNG_NORETURN)
40 { 41 {
41 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 42 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
42 char msg[16]; 43 char msg[16];
43 if (png_ptr != NULL) 44 if (png_ptr != NULL)
44 { 45 {
45 if (png_ptr->flags& 46 if ((png_ptr->flags &
46 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) 47 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0
47 { 48 {
48 if (*error_message == PNG_LITERAL_SHARP) 49 if (*error_message == PNG_LITERAL_SHARP)
49 { 50 {
50 /* Strip "#nnnn " from beginning of error message. */ 51 /* Strip "#nnnn " from beginning of error message. */
51 int offset; 52 int offset;
52 for (offset = 1; offset<15; offset++) 53 for (offset = 1; offset<15; offset++)
53 if (error_message[offset] == ' ') 54 if (error_message[offset] == ' ')
54 break; 55 break;
55 56
56 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) 57 if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
57 { 58 {
58 int i; 59 int i;
59 for (i = 0; i < offset - 1; i++) 60 for (i = 0; i < offset - 1; i++)
60 msg[i] = error_message[i + 1]; 61 msg[i] = error_message[i + 1];
61 msg[i - 1] = '\0'; 62 msg[i - 1] = '\0';
62 error_message = msg; 63 error_message = msg;
63 } 64 }
64 65
65 else 66 else
66 error_message += offset; 67 error_message += offset;
67 } 68 }
68 69
69 else 70 else
70 { 71 {
71 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) 72 if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
72 { 73 {
73 msg[0] = '0'; 74 msg[0] = '0';
74 msg[1] = '\0'; 75 msg[1] = '\0';
75 error_message = msg; 76 error_message = msg;
76 } 77 }
77 } 78 }
78 } 79 }
79 } 80 }
80 #endif 81 #endif
81 if (png_ptr != NULL && png_ptr->error_fn != NULL) 82 if (png_ptr != NULL && png_ptr->error_fn != NULL)
(...skipping 13 matching lines...) Expand all
95 * apparently an error, introduced in libpng-1.2.20, and png_default_error 96 * apparently an error, introduced in libpng-1.2.20, and png_default_error
96 * will crash in this case. 97 * will crash in this case.
97 */ 98 */
98 if (png_ptr != NULL && png_ptr->error_fn != NULL) 99 if (png_ptr != NULL && png_ptr->error_fn != NULL)
99 (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), ""); 100 (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), "");
100 101
101 /* If the custom handler doesn't exist, or if it returns, 102 /* If the custom handler doesn't exist, or if it returns,
102 use the default handler, which will not return. */ 103 use the default handler, which will not return. */
103 png_default_error(png_ptr, ""); 104 png_default_error(png_ptr, "");
104 } 105 }
105 #endif /* PNG_ERROR_TEXT_SUPPORTED */ 106 #endif /* ERROR_TEXT */
106 107
107 /* Utility to safely appends strings to a buffer. This never errors out so 108 /* Utility to safely appends strings to a buffer. This never errors out so
108 * error checking is not required in the caller. 109 * error checking is not required in the caller.
109 */ 110 */
110 size_t 111 size_t
111 png_safecat(png_charp buffer, size_t bufsize, size_t pos, 112 png_safecat(png_charp buffer, size_t bufsize, size_t pos,
112 png_const_charp string) 113 png_const_charp string)
113 { 114 {
114 if (buffer != NULL && pos < bufsize) 115 if (buffer != NULL && pos < bufsize)
115 { 116 {
(...skipping 28 matching lines...) Expand all
144 while (end > start && (number != 0 || count < mincount)) 145 while (end > start && (number != 0 || count < mincount))
145 { 146 {
146 147
147 static const char digits[] = "0123456789ABCDEF"; 148 static const char digits[] = "0123456789ABCDEF";
148 149
149 switch (format) 150 switch (format)
150 { 151 {
151 case PNG_NUMBER_FORMAT_fixed: 152 case PNG_NUMBER_FORMAT_fixed:
152 /* Needs five digits (the fraction) */ 153 /* Needs five digits (the fraction) */
153 mincount = 5; 154 mincount = 5;
154 if (output || number % 10 != 0) 155 if (output != 0 || number % 10 != 0)
155 { 156 {
156 *--end = digits[number % 10]; 157 *--end = digits[number % 10];
157 output = 1; 158 output = 1;
158 } 159 }
159 number /= 10; 160 number /= 10;
160 break; 161 break;
161 162
162 case PNG_NUMBER_FORMAT_02u: 163 case PNG_NUMBER_FORMAT_02u:
163 /* Expects at least 2 digits. */ 164 /* Expects at least 2 digits. */
164 mincount = 2; 165 mincount = 2;
(...skipping 16 matching lines...) Expand all
181 182
182 default: /* an error */ 183 default: /* an error */
183 number = 0; 184 number = 0;
184 break; 185 break;
185 } 186 }
186 187
187 /* Keep track of the number of digits added */ 188 /* Keep track of the number of digits added */
188 ++count; 189 ++count;
189 190
190 /* Float a fixed number here: */ 191 /* Float a fixed number here: */
191 if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start) 192 if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
192 { 193 {
193 /* End of the fraction, but maybe nothing was output? In that case 194 /* End of the fraction, but maybe nothing was output? In that case
194 * drop the decimal point. If the number is a true zero handle that 195 * drop the decimal point. If the number is a true zero handle that
195 * here. 196 * here.
196 */ 197 */
197 if (output) 198 if (output != 0)
198 *--end = '.'; 199 *--end = '.';
199 else if (number == 0) /* and !output */ 200 else if (number == 0) /* and !output */
200 *--end = '0'; 201 *--end = '0';
201 } 202 }
202 } 203 }
203 204
204 return end; 205 return end;
205 } 206 }
206 #endif 207 #endif
207 208
208 #ifdef PNG_WARNINGS_SUPPORTED 209 #ifdef PNG_WARNINGS_SUPPORTED
209 /* This function is called whenever there is a non-fatal error. This function 210 /* This function is called whenever there is a non-fatal error. This function
210 * should not be changed. If there is a need to handle warnings differently, 211 * should not be changed. If there is a need to handle warnings differently,
211 * you should supply a replacement warning function and use 212 * you should supply a replacement warning function and use
212 * png_set_error_fn() to replace the warning function at run-time. 213 * png_set_error_fn() to replace the warning function at run-time.
213 */ 214 */
214 void PNGAPI 215 void PNGAPI
215 png_warning(png_const_structrp png_ptr, png_const_charp warning_message) 216 png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
216 { 217 {
217 int offset = 0; 218 int offset = 0;
218 if (png_ptr != NULL) 219 if (png_ptr != NULL)
219 { 220 {
220 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 221 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
221 if (png_ptr->flags& 222 if ((png_ptr->flags &
222 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) 223 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
223 #endif 224 #endif
224 { 225 {
225 if (*warning_message == PNG_LITERAL_SHARP) 226 if (*warning_message == PNG_LITERAL_SHARP)
226 { 227 {
227 for (offset = 1; offset < 15; offset++) 228 for (offset = 1; offset < 15; offset++)
228 if (warning_message[offset] == ' ') 229 if (warning_message[offset] == ' ')
229 break; 230 break;
230 } 231 }
231 } 232 }
232 } 233 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 348
348 /* i is always less than (sizeof msg), so: */ 349 /* i is always less than (sizeof msg), so: */
349 msg[i] = '\0'; 350 msg[i] = '\0';
350 351
351 /* And this is the formatted message. It may be larger than 352 /* And this is the formatted message. It may be larger than
352 * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these 353 * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these
353 * are not (currently) formatted. 354 * are not (currently) formatted.
354 */ 355 */
355 png_warning(png_ptr, msg); 356 png_warning(png_ptr, msg);
356 } 357 }
357 #endif /* PNG_WARNINGS_SUPPORTED */ 358 #endif /* WARNINGS */
358 359
359 #ifdef PNG_BENIGN_ERRORS_SUPPORTED 360 #ifdef PNG_BENIGN_ERRORS_SUPPORTED
360 void PNGAPI 361 void PNGAPI
361 png_benign_error(png_const_structrp png_ptr, png_const_charp error_message) 362 png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
362 { 363 {
363 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) 364 if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
364 { 365 {
365 # ifdef PNG_READ_SUPPORTED 366 # ifdef PNG_READ_SUPPORTED
366 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && 367 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
367 png_ptr->chunk_name != 0) 368 png_ptr->chunk_name != 0)
368 png_chunk_warning(png_ptr, error_message); 369 png_chunk_warning(png_ptr, error_message);
369 else 370 else
370 # endif 371 # endif
371 png_warning(png_ptr, error_message); 372 png_warning(png_ptr, error_message);
372 } 373 }
373 374
374 else 375 else
375 { 376 {
376 # ifdef PNG_READ_SUPPORTED 377 # ifdef PNG_READ_SUPPORTED
377 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && 378 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
378 png_ptr->chunk_name != 0) 379 png_ptr->chunk_name != 0)
379 png_chunk_error(png_ptr, error_message); 380 png_chunk_error(png_ptr, error_message);
380 else 381 else
381 # endif 382 # endif
382 png_error(png_ptr, error_message); 383 png_error(png_ptr, error_message);
383 } 384 }
385
386 # ifndef PNG_ERROR_TEXT_SUPPORTED
387 PNG_UNUSED(error_message)
388 # endif
384 } 389 }
385 390
386 void /* PRIVATE */ 391 void /* PRIVATE */
387 png_app_warning(png_const_structrp png_ptr, png_const_charp error_message) 392 png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
388 { 393 {
389 if (png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) 394 if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
390 png_warning(png_ptr, error_message); 395 png_warning(png_ptr, error_message);
391 else 396 else
392 png_error(png_ptr, error_message); 397 png_error(png_ptr, error_message);
398
399 # ifndef PNG_ERROR_TEXT_SUPPORTED
400 PNG_UNUSED(error_message)
401 # endif
393 } 402 }
394 403
395 void /* PRIVATE */ 404 void /* PRIVATE */
396 png_app_error(png_const_structrp png_ptr, png_const_charp error_message) 405 png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
397 { 406 {
398 if (png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) 407 if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
399 png_warning(png_ptr, error_message); 408 png_warning(png_ptr, error_message);
400 else 409 else
401 png_error(png_ptr, error_message); 410 png_error(png_ptr, error_message);
411
412 # ifndef PNG_ERROR_TEXT_SUPPORTED
413 PNG_UNUSED(error_message)
414 # endif
402 } 415 }
403 #endif /* BENIGN_ERRORS */ 416 #endif /* BENIGN_ERRORS */
404 417
418 #define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */
419 #if defined(PNG_WARNINGS_SUPPORTED) || \
420 (defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
405 /* These utilities are used internally to build an error message that relates 421 /* These utilities are used internally to build an error message that relates
406 * to the current chunk. The chunk name comes from png_ptr->chunk_name, 422 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
407 * this is used to prefix the message. The message is limited in length 423 * which is used to prefix the message. The message is limited in length
408 * to 63 bytes, the name characters are output as hex digits wrapped in [] 424 * to 63 bytes. The name characters are output as hex digits wrapped in []
409 * if the character is invalid. 425 * if the character is invalid.
410 */ 426 */
411 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) 427 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
412 static PNG_CONST char png_digit[16] = { 428 static PNG_CONST char png_digit[16] = {
413 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 429 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
414 'A', 'B', 'C', 'D', 'E', 'F' 430 'A', 'B', 'C', 'D', 'E', 'F'
415 }; 431 };
416 432
417 #define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
418 #if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
419 static void /* PRIVATE */ 433 static void /* PRIVATE */
420 png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp 434 png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
421 error_message) 435 error_message)
422 { 436 {
423 png_uint_32 chunk_name = png_ptr->chunk_name; 437 png_uint_32 chunk_name = png_ptr->chunk_name;
424 int iout = 0, ishift = 24; 438 int iout = 0, ishift = 24;
425 439
426 while (ishift >= 0) 440 while (ishift >= 0)
427 { 441 {
428 int c = (int)(chunk_name >> ishift) & 0xff; 442 int c = (int)(chunk_name >> ishift) & 0xff;
429 443
430 ishift -= 8; 444 ishift -= 8;
431 if (isnonalpha(c)) 445 if (isnonalpha(c) != 0)
432 { 446 {
433 buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET; 447 buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
434 buffer[iout++] = png_digit[(c & 0xf0) >> 4]; 448 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
435 buffer[iout++] = png_digit[c & 0x0f]; 449 buffer[iout++] = png_digit[c & 0x0f];
436 buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET; 450 buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
437 } 451 }
438 452
439 else 453 else
440 { 454 {
441 buffer[iout++] = (char)c; 455 buffer[iout++] = (char)c;
(...skipping 10 matching lines...) Expand all
452 buffer[iout++] = ':'; 466 buffer[iout++] = ':';
453 buffer[iout++] = ' '; 467 buffer[iout++] = ' ';
454 468
455 while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0') 469 while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0')
456 buffer[iout++] = error_message[iin++]; 470 buffer[iout++] = error_message[iin++];
457 471
458 /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */ 472 /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */
459 buffer[iout] = '\0'; 473 buffer[iout] = '\0';
460 } 474 }
461 } 475 }
462 #endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */ 476 #endif /* WARNINGS || ERROR_TEXT */
463 477
464 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) 478 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
465 PNG_FUNCTION(void,PNGAPI 479 PNG_FUNCTION(void,PNGAPI
466 png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message), 480 png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
467 PNG_NORETURN) 481 PNG_NORETURN)
468 { 482 {
469 char msg[18+PNG_MAX_ERROR_TEXT]; 483 char msg[18+PNG_MAX_ERROR_TEXT];
470 if (png_ptr == NULL) 484 if (png_ptr == NULL)
471 png_error(png_ptr, error_message); 485 png_error(png_ptr, error_message);
472 486
473 else 487 else
474 { 488 {
475 png_format_buffer(png_ptr, msg, error_message); 489 png_format_buffer(png_ptr, msg, error_message);
476 png_error(png_ptr, msg); 490 png_error(png_ptr, msg);
477 } 491 }
478 } 492 }
479 #endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */ 493 #endif /* READ && ERROR_TEXT */
480 494
481 #ifdef PNG_WARNINGS_SUPPORTED 495 #ifdef PNG_WARNINGS_SUPPORTED
482 void PNGAPI 496 void PNGAPI
483 png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message) 497 png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)
484 { 498 {
485 char msg[18+PNG_MAX_ERROR_TEXT]; 499 char msg[18+PNG_MAX_ERROR_TEXT];
486 if (png_ptr == NULL) 500 if (png_ptr == NULL)
487 png_warning(png_ptr, warning_message); 501 png_warning(png_ptr, warning_message);
488 502
489 else 503 else
490 { 504 {
491 png_format_buffer(png_ptr, msg, warning_message); 505 png_format_buffer(png_ptr, msg, warning_message);
492 png_warning(png_ptr, msg); 506 png_warning(png_ptr, msg);
493 } 507 }
494 } 508 }
495 #endif /* PNG_WARNINGS_SUPPORTED */ 509 #endif /* WARNINGS */
496 510
497 #ifdef PNG_READ_SUPPORTED 511 #ifdef PNG_READ_SUPPORTED
498 #ifdef PNG_BENIGN_ERRORS_SUPPORTED 512 #ifdef PNG_BENIGN_ERRORS_SUPPORTED
499 void PNGAPI 513 void PNGAPI
500 png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp 514 png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
501 error_message) 515 error_message)
502 { 516 {
503 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) 517 if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
504 png_chunk_warning(png_ptr, error_message); 518 png_chunk_warning(png_ptr, error_message);
505 519
506 else 520 else
507 png_chunk_error(png_ptr, error_message); 521 png_chunk_error(png_ptr, error_message);
508 } 522
509 #endif 523 # ifndef PNG_ERROR_TEXT_SUPPORTED
510 #endif /* PNG_READ_SUPPORTED */ 524 PNG_UNUSED(error_message)
525 # endif
526 }
527 #endif
528 #endif /* READ */
511 529
512 void /* PRIVATE */ 530 void /* PRIVATE */
513 png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error) 531 png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
514 { 532 {
533 # ifndef PNG_WARNINGS_SUPPORTED
534 PNG_UNUSED(message)
535 # endif
536
515 /* This is always supported, but for just read or just write it 537 /* This is always supported, but for just read or just write it
516 * unconditionally does the right thing. 538 * unconditionally does the right thing.
517 */ 539 */
518 # if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) 540 # if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
519 if (png_ptr->mode & PNG_IS_READ_STRUCT) 541 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
520 # endif 542 # endif
521 543
522 # ifdef PNG_READ_SUPPORTED 544 # ifdef PNG_READ_SUPPORTED
523 { 545 {
524 if (error < PNG_CHUNK_ERROR) 546 if (error < PNG_CHUNK_ERROR)
525 png_chunk_warning(png_ptr, message); 547 png_chunk_warning(png_ptr, message);
526 548
527 else 549 else
528 png_chunk_benign_error(png_ptr, message); 550 png_chunk_benign_error(png_ptr, message);
529 } 551 }
530 # endif 552 # endif
531 553
532 # if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED) 554 # if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
533 else if (!(png_ptr->mode & PNG_IS_READ_STRUCT)) 555 else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
534 # endif 556 # endif
535 557
536 # ifdef PNG_WRITE_SUPPORTED 558 # ifdef PNG_WRITE_SUPPORTED
537 { 559 {
538 if (error < PNG_CHUNK_WRITE_ERROR) 560 if (error < PNG_CHUNK_WRITE_ERROR)
539 png_app_warning(png_ptr, message); 561 png_app_warning(png_ptr, message);
540 562
541 else 563 else
542 png_app_error(png_ptr, message); 564 png_app_error(png_ptr, message);
543 } 565 }
544 # endif 566 # endif
545 } 567 }
546 568
547 #ifdef PNG_ERROR_TEXT_SUPPORTED 569 #ifdef PNG_ERROR_TEXT_SUPPORTED
548 #ifdef PNG_FLOATING_POINT_SUPPORTED 570 #ifdef PNG_FLOATING_POINT_SUPPORTED
549 PNG_FUNCTION(void, 571 PNG_FUNCTION(void,
550 png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN) 572 png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
551 { 573 {
552 # define fixed_message "fixed point overflow in " 574 # define fixed_message "fixed point overflow in "
553 # define fixed_message_ln ((sizeof fixed_message)-1) 575 # define fixed_message_ln ((sizeof fixed_message)-1)
554 int iin; 576 int iin;
555 char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT]; 577 char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
556 memcpy(msg, fixed_message, fixed_message_ln); 578 memcpy(msg, fixed_message, fixed_message_ln);
557 iin = 0; 579 iin = 0;
558 if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0) 580 if (name != NULL)
559 { 581 while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
560 msg[fixed_message_ln + iin] = name[iin]; 582 {
561 ++iin; 583 msg[fixed_message_ln + iin] = name[iin];
562 } 584 ++iin;
585 }
563 msg[fixed_message_ln + iin] = 0; 586 msg[fixed_message_ln + iin] = 0;
564 png_error(png_ptr, msg); 587 png_error(png_ptr, msg);
565 } 588 }
566 #endif 589 #endif
567 #endif 590 #endif
568 591
569 #ifdef PNG_SETJMP_SUPPORTED 592 #ifdef PNG_SETJMP_SUPPORTED
570 /* This API only exists if ANSI-C style error handling is used, 593 /* This API only exists if ANSI-C style error handling is used,
571 * otherwise it is necessary for png_default_error to be overridden. 594 * otherwise it is necessary for png_default_error to be overridden.
572 */ 595 */
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 #else 751 #else
729 PNG_UNUSED(error_message) /* Make compiler happy */ 752 PNG_UNUSED(error_message) /* Make compiler happy */
730 #endif 753 #endif
731 png_longjmp(png_ptr, 1); 754 png_longjmp(png_ptr, 1);
732 } 755 }
733 756
734 PNG_FUNCTION(void,PNGAPI 757 PNG_FUNCTION(void,PNGAPI
735 png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN) 758 png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
736 { 759 {
737 #ifdef PNG_SETJMP_SUPPORTED 760 #ifdef PNG_SETJMP_SUPPORTED
738 if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr) 761 if (png_ptr != NULL && png_ptr->longjmp_fn != NULL &&
762 png_ptr->jmp_buf_ptr != NULL)
739 png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val); 763 png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);
740 #endif 764 #else
741 765 PNG_UNUSED(png_ptr)
742 /* Here if not setjmp support or if png_ptr is null. */ 766 PNG_UNUSED(val)
767 #endif
768
769 /* If control reaches this point, png_longjmp() must not return. The only
770 * choice is to terminate the whole process (or maybe the thread); to do
771 * this the ANSI-C abort() function is used unless a different method is
772 * implemented by overriding the default configuration setting for
773 * PNG_ABORT().
774 */
743 PNG_ABORT(); 775 PNG_ABORT();
744 } 776 }
745 777
746 #ifdef PNG_WARNINGS_SUPPORTED 778 #ifdef PNG_WARNINGS_SUPPORTED
747 /* This function is called when there is a warning, but the library thinks 779 /* This function is called when there is a warning, but the library thinks
748 * it can continue anyway. Replacement functions don't have to do anything 780 * it can continue anyway. Replacement functions don't have to do anything
749 * here if you don't want them to. In the default configuration, png_ptr is 781 * here if you don't want them to. In the default configuration, png_ptr is
750 * not used, but it is passed in case it may be useful. 782 * not used, but it is passed in case it may be useful.
751 */ 783 */
752 static void /* PRIVATE */ 784 static void /* PRIVATE */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 817
786 { 818 {
787 fprintf(stderr, "libpng warning: %s", warning_message); 819 fprintf(stderr, "libpng warning: %s", warning_message);
788 fprintf(stderr, PNG_STRING_NEWLINE); 820 fprintf(stderr, PNG_STRING_NEWLINE);
789 } 821 }
790 #else 822 #else
791 PNG_UNUSED(warning_message) /* Make compiler happy */ 823 PNG_UNUSED(warning_message) /* Make compiler happy */
792 #endif 824 #endif
793 PNG_UNUSED(png_ptr) /* Make compiler happy */ 825 PNG_UNUSED(png_ptr) /* Make compiler happy */
794 } 826 }
795 #endif /* PNG_WARNINGS_SUPPORTED */ 827 #endif /* WARNINGS */
796 828
797 /* This function is called when the application wants to use another method 829 /* This function is called when the application wants to use another method
798 * of handling errors and warnings. Note that the error function MUST NOT 830 * of handling errors and warnings. Note that the error function MUST NOT
799 * return to the calling routine or serious problems will occur. The return 831 * return to the calling routine or serious problems will occur. The return
800 * method used in the default routine calls longjmp(png_ptr->jmp_buf_ptr, 1) 832 * method used in the default routine calls longjmp(png_ptr->jmp_buf_ptr, 1)
801 */ 833 */
802 void PNGAPI 834 void PNGAPI
803 png_set_error_fn(png_structrp png_ptr, png_voidp error_ptr, 835 png_set_error_fn(png_structrp png_ptr, png_voidp error_ptr,
804 png_error_ptr error_fn, png_error_ptr warning_fn) 836 png_error_ptr error_fn, png_error_ptr warning_fn)
805 { 837 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 } 874 }
843 } 875 }
844 #endif 876 #endif
845 877
846 #if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ 878 #if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
847 defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) 879 defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
848 /* Currently the above both depend on SETJMP_SUPPORTED, however it would be 880 /* Currently the above both depend on SETJMP_SUPPORTED, however it would be
849 * possible to implement without setjmp support just so long as there is some 881 * possible to implement without setjmp support just so long as there is some
850 * way to handle the error return here: 882 * way to handle the error return here:
851 */ 883 */
852 PNG_FUNCTION(void /* PRIVATE */, 884 PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
853 png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message), 885 png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
854 PNG_NORETURN) 886 PNG_NORETURN)
855 { 887 {
856 const png_const_structrp png_ptr = png_nonconst_ptr; 888 const png_const_structrp png_ptr = png_nonconst_ptr;
857 png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); 889 png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
858 890
859 /* An error is always logged here, overwriting anything (typically a warning) 891 /* An error is always logged here, overwriting anything (typically a warning)
860 * that is already there: 892 * that is already there:
861 */ 893 */
862 if (image != NULL) 894 if (image != NULL)
863 { 895 {
(...skipping 14 matching lines...) Expand all
878 png_safecat(image->message, (sizeof image->message), pos, 910 png_safecat(image->message, (sizeof image->message), pos,
879 error_message); 911 error_message);
880 } 912 }
881 } 913 }
882 914
883 /* Here on an internal programming error. */ 915 /* Here on an internal programming error. */
884 abort(); 916 abort();
885 } 917 }
886 918
887 #ifdef PNG_WARNINGS_SUPPORTED 919 #ifdef PNG_WARNINGS_SUPPORTED
888 void /* PRIVATE */ 920 void /* PRIVATE */ PNGCBAPI
889 png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message) 921 png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
890 { 922 {
891 const png_const_structrp png_ptr = png_nonconst_ptr; 923 const png_const_structrp png_ptr = png_nonconst_ptr;
892 png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr); 924 png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
893 925
894 /* A warning is only logged if there is no prior warning or error. */ 926 /* A warning is only logged if there is no prior warning or error. */
895 if (image->warning_or_error == 0) 927 if (image->warning_or_error == 0)
896 { 928 {
897 png_safecat(image->message, (sizeof image->message), 0, warning_message); 929 png_safecat(image->message, (sizeof image->message), 0, warning_message);
898 image->warning_or_error |= PNG_IMAGE_WARNING; 930 image->warning_or_error |= PNG_IMAGE_WARNING;
899 } 931 }
900 } 932 }
901 #endif 933 #endif
902 934
903 int /* PRIVATE */ 935 int /* PRIVATE */
904 png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg) 936 png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
905 { 937 {
906 volatile png_imagep image = image_in; 938 volatile png_imagep image = image_in;
907 volatile int result; 939 volatile int result;
908 volatile png_voidp saved_error_buf; 940 volatile png_voidp saved_error_buf;
909 jmp_buf safe_jmpbuf; 941 jmp_buf safe_jmpbuf;
910 942
911 /* Safely execute function(arg) with png_error returning to this function. */ 943 /* Safely execute function(arg) with png_error returning to this function. */
912 saved_error_buf = image->opaque->error_buf; 944 saved_error_buf = image->opaque->error_buf;
913 result = setjmp(safe_jmpbuf) == 0; 945 result = setjmp(safe_jmpbuf) == 0;
914 946
915 if (result) 947 if (result != 0)
916 { 948 {
917 949
918 image->opaque->error_buf = safe_jmpbuf; 950 image->opaque->error_buf = safe_jmpbuf;
919 result = function(arg); 951 result = function(arg);
920 } 952 }
921 953
922 image->opaque->error_buf = saved_error_buf; 954 image->opaque->error_buf = saved_error_buf;
923 955
924 /* And do the cleanup prior to any failure return. */ 956 /* And do the cleanup prior to any failure return. */
925 if (!result) 957 if (result == 0)
926 png_image_free(image); 958 png_image_free(image);
927 959
928 return result; 960 return result;
929 } 961 }
930 #endif /* SIMPLIFIED READ/WRITE */ 962 #endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */
931 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ 963 #endif /* READ || WRITE */
OLDNEW
« no previous file with comments | « third_party/libpng/pngdebug.h ('k') | third_party/libpng/pngget.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698