OLD | NEW |
1 | 1 |
2 /* pngrutil.c - utilities to read a PNG file | 2 /* pngrutil.c - utilities to read a PNG file |
3 * | 3 * |
4 * Last changed in libpng 1.2.43 [February 25, 2010] | 4 * Last changed in libpng 1.2.44 [June 26, 2010] |
5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson |
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
7 * (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.) |
8 * | 8 * |
9 * This code is released under the libpng license. | 9 * This code is released under the libpng license. |
10 * For conditions of distribution and use, see the disclaimer | 10 * For conditions of distribution and use, see the disclaimer |
11 * and license in png.h | 11 * and license in png.h |
12 * | 12 * |
13 * This file contains routines that are only called from within | 13 * This file contains routines that are only called from within |
14 * libpng itself during the course of reading an image. | 14 * libpng itself during the course of reading an image. |
15 */ | 15 */ |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 inflateReset(&png_ptr->zstream); | 264 inflateReset(&png_ptr->zstream); |
265 | 265 |
266 if (ret == Z_STREAM_END) | 266 if (ret == Z_STREAM_END) |
267 return count; /* NOTE: may be zero. */ | 267 return count; /* NOTE: may be zero. */ |
268 | 268 |
269 /* Now handle the error codes - the API always returns 0 | 269 /* Now handle the error codes - the API always returns 0 |
270 * and the error message is dumped into the uncompressed | 270 * and the error message is dumped into the uncompressed |
271 * buffer if available. | 271 * buffer if available. |
272 */ | 272 */ |
273 { | 273 { |
274 char *msg, umsg[52]; | 274 PNG_CONST char *msg; |
275 if (png_ptr->zstream.msg != 0) | 275 if (png_ptr->zstream.msg != 0) |
276 msg = png_ptr->zstream.msg; | 276 msg = png_ptr->zstream.msg; |
277 else | 277 else |
278 { | 278 { |
279 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) | 279 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) |
| 280 char umsg[52]; |
| 281 |
280 switch (ret) | 282 switch (ret) |
281 { | 283 { |
282 case Z_BUF_ERROR: | 284 case Z_BUF_ERROR: |
283 msg = "Buffer error in compressed datastream in %s chunk"; | 285 msg = "Buffer error in compressed datastream in %s chunk"; |
284 break; | 286 break; |
285 case Z_DATA_ERROR: | 287 case Z_DATA_ERROR: |
286 msg = "Data error in compressed datastream in %s chunk"; | 288 msg = "Data error in compressed datastream in %s chunk"; |
287 break; | 289 break; |
288 default: | 290 default: |
289 msg = "Incomplete compressed datastream in %s chunk"; | 291 msg = "Incomplete compressed datastream in %s chunk"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 chunklength - prefix_size, | 336 chunklength - prefix_size, |
335 0/*output*/, 0/*output size*/); | 337 0/*output*/, 0/*output size*/); |
336 | 338 |
337 /* Now check the limits on this chunk - if the limit fails the | 339 /* Now check the limits on this chunk - if the limit fails the |
338 * compressed data will be removed, the prefix will remain. | 340 * compressed data will be removed, the prefix will remain. |
339 */ | 341 */ |
340 #ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED | 342 #ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED |
341 if (png_ptr->user_chunk_malloc_max && | 343 if (png_ptr->user_chunk_malloc_max && |
342 (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1)) | 344 (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1)) |
343 #else | 345 #else |
| 346 #ifdef PNG_USER_CHUNK_MALLOC_MAX |
344 if ((PNG_USER_CHUNK_MALLOC_MAX > 0) && | 347 if ((PNG_USER_CHUNK_MALLOC_MAX > 0) && |
345 prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1) | 348 prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1) |
346 #endif | 349 #endif |
| 350 #endif |
347 png_warning(png_ptr, "Exceeded size limit while expanding chunk"); | 351 png_warning(png_ptr, "Exceeded size limit while expanding chunk"); |
348 | 352 |
349 /* If the size is zero either there was an error and a message | 353 /* If the size is zero either there was an error and a message |
350 * has already been output (warning) or the size really is zero | 354 * has already been output (warning) or the size really is zero |
351 * and we have nothing to do - the code will exit through the | 355 * and we have nothing to do - the code will exit through the |
352 * error case below. | 356 * error case below. |
353 */ | 357 */ |
354 else if (expanded_size > 0) | 358 #if defined(PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED) || \ |
| 359 defined(PNG_USER_CHUNK_MALLOC_MAX) |
| 360 else |
| 361 #endif |
| 362 if (expanded_size > 0 |
355 { | 363 { |
356 /* Success (maybe) - really uncompress the chunk. */ | 364 /* Success (maybe) - really uncompress the chunk. */ |
357 png_size_t new_size = 0; | 365 png_size_t new_size = 0; |
358 png_charp text = png_malloc_warn(png_ptr, | 366 png_charp text = png_malloc_warn(png_ptr, |
359 prefix_size + expanded_size + 1); | 367 prefix_size + expanded_size + 1); |
360 | 368 |
361 if (text != NULL) | 369 if (text != NULL) |
362 { | 370 { |
363 png_memcpy(text, png_ptr->chunkdata, prefix_size); | 371 png_memcpy(text, png_ptr->chunkdata, prefix_size); |
364 new_size = png_inflate(png_ptr, | 372 new_size = png_inflate(png_ptr, |
(...skipping 13 matching lines...) Expand all Loading... |
378 png_warning(png_ptr, "png_inflate logic error"); | 386 png_warning(png_ptr, "png_inflate logic error"); |
379 png_free(png_ptr, text); | 387 png_free(png_ptr, text); |
380 } | 388 } |
381 else | 389 else |
382 png_warning(png_ptr, "Not enough memory to decompress chunk."); | 390 png_warning(png_ptr, "Not enough memory to decompress chunk."); |
383 } | 391 } |
384 } | 392 } |
385 | 393 |
386 else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ | 394 else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ |
387 { | 395 { |
| 396 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) |
388 char umsg[50]; | 397 char umsg[50]; |
389 | 398 |
390 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) | 399 png_snprintf(umsg, sizeof umsg, "Unknown zTXt compression type %d", |
391 png_snprintf(umsg, sizeof umsg, "Unknown zTXt compression type %d", comp_t
ype); | 400 comp_type); |
392 png_warning(png_ptr, umsg); | 401 png_warning(png_ptr, umsg); |
393 #else | 402 #else |
394 png_warning(png_ptr, "Unknown zTXt compression type"); | 403 png_warning(png_ptr, "Unknown zTXt compression type"); |
395 #endif | 404 #endif |
396 | 405 |
397 /* The recovery is to simply drop the data. */ | 406 /* The recovery is to simply drop the data. */ |
398 } | 407 } |
399 | 408 |
400 /* Generic error return - leave the prefix, delete the compressed | 409 /* Generic error return - leave the prefix, delete the compressed |
401 * data, reallocate the chunkdata to remove the potentially large | 410 * data, reallocate the chunkdata to remove the potentially large |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 png_warning(png_ptr, | 909 png_warning(png_ptr, |
901 "Ignoring incorrect cHRM value when sRGB is also present"); | 910 "Ignoring incorrect cHRM value when sRGB is also present"); |
902 #ifdef PNG_CONSOLE_IO_SUPPORTED | 911 #ifdef PNG_CONSOLE_IO_SUPPORTED |
903 #ifdef PNG_FLOATING_POINT_SUPPORTED | 912 #ifdef PNG_FLOATING_POINT_SUPPORTED |
904 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", | 913 fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", |
905 white_x, white_y, red_x, red_y); | 914 white_x, white_y, red_x, red_y); |
906 fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n", | 915 fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n", |
907 green_x, green_y, blue_x, blue_y); | 916 green_x, green_y, blue_x, blue_y); |
908 #else | 917 #else |
909 fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n", | 918 fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n", |
910 int_x_white, int_y_white, int_x_red, int_y_red); | 919 (long)int_x_white, (long)int_y_white, |
| 920 (long)int_x_red, (long)int_y_red); |
911 fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n", | 921 fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n", |
912 int_x_green, int_y_green, int_x_blue, int_y_blue); | 922 (long)int_x_green, (long)int_y_green, |
| 923 (long)int_x_blue, (long)int_y_blue); |
913 #endif | 924 #endif |
914 #endif /* PNG_CONSOLE_IO_SUPPORTED */ | 925 #endif /* PNG_CONSOLE_IO_SUPPORTED */ |
915 } | 926 } |
916 return; | 927 return; |
917 } | 928 } |
918 #endif /* PNG_READ_sRGB_SUPPORTED */ | 929 #endif /* PNG_READ_sRGB_SUPPORTED */ |
919 | 930 |
920 #ifdef PNG_FLOATING_POINT_SUPPORTED | 931 #ifdef PNG_FLOATING_POINT_SUPPORTED |
921 png_set_cHRM(png_ptr, info_ptr, | 932 png_set_cHRM(png_ptr, info_ptr, |
922 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); | 933 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 png_crc_finish(png_ptr, length); | 1811 png_crc_finish(png_ptr, length); |
1801 return; | 1812 return; |
1802 } | 1813 } |
1803 | 1814 |
1804 png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)", | 1815 png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)", |
1805 length + 1); | 1816 length + 1); |
1806 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); | 1817 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); |
1807 if (png_ptr->chunkdata == NULL) | 1818 if (png_ptr->chunkdata == NULL) |
1808 { | 1819 { |
1809 png_warning(png_ptr, "Out of memory while processing sCAL chunk"); | 1820 png_warning(png_ptr, "Out of memory while processing sCAL chunk"); |
| 1821 png_crc_finish(png_ptr, length); |
1810 return; | 1822 return; |
1811 } | 1823 } |
1812 slength = (png_size_t)length; | 1824 slength = (png_size_t)length; |
1813 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); | 1825 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); |
1814 | 1826 |
1815 if (png_crc_finish(png_ptr, 0)) | 1827 if (png_crc_finish(png_ptr, 0)) |
1816 { | 1828 { |
1817 png_free(png_ptr, png_ptr->chunkdata); | 1829 png_free(png_ptr, png_ptr->chunkdata); |
1818 png_ptr->chunkdata = NULL; | 1830 png_ptr->chunkdata = NULL; |
1819 return; | 1831 return; |
1820 } | 1832 } |
1821 | 1833 |
1822 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ | 1834 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ |
1823 | 1835 |
1824 ep = png_ptr->chunkdata + 1; /* Skip unit byte */ | 1836 ep = png_ptr->chunkdata + 1; /* Skip unit byte */ |
1825 | 1837 |
1826 #ifdef PNG_FLOATING_POINT_SUPPORTED | 1838 #ifdef PNG_FLOATING_POINT_SUPPORTED |
1827 width = png_strtod(png_ptr, ep, &vp); | 1839 width = png_strtod(png_ptr, ep, &vp); |
1828 if (*vp) | 1840 if (*vp) |
1829 { | 1841 { |
1830 png_warning(png_ptr, "malformed width string in sCAL chunk"); | 1842 png_warning(png_ptr, "malformed width string in sCAL chunk"); |
| 1843 png_free(png_ptr, png_ptr->chunkdata); |
| 1844 png_ptr->chunkdata = NULL; |
1831 return; | 1845 return; |
1832 } | 1846 } |
1833 #else | 1847 #else |
1834 #ifdef PNG_FIXED_POINT_SUPPORTED | 1848 #ifdef PNG_FIXED_POINT_SUPPORTED |
1835 swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); | 1849 swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); |
1836 if (swidth == NULL) | 1850 if (swidth == NULL) |
1837 { | 1851 { |
1838 png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); | 1852 png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); |
1839 return; | 1853 return; |
1840 } | 1854 } |
1841 png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); | 1855 png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); |
1842 #endif | 1856 #endif |
1843 #endif | 1857 #endif |
1844 | 1858 |
1845 for (ep = png_ptr->chunkdata; *ep; ep++) | 1859 for (ep = png_ptr->chunkdata; *ep; ep++) |
1846 /* Empty loop */ ; | 1860 /* Empty loop */ ; |
1847 ep++; | 1861 ep++; |
1848 | 1862 |
1849 if (png_ptr->chunkdata + slength < ep) | 1863 if (png_ptr->chunkdata + slength < ep) |
1850 { | 1864 { |
1851 png_warning(png_ptr, "Truncated sCAL chunk"); | 1865 png_warning(png_ptr, "Truncated sCAL chunk"); |
1852 #if defined(PNG_FIXED_POINT_SUPPORTED) && \ | 1866 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) |
1853 !defined(PNG_FLOATING_POINT_SUPPORTED) | |
1854 png_free(png_ptr, swidth); | 1867 png_free(png_ptr, swidth); |
1855 #endif | 1868 #endif |
1856 png_free(png_ptr, png_ptr->chunkdata); | 1869 png_free(png_ptr, png_ptr->chunkdata); |
1857 png_ptr->chunkdata = NULL; | 1870 png_ptr->chunkdata = NULL; |
1858 return; | 1871 return; |
1859 } | 1872 } |
1860 | 1873 |
1861 #ifdef PNG_FLOATING_POINT_SUPPORTED | 1874 #ifdef PNG_FLOATING_POINT_SUPPORTED |
1862 height = png_strtod(png_ptr, ep, &vp); | 1875 height = png_strtod(png_ptr, ep, &vp); |
1863 if (*vp) | 1876 if (*vp) |
1864 { | 1877 { |
1865 png_warning(png_ptr, "malformed height string in sCAL chunk"); | 1878 png_warning(png_ptr, "malformed height string in sCAL chunk"); |
| 1879 png_free(png_ptr, png_ptr->chunkdata); |
| 1880 png_ptr->chunkdata = NULL; |
| 1881 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) |
| 1882 png_free(png_ptr, swidth); |
| 1883 #endif |
1866 return; | 1884 return; |
1867 } | 1885 } |
1868 #else | 1886 #else |
1869 #ifdef PNG_FIXED_POINT_SUPPORTED | 1887 #ifdef PNG_FIXED_POINT_SUPPORTED |
1870 sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); | 1888 sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); |
1871 if (sheight == NULL) | 1889 if (sheight == NULL) |
1872 { | 1890 { |
1873 png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); | 1891 png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); |
| 1892 png_free(png_ptr, png_ptr->chunkdata); |
| 1893 png_ptr->chunkdata = NULL; |
| 1894 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) |
| 1895 png_free(png_ptr, swidth); |
| 1896 #endif |
1874 return; | 1897 return; |
1875 } | 1898 } |
1876 png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); | 1899 png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); |
1877 #endif | 1900 #endif |
1878 #endif | 1901 #endif |
1879 | 1902 |
1880 if (png_ptr->chunkdata + slength < ep | 1903 if (png_ptr->chunkdata + slength < ep |
1881 #ifdef PNG_FLOATING_POINT_SUPPORTED | 1904 #ifdef PNG_FLOATING_POINT_SUPPORTED |
1882 || width <= 0. || height <= 0. | 1905 || width <= 0. || height <= 0. |
1883 #endif | 1906 #endif |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3348 png_debug1(3, "height = %lu,", png_ptr->height); | 3371 png_debug1(3, "height = %lu,", png_ptr->height); |
3349 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); | 3372 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); |
3350 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); | 3373 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); |
3351 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); | 3374 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); |
3352 png_debug1(3, "irowbytes = %lu", | 3375 png_debug1(3, "irowbytes = %lu", |
3353 PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); | 3376 PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); |
3354 | 3377 |
3355 png_ptr->flags |= PNG_FLAG_ROW_INIT; | 3378 png_ptr->flags |= PNG_FLAG_ROW_INIT; |
3356 } | 3379 } |
3357 #endif /* PNG_READ_SUPPORTED */ | 3380 #endif /* PNG_READ_SUPPORTED */ |
OLD | NEW |