| OLD | NEW |
| 1 | 1 |
| 2 /* pngpread.c - read a png file in push mode | 2 /* pngpread.c - read a png file in push mode |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.37 [June 4, 2009] | 4 * Last changed in libpng 1.2.43 [February 25, 2010] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson |
| 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson | |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (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 * |
| 9 * This code is released under the libpng license. |
| 10 * For conditions of distribution and use, see the disclaimer |
| 11 * and license in png.h |
| 9 */ | 12 */ |
| 10 | 13 |
| 11 #define PNG_INTERNAL | 14 #define PNG_INTERNAL |
| 15 #define PNG_NO_PEDANTIC_WARNINGS |
| 12 #include "png.h" | 16 #include "png.h" |
| 13 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED | 17 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
| 14 | 18 |
| 15 /* Push model modes */ | 19 /* Push model modes */ |
| 16 #define PNG_READ_SIG_MODE 0 | 20 #define PNG_READ_SIG_MODE 0 |
| 17 #define PNG_READ_CHUNK_MODE 1 | 21 #define PNG_READ_CHUNK_MODE 1 |
| 18 #define PNG_READ_IDAT_MODE 2 | 22 #define PNG_READ_IDAT_MODE 2 |
| 19 #define PNG_SKIP_MODE 3 | 23 #define PNG_SKIP_MODE 3 |
| 20 #define PNG_READ_tEXt_MODE 4 | 24 #define PNG_READ_tEXt_MODE 4 |
| 21 #define PNG_READ_zTXt_MODE 5 | 25 #define PNG_READ_zTXt_MODE 5 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 png_push_read_chunk(png_ptr, info_ptr); | 64 png_push_read_chunk(png_ptr, info_ptr); |
| 61 break; | 65 break; |
| 62 } | 66 } |
| 63 | 67 |
| 64 case PNG_READ_IDAT_MODE: | 68 case PNG_READ_IDAT_MODE: |
| 65 { | 69 { |
| 66 png_push_read_IDAT(png_ptr); | 70 png_push_read_IDAT(png_ptr); |
| 67 break; | 71 break; |
| 68 } | 72 } |
| 69 | 73 |
| 70 #if defined(PNG_READ_tEXt_SUPPORTED) | 74 #ifdef PNG_READ_tEXt_SUPPORTED |
| 71 case PNG_READ_tEXt_MODE: | 75 case PNG_READ_tEXt_MODE: |
| 72 { | 76 { |
| 73 png_push_read_tEXt(png_ptr, info_ptr); | 77 png_push_read_tEXt(png_ptr, info_ptr); |
| 74 break; | 78 break; |
| 75 } | 79 } |
| 76 | 80 |
| 77 #endif | 81 #endif |
| 78 #if defined(PNG_READ_zTXt_SUPPORTED) | 82 #ifdef PNG_READ_zTXt_SUPPORTED |
| 79 case PNG_READ_zTXt_MODE: | 83 case PNG_READ_zTXt_MODE: |
| 80 { | 84 { |
| 81 png_push_read_zTXt(png_ptr, info_ptr); | 85 png_push_read_zTXt(png_ptr, info_ptr); |
| 82 break; | 86 break; |
| 83 } | 87 } |
| 84 | 88 |
| 85 #endif | 89 #endif |
| 86 #if defined(PNG_READ_iTXt_SUPPORTED) | 90 #ifdef PNG_READ_iTXt_SUPPORTED |
| 87 case PNG_READ_iTXt_MODE: | 91 case PNG_READ_iTXt_MODE: |
| 88 { | 92 { |
| 89 png_push_read_iTXt(png_ptr, info_ptr); | 93 png_push_read_iTXt(png_ptr, info_ptr); |
| 90 break; | 94 break; |
| 91 } | 95 } |
| 92 | 96 |
| 93 #endif | 97 #endif |
| 94 case PNG_SKIP_MODE: | 98 case PNG_SKIP_MODE: |
| 95 { | 99 { |
| 96 png_push_crc_finish(png_ptr); | 100 png_push_crc_finish(png_ptr); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 148 } |
| 145 | 149 |
| 146 void /* PRIVATE */ | 150 void /* PRIVATE */ |
| 147 png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) | 151 png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) |
| 148 { | 152 { |
| 149 #ifdef PNG_USE_LOCAL_ARRAYS | 153 #ifdef PNG_USE_LOCAL_ARRAYS |
| 150 PNG_CONST PNG_IHDR; | 154 PNG_CONST PNG_IHDR; |
| 151 PNG_CONST PNG_IDAT; | 155 PNG_CONST PNG_IDAT; |
| 152 PNG_CONST PNG_IEND; | 156 PNG_CONST PNG_IEND; |
| 153 PNG_CONST PNG_PLTE; | 157 PNG_CONST PNG_PLTE; |
| 154 #if defined(PNG_READ_bKGD_SUPPORTED) | 158 #ifdef PNG_READ_bKGD_SUPPORTED |
| 155 PNG_CONST PNG_bKGD; | 159 PNG_CONST PNG_bKGD; |
| 156 #endif | 160 #endif |
| 157 #if defined(PNG_READ_cHRM_SUPPORTED) | 161 #ifdef PNG_READ_cHRM_SUPPORTED |
| 158 PNG_CONST PNG_cHRM; | 162 PNG_CONST PNG_cHRM; |
| 159 #endif | 163 #endif |
| 160 #if defined(PNG_READ_gAMA_SUPPORTED) | 164 #ifdef PNG_READ_gAMA_SUPPORTED |
| 161 PNG_CONST PNG_gAMA; | 165 PNG_CONST PNG_gAMA; |
| 162 #endif | 166 #endif |
| 163 #if defined(PNG_READ_hIST_SUPPORTED) | 167 #ifdef PNG_READ_hIST_SUPPORTED |
| 164 PNG_CONST PNG_hIST; | 168 PNG_CONST PNG_hIST; |
| 165 #endif | 169 #endif |
| 166 #if defined(PNG_READ_iCCP_SUPPORTED) | 170 #ifdef PNG_READ_iCCP_SUPPORTED |
| 167 PNG_CONST PNG_iCCP; | 171 PNG_CONST PNG_iCCP; |
| 168 #endif | 172 #endif |
| 169 #if defined(PNG_READ_iTXt_SUPPORTED) | 173 #ifdef PNG_READ_iTXt_SUPPORTED |
| 170 PNG_CONST PNG_iTXt; | 174 PNG_CONST PNG_iTXt; |
| 171 #endif | 175 #endif |
| 172 #if defined(PNG_READ_oFFs_SUPPORTED) | 176 #ifdef PNG_READ_oFFs_SUPPORTED |
| 173 PNG_CONST PNG_oFFs; | 177 PNG_CONST PNG_oFFs; |
| 174 #endif | 178 #endif |
| 175 #if defined(PNG_READ_pCAL_SUPPORTED) | 179 #ifdef PNG_READ_pCAL_SUPPORTED |
| 176 PNG_CONST PNG_pCAL; | 180 PNG_CONST PNG_pCAL; |
| 177 #endif | 181 #endif |
| 178 #if defined(PNG_READ_pHYs_SUPPORTED) | 182 #ifdef PNG_READ_pHYs_SUPPORTED |
| 179 PNG_CONST PNG_pHYs; | 183 PNG_CONST PNG_pHYs; |
| 180 #endif | 184 #endif |
| 181 #if defined(PNG_READ_sBIT_SUPPORTED) | 185 #ifdef PNG_READ_sBIT_SUPPORTED |
| 182 PNG_CONST PNG_sBIT; | 186 PNG_CONST PNG_sBIT; |
| 183 #endif | 187 #endif |
| 184 #if defined(PNG_READ_sCAL_SUPPORTED) | 188 #ifdef PNG_READ_sCAL_SUPPORTED |
| 185 PNG_CONST PNG_sCAL; | 189 PNG_CONST PNG_sCAL; |
| 186 #endif | 190 #endif |
| 187 #if defined(PNG_READ_sRGB_SUPPORTED) | 191 #ifdef PNG_READ_sRGB_SUPPORTED |
| 188 PNG_CONST PNG_sRGB; | 192 PNG_CONST PNG_sRGB; |
| 189 #endif | 193 #endif |
| 190 #if defined(PNG_READ_sPLT_SUPPORTED) | 194 #ifdef PNG_READ_sPLT_SUPPORTED |
| 191 PNG_CONST PNG_sPLT; | 195 PNG_CONST PNG_sPLT; |
| 192 #endif | 196 #endif |
| 193 #if defined(PNG_READ_tEXt_SUPPORTED) | 197 #ifdef PNG_READ_tEXt_SUPPORTED |
| 194 PNG_CONST PNG_tEXt; | 198 PNG_CONST PNG_tEXt; |
| 195 #endif | 199 #endif |
| 196 #if defined(PNG_READ_tIME_SUPPORTED) | 200 #ifdef PNG_READ_tIME_SUPPORTED |
| 197 PNG_CONST PNG_tIME; | 201 PNG_CONST PNG_tIME; |
| 198 #endif | 202 #endif |
| 199 #if defined(PNG_READ_tRNS_SUPPORTED) | 203 #ifdef PNG_READ_tRNS_SUPPORTED |
| 200 PNG_CONST PNG_tRNS; | 204 PNG_CONST PNG_tRNS; |
| 201 #endif | 205 #endif |
| 202 #if defined(PNG_READ_zTXt_SUPPORTED) | 206 #ifdef PNG_READ_zTXt_SUPPORTED |
| 203 PNG_CONST PNG_zTXt; | 207 PNG_CONST PNG_zTXt; |
| 204 #endif | 208 #endif |
| 205 #endif /* PNG_USE_LOCAL_ARRAYS */ | 209 #endif /* PNG_USE_LOCAL_ARRAYS */ |
| 210 |
| 206 /* First we make sure we have enough data for the 4 byte chunk name | 211 /* First we make sure we have enough data for the 4 byte chunk name |
| 207 * and the 4 byte chunk length before proceeding with decoding the | 212 * and the 4 byte chunk length before proceeding with decoding the |
| 208 * chunk data. To fully decode each of these chunks, we also make | 213 * chunk data. To fully decode each of these chunks, we also make |
| 209 * sure we have enough data in the buffer for the 4 byte CRC at the | 214 * sure we have enough data in the buffer for the 4 byte CRC at the |
| 210 * end of every chunk (except IDAT, which is handled separately). | 215 * end of every chunk (except IDAT, which is handled separately). |
| 211 */ | 216 */ |
| 212 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) | 217 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
| 213 { | 218 { |
| 214 png_byte chunk_length[4]; | 219 png_byte chunk_length[4]; |
| 215 | 220 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return; | 324 return; |
| 320 | 325 |
| 321 if (png_ptr->mode & PNG_AFTER_IDAT) | 326 if (png_ptr->mode & PNG_AFTER_IDAT) |
| 322 png_error(png_ptr, "Too many IDAT's found"); | 327 png_error(png_ptr, "Too many IDAT's found"); |
| 323 } | 328 } |
| 324 | 329 |
| 325 png_ptr->idat_size = png_ptr->push_length; | 330 png_ptr->idat_size = png_ptr->push_length; |
| 326 png_ptr->mode |= PNG_HAVE_IDAT; | 331 png_ptr->mode |= PNG_HAVE_IDAT; |
| 327 png_ptr->process_mode = PNG_READ_IDAT_MODE; | 332 png_ptr->process_mode = PNG_READ_IDAT_MODE; |
| 328 png_push_have_info(png_ptr, info_ptr); | 333 png_push_have_info(png_ptr, info_ptr); |
| 329 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; | 334 png_ptr->zstream.avail_out = |
| 335 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, |
| 336 png_ptr->iwidth) + 1; |
| 330 png_ptr->zstream.next_out = png_ptr->row_buf; | 337 png_ptr->zstream.next_out = png_ptr->row_buf; |
| 331 return; | 338 return; |
| 332 } | 339 } |
| 333 | 340 |
| 334 #if defined(PNG_READ_gAMA_SUPPORTED) | 341 #ifdef PNG_READ_gAMA_SUPPORTED |
| 335 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) | 342 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) |
| 336 { | 343 { |
| 337 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 344 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 338 { | 345 { |
| 339 png_push_save_buffer(png_ptr); | 346 png_push_save_buffer(png_ptr); |
| 340 return; | 347 return; |
| 341 } | 348 } |
| 342 | 349 |
| 343 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); | 350 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); |
| 344 } | 351 } |
| 345 | 352 |
| 346 #endif | 353 #endif |
| 347 #if defined(PNG_READ_sBIT_SUPPORTED) | 354 #ifdef PNG_READ_sBIT_SUPPORTED |
| 348 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) | 355 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) |
| 349 { | 356 { |
| 350 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 357 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 351 { | 358 { |
| 352 png_push_save_buffer(png_ptr); | 359 png_push_save_buffer(png_ptr); |
| 353 return; | 360 return; |
| 354 } | 361 } |
| 355 | 362 |
| 356 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); | 363 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); |
| 357 } | 364 } |
| 358 | 365 |
| 359 #endif | 366 #endif |
| 360 #if defined(PNG_READ_cHRM_SUPPORTED) | 367 #ifdef PNG_READ_cHRM_SUPPORTED |
| 361 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) | 368 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) |
| 362 { | 369 { |
| 363 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 370 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 364 { | 371 { |
| 365 png_push_save_buffer(png_ptr); | 372 png_push_save_buffer(png_ptr); |
| 366 return; | 373 return; |
| 367 } | 374 } |
| 368 | 375 |
| 369 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); | 376 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); |
| 370 } | 377 } |
| 371 | 378 |
| 372 #endif | 379 #endif |
| 373 #if defined(PNG_READ_sRGB_SUPPORTED) | 380 #ifdef PNG_READ_sRGB_SUPPORTED |
| 374 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) | 381 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) |
| 375 { | 382 { |
| 376 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 383 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 377 { | 384 { |
| 378 png_push_save_buffer(png_ptr); | 385 png_push_save_buffer(png_ptr); |
| 379 return; | 386 return; |
| 380 } | 387 } |
| 381 | 388 |
| 382 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); | 389 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); |
| 383 } | 390 } |
| 384 | 391 |
| 385 #endif | 392 #endif |
| 386 #if defined(PNG_READ_iCCP_SUPPORTED) | 393 #ifdef PNG_READ_iCCP_SUPPORTED |
| 387 else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) | 394 else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) |
| 388 { | 395 { |
| 389 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 396 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 390 { | 397 { |
| 391 png_push_save_buffer(png_ptr); | 398 png_push_save_buffer(png_ptr); |
| 392 return; | 399 return; |
| 393 } | 400 } |
| 394 | 401 |
| 395 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); | 402 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); |
| 396 } | 403 } |
| 397 | 404 |
| 398 #endif | 405 #endif |
| 399 #if defined(PNG_READ_sPLT_SUPPORTED) | 406 #ifdef PNG_READ_sPLT_SUPPORTED |
| 400 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) | 407 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) |
| 401 { | 408 { |
| 402 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 409 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 403 { | 410 { |
| 404 png_push_save_buffer(png_ptr); | 411 png_push_save_buffer(png_ptr); |
| 405 return; | 412 return; |
| 406 } | 413 } |
| 407 | 414 |
| 408 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); | 415 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); |
| 409 } | 416 } |
| 410 | 417 |
| 411 #endif | 418 #endif |
| 412 #if defined(PNG_READ_tRNS_SUPPORTED) | 419 #ifdef PNG_READ_tRNS_SUPPORTED |
| 413 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) | 420 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) |
| 414 { | 421 { |
| 415 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 422 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 416 { | 423 { |
| 417 png_push_save_buffer(png_ptr); | 424 png_push_save_buffer(png_ptr); |
| 418 return; | 425 return; |
| 419 } | 426 } |
| 420 | 427 |
| 421 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); | 428 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); |
| 422 } | 429 } |
| 423 | 430 |
| 424 #endif | 431 #endif |
| 425 #if defined(PNG_READ_bKGD_SUPPORTED) | 432 #ifdef PNG_READ_bKGD_SUPPORTED |
| 426 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) | 433 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) |
| 427 { | 434 { |
| 428 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 435 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 429 { | 436 { |
| 430 png_push_save_buffer(png_ptr); | 437 png_push_save_buffer(png_ptr); |
| 431 return; | 438 return; |
| 432 } | 439 } |
| 433 | 440 |
| 434 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); | 441 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); |
| 435 } | 442 } |
| 436 | 443 |
| 437 #endif | 444 #endif |
| 438 #if defined(PNG_READ_hIST_SUPPORTED) | 445 #ifdef PNG_READ_hIST_SUPPORTED |
| 439 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) | 446 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) |
| 440 { | 447 { |
| 441 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 448 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 442 { | 449 { |
| 443 png_push_save_buffer(png_ptr); | 450 png_push_save_buffer(png_ptr); |
| 444 return; | 451 return; |
| 445 } | 452 } |
| 446 | 453 |
| 447 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); | 454 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); |
| 448 } | 455 } |
| 449 | 456 |
| 450 #endif | 457 #endif |
| 451 #if defined(PNG_READ_pHYs_SUPPORTED) | 458 #ifdef PNG_READ_pHYs_SUPPORTED |
| 452 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) | 459 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) |
| 453 { | 460 { |
| 454 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 461 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 455 { | 462 { |
| 456 png_push_save_buffer(png_ptr); | 463 png_push_save_buffer(png_ptr); |
| 457 return; | 464 return; |
| 458 } | 465 } |
| 459 | 466 |
| 460 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); | 467 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); |
| 461 } | 468 } |
| 462 | 469 |
| 463 #endif | 470 #endif |
| 464 #if defined(PNG_READ_oFFs_SUPPORTED) | 471 #ifdef PNG_READ_oFFs_SUPPORTED |
| 465 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) | 472 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) |
| 466 { | 473 { |
| 467 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 474 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 468 { | 475 { |
| 469 png_push_save_buffer(png_ptr); | 476 png_push_save_buffer(png_ptr); |
| 470 return; | 477 return; |
| 471 } | 478 } |
| 472 | 479 |
| 473 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); | 480 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); |
| 474 } | 481 } |
| 475 #endif | 482 #endif |
| 476 | 483 |
| 477 #if defined(PNG_READ_pCAL_SUPPORTED) | 484 #ifdef PNG_READ_pCAL_SUPPORTED |
| 478 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) | 485 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) |
| 479 { | 486 { |
| 480 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 487 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 481 { | 488 { |
| 482 png_push_save_buffer(png_ptr); | 489 png_push_save_buffer(png_ptr); |
| 483 return; | 490 return; |
| 484 } | 491 } |
| 485 | 492 |
| 486 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); | 493 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 487 } | 494 } |
| 488 | 495 |
| 489 #endif | 496 #endif |
| 490 #if defined(PNG_READ_sCAL_SUPPORTED) | 497 #ifdef PNG_READ_sCAL_SUPPORTED |
| 491 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) | 498 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) |
| 492 { | 499 { |
| 493 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 500 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 494 { | 501 { |
| 495 png_push_save_buffer(png_ptr); | 502 png_push_save_buffer(png_ptr); |
| 496 return; | 503 return; |
| 497 } | 504 } |
| 498 | 505 |
| 499 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); | 506 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 500 } | 507 } |
| 501 | 508 |
| 502 #endif | 509 #endif |
| 503 #if defined(PNG_READ_tIME_SUPPORTED) | 510 #ifdef PNG_READ_tIME_SUPPORTED |
| 504 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) | 511 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) |
| 505 { | 512 { |
| 506 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 513 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 507 { | 514 { |
| 508 png_push_save_buffer(png_ptr); | 515 png_push_save_buffer(png_ptr); |
| 509 return; | 516 return; |
| 510 } | 517 } |
| 511 | 518 |
| 512 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); | 519 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); |
| 513 } | 520 } |
| 514 | 521 |
| 515 #endif | 522 #endif |
| 516 #if defined(PNG_READ_tEXt_SUPPORTED) | 523 #ifdef PNG_READ_tEXt_SUPPORTED |
| 517 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) | 524 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) |
| 518 { | 525 { |
| 519 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 526 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 520 { | 527 { |
| 521 png_push_save_buffer(png_ptr); | 528 png_push_save_buffer(png_ptr); |
| 522 return; | 529 return; |
| 523 } | 530 } |
| 524 | 531 |
| 525 png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); | 532 png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); |
| 526 } | 533 } |
| 527 | 534 |
| 528 #endif | 535 #endif |
| 529 #if defined(PNG_READ_zTXt_SUPPORTED) | 536 #ifdef PNG_READ_zTXt_SUPPORTED |
| 530 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) | 537 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) |
| 531 { | 538 { |
| 532 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 539 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 533 { | 540 { |
| 534 png_push_save_buffer(png_ptr); | 541 png_push_save_buffer(png_ptr); |
| 535 return; | 542 return; |
| 536 } | 543 } |
| 537 | 544 |
| 538 png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); | 545 png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); |
| 539 } | 546 } |
| 540 | 547 |
| 541 #endif | 548 #endif |
| 542 #if defined(PNG_READ_iTXt_SUPPORTED) | 549 #ifdef PNG_READ_iTXt_SUPPORTED |
| 543 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) | 550 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) |
| 544 { | 551 { |
| 545 if (png_ptr->push_length + 4 > png_ptr->buffer_size) | 552 if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 546 { | 553 { |
| 547 png_push_save_buffer(png_ptr); | 554 png_push_save_buffer(png_ptr); |
| 548 return; | 555 return; |
| 549 } | 556 } |
| 550 | 557 |
| 551 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); | 558 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); |
| 552 } | 559 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 png_bytep old_buffer; | 695 png_bytep old_buffer; |
| 689 | 696 |
| 690 if (png_ptr->save_buffer_size > PNG_SIZE_MAX - | 697 if (png_ptr->save_buffer_size > PNG_SIZE_MAX - |
| 691 (png_ptr->current_buffer_size + 256)) | 698 (png_ptr->current_buffer_size + 256)) |
| 692 { | 699 { |
| 693 png_error(png_ptr, "Potential overflow of save_buffer"); | 700 png_error(png_ptr, "Potential overflow of save_buffer"); |
| 694 } | 701 } |
| 695 | 702 |
| 696 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; | 703 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; |
| 697 old_buffer = png_ptr->save_buffer; | 704 old_buffer = png_ptr->save_buffer; |
| 698 png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, | 705 png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, |
| 699 (png_uint_32)new_max); | 706 (png_uint_32)new_max); |
| 707 if (png_ptr->save_buffer == NULL) |
| 708 { |
| 709 png_free(png_ptr, old_buffer); |
| 710 png_error(png_ptr, "Insufficient memory for save_buffer"); |
| 711 } |
| 700 png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); | 712 png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); |
| 701 png_free(png_ptr, old_buffer); | 713 png_free(png_ptr, old_buffer); |
| 702 png_ptr->save_buffer_max = new_max; | 714 png_ptr->save_buffer_max = new_max; |
| 703 } | 715 } |
| 704 if (png_ptr->current_buffer_size) | 716 if (png_ptr->current_buffer_size) |
| 705 { | 717 { |
| 706 png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, | 718 png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, |
| 707 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); | 719 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); |
| 708 png_ptr->save_buffer_size += png_ptr->current_buffer_size; | 720 png_ptr->save_buffer_size += png_ptr->current_buffer_size; |
| 709 png_ptr->current_buffer_size = 0; | 721 png_ptr->current_buffer_size = 0; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 | 801 |
| 790 /* Check for overflow */ | 802 /* Check for overflow */ |
| 791 if ((png_uint_32)save_size != png_ptr->idat_size) | 803 if ((png_uint_32)save_size != png_ptr->idat_size) |
| 792 png_error(png_ptr, "save_size overflowed in pngpread"); | 804 png_error(png_ptr, "save_size overflowed in pngpread"); |
| 793 } | 805 } |
| 794 else | 806 else |
| 795 save_size = png_ptr->current_buffer_size; | 807 save_size = png_ptr->current_buffer_size; |
| 796 | 808 |
| 797 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); | 809 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
| 798 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) | 810 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) |
| 799 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); | 811 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); |
| 800 | 812 |
| 801 png_ptr->idat_size -= save_size; | 813 png_ptr->idat_size -= save_size; |
| 802 png_ptr->buffer_size -= save_size; | 814 png_ptr->buffer_size -= save_size; |
| 803 png_ptr->current_buffer_size -= save_size; | 815 png_ptr->current_buffer_size -= save_size; |
| 804 png_ptr->current_buffer_ptr += save_size; | 816 png_ptr->current_buffer_ptr += save_size; |
| 805 } | 817 } |
| 806 if (!png_ptr->idat_size) | 818 if (!png_ptr->idat_size) |
| 807 { | 819 { |
| 808 if (png_ptr->buffer_size < 4) | 820 if (png_ptr->buffer_size < 4) |
| 809 { | 821 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 } | 861 } |
| 850 else if (ret == Z_BUF_ERROR) | 862 else if (ret == Z_BUF_ERROR) |
| 851 break; | 863 break; |
| 852 | 864 |
| 853 else | 865 else |
| 854 png_error(png_ptr, "Decompression Error"); | 866 png_error(png_ptr, "Decompression Error"); |
| 855 } | 867 } |
| 856 if (!(png_ptr->zstream.avail_out)) | 868 if (!(png_ptr->zstream.avail_out)) |
| 857 { | 869 { |
| 858 if (( | 870 if (( |
| 859 #if defined(PNG_READ_INTERLACING_SUPPORTED) | 871 #ifdef PNG_READ_INTERLACING_SUPPORTED |
| 860 png_ptr->interlaced && png_ptr->pass > 6) || | 872 png_ptr->interlaced && png_ptr->pass > 6) || |
| 861 (!png_ptr->interlaced && | 873 (!png_ptr->interlaced && |
| 862 #endif | 874 #endif |
| 863 png_ptr->row_number == png_ptr->num_rows)) | 875 png_ptr->row_number == png_ptr->num_rows)) |
| 864 { | 876 { |
| 865 if (png_ptr->zstream.avail_in) | 877 if (png_ptr->zstream.avail_in) |
| 866 png_warning(png_ptr, "Too much data in IDAT chunks"); | 878 png_warning(png_ptr, "Too much data in IDAT chunks"); |
| 867 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; | 879 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
| 868 break; | 880 break; |
| 869 } | 881 } |
| 870 png_push_process_row(png_ptr); | 882 png_push_process_row(png_ptr); |
| 871 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; | 883 png_ptr->zstream.avail_out = |
| 884 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, |
| 885 png_ptr->iwidth) + 1; |
| 872 png_ptr->zstream.next_out = png_ptr->row_buf; | 886 png_ptr->zstream.next_out = png_ptr->row_buf; |
| 873 } | 887 } |
| 874 | 888 |
| 875 else | 889 else |
| 876 break; | 890 break; |
| 877 } | 891 } |
| 878 } | 892 } |
| 879 | 893 |
| 880 void /* PRIVATE */ | 894 void /* PRIVATE */ |
| 881 png_push_process_row(png_structp png_ptr) | 895 png_push_process_row(png_structp png_ptr) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 892 png_read_filter_row(png_ptr, &(png_ptr->row_info), | 906 png_read_filter_row(png_ptr, &(png_ptr->row_info), |
| 893 png_ptr->row_buf + 1, png_ptr->prev_row + 1, | 907 png_ptr->row_buf + 1, png_ptr->prev_row + 1, |
| 894 (int)(png_ptr->row_buf[0])); | 908 (int)(png_ptr->row_buf[0])); |
| 895 | 909 |
| 896 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, | 910 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, |
| 897 png_ptr->rowbytes + 1); | 911 png_ptr->rowbytes + 1); |
| 898 | 912 |
| 899 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) | 913 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) |
| 900 png_do_read_transformations(png_ptr); | 914 png_do_read_transformations(png_ptr); |
| 901 | 915 |
| 902 #if defined(PNG_READ_INTERLACING_SUPPORTED) | 916 #ifdef PNG_READ_INTERLACING_SUPPORTED |
| 903 /* Blow up interlaced rows to full size */ | 917 /* Blow up interlaced rows to full size */ |
| 904 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) | 918 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 905 { | 919 { |
| 906 if (png_ptr->pass < 6) | 920 if (png_ptr->pass < 6) |
| 907 /* old interface (pre-1.0.9): | 921 /* old interface (pre-1.0.9): |
| 908 png_do_read_interlace(&(png_ptr->row_info), | 922 png_do_read_interlace(&(png_ptr->row_info), |
| 909 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); | 923 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); |
| 910 */ | 924 */ |
| 911 png_do_read_interlace(png_ptr); | 925 png_do_read_interlace(png_ptr); |
| 912 | 926 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 /* Height of interlace block. This is not currently used - if you need | 1118 /* Height of interlace block. This is not currently used - if you need |
| 1105 * it, uncomment it here and in png.h | 1119 * it, uncomment it here and in png.h |
| 1106 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; | 1120 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
| 1107 */ | 1121 */ |
| 1108 #endif | 1122 #endif |
| 1109 | 1123 |
| 1110 png_ptr->row_number++; | 1124 png_ptr->row_number++; |
| 1111 if (png_ptr->row_number < png_ptr->num_rows) | 1125 if (png_ptr->row_number < png_ptr->num_rows) |
| 1112 return; | 1126 return; |
| 1113 | 1127 |
| 1114 #if defined(PNG_READ_INTERLACING_SUPPORTED) | 1128 #ifdef PNG_READ_INTERLACING_SUPPORTED |
| 1115 if (png_ptr->interlaced) | 1129 if (png_ptr->interlaced) |
| 1116 { | 1130 { |
| 1117 png_ptr->row_number = 0; | 1131 png_ptr->row_number = 0; |
| 1118 png_memset_check(png_ptr, png_ptr->prev_row, 0, | 1132 png_memset_check(png_ptr, png_ptr->prev_row, 0, |
| 1119 png_ptr->rowbytes + 1); | 1133 png_ptr->rowbytes + 1); |
| 1120 do | 1134 do |
| 1121 { | 1135 { |
| 1122 png_ptr->pass++; | 1136 png_ptr->pass++; |
| 1123 if ((png_ptr->pass == 1 && png_ptr->width < 5) || | 1137 if ((png_ptr->pass == 1 && png_ptr->width < 5) || |
| 1124 (png_ptr->pass == 3 && png_ptr->width < 3) || | 1138 (png_ptr->pass == 3 && png_ptr->width < 3) || |
| 1125 (png_ptr->pass == 5 && png_ptr->width < 2)) | 1139 (png_ptr->pass == 5 && png_ptr->width < 2)) |
| 1126 png_ptr->pass++; | 1140 png_ptr->pass++; |
| 1127 | 1141 |
| 1128 if (png_ptr->pass > 7) | 1142 if (png_ptr->pass > 7) |
| 1129 png_ptr->pass--; | 1143 png_ptr->pass--; |
| 1130 | 1144 |
| 1131 if (png_ptr->pass >= 7) | 1145 if (png_ptr->pass >= 7) |
| 1132 break; | 1146 break; |
| 1133 | 1147 |
| 1134 png_ptr->iwidth = (png_ptr->width + | 1148 png_ptr->iwidth = (png_ptr->width + |
| 1135 png_pass_inc[png_ptr->pass] - 1 - | 1149 png_pass_inc[png_ptr->pass] - 1 - |
| 1136 png_pass_start[png_ptr->pass]) / | 1150 png_pass_start[png_ptr->pass]) / |
| 1137 png_pass_inc[png_ptr->pass]; | 1151 png_pass_inc[png_ptr->pass]; |
| 1138 | 1152 |
| 1139 png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, | |
| 1140 png_ptr->iwidth) + 1; | |
| 1141 | |
| 1142 if (png_ptr->transformations & PNG_INTERLACE) | 1153 if (png_ptr->transformations & PNG_INTERLACE) |
| 1143 break; | 1154 break; |
| 1144 | 1155 |
| 1145 png_ptr->num_rows = (png_ptr->height + | 1156 png_ptr->num_rows = (png_ptr->height + |
| 1146 png_pass_yinc[png_ptr->pass] - 1 - | 1157 png_pass_yinc[png_ptr->pass] - 1 - |
| 1147 png_pass_ystart[png_ptr->pass]) / | 1158 png_pass_ystart[png_ptr->pass]) / |
| 1148 png_pass_yinc[png_ptr->pass]; | 1159 png_pass_yinc[png_ptr->pass]; |
| 1149 | 1160 |
| 1150 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); | 1161 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); |
| 1151 } | 1162 } |
| 1152 #endif /* PNG_READ_INTERLACING_SUPPORTED */ | 1163 #endif /* PNG_READ_INTERLACING_SUPPORTED */ |
| 1153 } | 1164 } |
| 1154 | 1165 |
| 1155 #if defined(PNG_READ_tEXt_SUPPORTED) | 1166 #ifdef PNG_READ_tEXt_SUPPORTED |
| 1156 void /* PRIVATE */ | 1167 void /* PRIVATE */ |
| 1157 png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 | 1168 png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1158 length) | 1169 length) |
| 1159 { | 1170 { |
| 1160 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) | 1171 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) |
| 1161 { | 1172 { |
| 1162 png_error(png_ptr, "Out of place tEXt"); | 1173 png_error(png_ptr, "Out of place tEXt"); |
| 1163 info_ptr = info_ptr; /* To quiet some compiler warnings */ | 1174 info_ptr = info_ptr; /* To quiet some compiler warnings */ |
| 1164 } | 1175 } |
| 1165 | 1176 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 int ret; | 1219 int ret; |
| 1209 | 1220 |
| 1210 if (png_ptr->buffer_size < 4) | 1221 if (png_ptr->buffer_size < 4) |
| 1211 { | 1222 { |
| 1212 png_push_save_buffer(png_ptr); | 1223 png_push_save_buffer(png_ptr); |
| 1213 return; | 1224 return; |
| 1214 } | 1225 } |
| 1215 | 1226 |
| 1216 png_push_crc_finish(png_ptr); | 1227 png_push_crc_finish(png_ptr); |
| 1217 | 1228 |
| 1218 #if defined(PNG_MAX_MALLOC_64K) | 1229 #ifdef PNG_MAX_MALLOC_64K |
| 1219 if (png_ptr->skip_length) | 1230 if (png_ptr->skip_length) |
| 1220 return; | 1231 return; |
| 1221 #endif | 1232 #endif |
| 1222 | 1233 |
| 1223 key = png_ptr->current_text; | 1234 key = png_ptr->current_text; |
| 1224 | 1235 |
| 1225 for (text = key; *text; text++) | 1236 for (text = key; *text; text++) |
| 1226 /* Empty loop */ ; | 1237 /* Empty loop */ ; |
| 1227 | 1238 |
| 1228 if (text < key + png_ptr->current_text_size) | 1239 if (text < key + png_ptr->current_text_size) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1243 png_free(png_ptr, key); | 1254 png_free(png_ptr, key); |
| 1244 png_free(png_ptr, text_ptr); | 1255 png_free(png_ptr, text_ptr); |
| 1245 png_ptr->current_text = NULL; | 1256 png_ptr->current_text = NULL; |
| 1246 | 1257 |
| 1247 if (ret) | 1258 if (ret) |
| 1248 png_warning(png_ptr, "Insufficient memory to store text chunk."); | 1259 png_warning(png_ptr, "Insufficient memory to store text chunk."); |
| 1249 } | 1260 } |
| 1250 } | 1261 } |
| 1251 #endif | 1262 #endif |
| 1252 | 1263 |
| 1253 #if defined(PNG_READ_zTXt_SUPPORTED) | 1264 #ifdef PNG_READ_zTXt_SUPPORTED |
| 1254 void /* PRIVATE */ | 1265 void /* PRIVATE */ |
| 1255 png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 | 1266 png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1256 length) | 1267 length) |
| 1257 { | 1268 { |
| 1258 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) | 1269 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) |
| 1259 { | 1270 { |
| 1260 png_error(png_ptr, "Out of place zTXt"); | 1271 png_error(png_ptr, "Out of place zTXt"); |
| 1261 info_ptr = info_ptr; /* To quiet some compiler warnings */ | 1272 info_ptr = info_ptr; /* To quiet some compiler warnings */ |
| 1262 } | 1273 } |
| 1263 | 1274 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 | 1455 |
| 1445 png_free(png_ptr, key); | 1456 png_free(png_ptr, key); |
| 1446 png_free(png_ptr, text_ptr); | 1457 png_free(png_ptr, text_ptr); |
| 1447 | 1458 |
| 1448 if (ret) | 1459 if (ret) |
| 1449 png_warning(png_ptr, "Insufficient memory to store text chunk."); | 1460 png_warning(png_ptr, "Insufficient memory to store text chunk."); |
| 1450 } | 1461 } |
| 1451 } | 1462 } |
| 1452 #endif | 1463 #endif |
| 1453 | 1464 |
| 1454 #if defined(PNG_READ_iTXt_SUPPORTED) | 1465 #ifdef PNG_READ_iTXt_SUPPORTED |
| 1455 void /* PRIVATE */ | 1466 void /* PRIVATE */ |
| 1456 png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 | 1467 png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1457 length) | 1468 length) |
| 1458 { | 1469 { |
| 1459 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) | 1470 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) |
| 1460 { | 1471 { |
| 1461 png_error(png_ptr, "Out of place iTXt"); | 1472 png_error(png_ptr, "Out of place iTXt"); |
| 1462 info_ptr = info_ptr; /* To quiet some compiler warnings */ | 1473 info_ptr = info_ptr; /* To quiet some compiler warnings */ |
| 1463 } | 1474 } |
| 1464 | 1475 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 int ret; | 1522 int ret; |
| 1512 | 1523 |
| 1513 if (png_ptr->buffer_size < 4) | 1524 if (png_ptr->buffer_size < 4) |
| 1514 { | 1525 { |
| 1515 png_push_save_buffer(png_ptr); | 1526 png_push_save_buffer(png_ptr); |
| 1516 return; | 1527 return; |
| 1517 } | 1528 } |
| 1518 | 1529 |
| 1519 png_push_crc_finish(png_ptr); | 1530 png_push_crc_finish(png_ptr); |
| 1520 | 1531 |
| 1521 #if defined(PNG_MAX_MALLOC_64K) | 1532 #ifdef PNG_MAX_MALLOC_64K |
| 1522 if (png_ptr->skip_length) | 1533 if (png_ptr->skip_length) |
| 1523 return; | 1534 return; |
| 1524 #endif | 1535 #endif |
| 1525 | 1536 |
| 1526 key = png_ptr->current_text; | 1537 key = png_ptr->current_text; |
| 1527 | 1538 |
| 1528 for (lang = key; *lang; lang++) | 1539 for (lang = key; *lang; lang++) |
| 1529 /* Empty loop */ ; | 1540 /* Empty loop */ ; |
| 1530 | 1541 |
| 1531 if (lang < key + png_ptr->current_text_size - 3) | 1542 if (lang < key + png_ptr->current_text_size - 3) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1560 text_ptr->text = text; | 1571 text_ptr->text = text; |
| 1561 text_ptr->text_length = 0; | 1572 text_ptr->text_length = 0; |
| 1562 text_ptr->itxt_length = png_strlen(text); | 1573 text_ptr->itxt_length = png_strlen(text); |
| 1563 | 1574 |
| 1564 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); | 1575 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); |
| 1565 | 1576 |
| 1566 png_ptr->current_text = NULL; | 1577 png_ptr->current_text = NULL; |
| 1567 | 1578 |
| 1568 png_free(png_ptr, text_ptr); | 1579 png_free(png_ptr, text_ptr); |
| 1569 if (ret) | 1580 if (ret) |
| 1570 png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); | 1581 png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); |
| 1571 } | 1582 } |
| 1572 } | 1583 } |
| 1573 #endif | 1584 #endif |
| 1574 | 1585 |
| 1575 /* This function is called when we haven't found a handler for this | 1586 /* This function is called when we haven't found a handler for this |
| 1576 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk | 1587 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk |
| 1577 * name or a critical chunk), the chunk is (currently) silently ignored. | 1588 * name or a critical chunk), the chunk is (currently) silently ignored. |
| 1578 */ | 1589 */ |
| 1579 void /* PRIVATE */ | 1590 void /* PRIVATE */ |
| 1580 png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 | 1591 png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1581 length) | 1592 length) |
| 1582 { | 1593 { |
| 1583 png_uint_32 skip = 0; | 1594 png_uint_32 skip = 0; |
| 1584 | 1595 |
| 1585 if (!(png_ptr->chunk_name[0] & 0x20)) | 1596 if (!(png_ptr->chunk_name[0] & 0x20)) |
| 1586 { | 1597 { |
| 1587 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) | 1598 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED |
| 1588 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != | 1599 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != |
| 1589 PNG_HANDLE_CHUNK_ALWAYS | 1600 PNG_HANDLE_CHUNK_ALWAYS |
| 1590 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) | 1601 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED |
| 1591 && png_ptr->read_user_chunk_fn == NULL | 1602 && png_ptr->read_user_chunk_fn == NULL |
| 1592 #endif | 1603 #endif |
| 1593 ) | 1604 ) |
| 1594 #endif | 1605 #endif |
| 1595 png_chunk_error(png_ptr, "unknown critical chunk"); | 1606 png_chunk_error(png_ptr, "unknown critical chunk"); |
| 1596 | 1607 |
| 1597 info_ptr = info_ptr; /* To quiet some compiler warnings */ | 1608 info_ptr = info_ptr; /* To quiet some compiler warnings */ |
| 1598 } | 1609 } |
| 1599 | 1610 |
| 1600 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) | 1611 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED |
| 1601 if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) | 1612 if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) |
| 1602 { | 1613 { |
| 1603 #ifdef PNG_MAX_MALLOC_64K | 1614 #ifdef PNG_MAX_MALLOC_64K |
| 1604 if (length > (png_uint_32)65535L) | 1615 if (length > (png_uint_32)65535L) |
| 1605 { | 1616 { |
| 1606 png_warning(png_ptr, "unknown chunk too large to fit in memory"); | 1617 png_warning(png_ptr, "unknown chunk too large to fit in memory"); |
| 1607 skip = length - (png_uint_32)65535L; | 1618 skip = length - (png_uint_32)65535L; |
| 1608 length = (png_uint_32)65535L; | 1619 length = (png_uint_32)65535L; |
| 1609 } | 1620 } |
| 1610 #endif | 1621 #endif |
| 1611 png_memcpy((png_charp)png_ptr->unknown_chunk.name, | 1622 png_memcpy((png_charp)png_ptr->unknown_chunk.name, |
| 1612 (png_charp)png_ptr->chunk_name, | 1623 (png_charp)png_ptr->chunk_name, |
| 1613 png_sizeof(png_ptr->unknown_chunk.name)); | 1624 png_sizeof(png_ptr->unknown_chunk.name)); |
| 1614 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1] | 1625 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1] |
| 1615 = '\0'; | 1626 = '\0'; |
| 1616 | 1627 |
| 1617 png_ptr->unknown_chunk.size = (png_size_t)length; | 1628 png_ptr->unknown_chunk.size = (png_size_t)length; |
| 1618 | 1629 |
| 1619 if (length == 0) | 1630 if (length == 0) |
| 1620 png_ptr->unknown_chunk.data = NULL; | 1631 png_ptr->unknown_chunk.data = NULL; |
| 1621 | 1632 |
| 1622 else | 1633 else |
| 1623 { | 1634 { |
| 1624 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, | 1635 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, |
| 1625 (png_uint_32)length); | 1636 (png_uint_32)length); |
| 1626 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); | 1637 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); |
| 1627 } | 1638 } |
| 1628 | 1639 |
| 1629 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) | 1640 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED |
| 1630 if (png_ptr->read_user_chunk_fn != NULL) | 1641 if (png_ptr->read_user_chunk_fn != NULL) |
| 1631 { | 1642 { |
| 1632 /* Callback to user unknown chunk handler */ | 1643 /* Callback to user unknown chunk handler */ |
| 1633 int ret; | 1644 int ret; |
| 1634 ret = (*(png_ptr->read_user_chunk_fn)) | 1645 ret = (*(png_ptr->read_user_chunk_fn)) |
| 1635 (png_ptr, &png_ptr->unknown_chunk); | 1646 (png_ptr, &png_ptr->unknown_chunk); |
| 1636 | 1647 |
| 1637 if (ret < 0) | 1648 if (ret < 0) |
| 1638 png_chunk_error(png_ptr, "error in user chunk"); | 1649 png_chunk_error(png_ptr, "error in user chunk"); |
| 1639 | 1650 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 } | 1695 } |
| 1685 | 1696 |
| 1686 void PNGAPI | 1697 void PNGAPI |
| 1687 png_progressive_combine_row (png_structp png_ptr, | 1698 png_progressive_combine_row (png_structp png_ptr, |
| 1688 png_bytep old_row, png_bytep new_row) | 1699 png_bytep old_row, png_bytep new_row) |
| 1689 { | 1700 { |
| 1690 #ifdef PNG_USE_LOCAL_ARRAYS | 1701 #ifdef PNG_USE_LOCAL_ARRAYS |
| 1691 PNG_CONST int FARDATA png_pass_dsp_mask[7] = | 1702 PNG_CONST int FARDATA png_pass_dsp_mask[7] = |
| 1692 {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; | 1703 {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; |
| 1693 #endif | 1704 #endif |
| 1705 |
| 1694 if (png_ptr == NULL) | 1706 if (png_ptr == NULL) |
| 1695 return; | 1707 return; |
| 1696 | 1708 |
| 1697 if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ | 1709 if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ |
| 1698 png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); | 1710 png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); |
| 1699 } | 1711 } |
| 1700 | 1712 |
| 1701 void PNGAPI | 1713 void PNGAPI |
| 1702 png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, | 1714 png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, |
| 1703 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, | 1715 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1715 | 1727 |
| 1716 png_voidp PNGAPI | 1728 png_voidp PNGAPI |
| 1717 png_get_progressive_ptr(png_structp png_ptr) | 1729 png_get_progressive_ptr(png_structp png_ptr) |
| 1718 { | 1730 { |
| 1719 if (png_ptr == NULL) | 1731 if (png_ptr == NULL) |
| 1720 return (NULL); | 1732 return (NULL); |
| 1721 | 1733 |
| 1722 return png_ptr->io_ptr; | 1734 return png_ptr->io_ptr; |
| 1723 } | 1735 } |
| 1724 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ | 1736 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
| OLD | NEW |