Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1 | |
| 2 | /* pngpread.c - read a png file in push mode |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | a31c74f | 2009-05-18 15:52:01 -0500 | [diff] [blame] | 4 | * Last changed in libpng 1.4.0 [May 18, 2009] |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * For conditions of distribution and use, see copyright notice in png.h |
Glenn Randers-Pehrson | 79134c6 | 2009-02-14 10:32:18 -0600 | [diff] [blame] | 6 | * Copyright (c) 1998-2009 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | d436672 | 2000-06-04 14:29:29 -0500 | [diff] [blame] | 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 10 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 11 | #include "png.h" |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 12 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 13 | #include "pngpriv.h" |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 14 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 15 | /* push model modes */ |
| 16 | #define PNG_READ_SIG_MODE 0 |
| 17 | #define PNG_READ_CHUNK_MODE 1 |
| 18 | #define PNG_READ_IDAT_MODE 2 |
| 19 | #define PNG_SKIP_MODE 3 |
| 20 | #define PNG_READ_tEXt_MODE 4 |
| 21 | #define PNG_READ_zTXt_MODE 5 |
| 22 | #define PNG_READ_DONE_MODE 6 |
| 23 | #define PNG_READ_iTXt_MODE 7 |
| 24 | #define PNG_ERROR_MODE 8 |
| 25 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 26 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 27 | png_process_data(png_structp png_ptr, png_infop info_ptr, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 28 | png_bytep buffer, png_size_t buffer_size) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 29 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 30 | if (png_ptr == NULL || info_ptr == NULL) |
| 31 | return; |
| 32 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 33 | png_push_restore_buffer(png_ptr, buffer, buffer_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 34 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 35 | while (png_ptr->buffer_size) |
| 36 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 37 | png_process_some_data(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 38 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 39 | } |
| 40 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 41 | /* What we do with the incoming data depends on what we were previously |
| 42 | * doing before we ran out of data... |
| 43 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 44 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 45 | png_process_some_data(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 46 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 47 | if (png_ptr == NULL) |
| 48 | return; |
| 49 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 50 | switch (png_ptr->process_mode) |
| 51 | { |
| 52 | case PNG_READ_SIG_MODE: |
| 53 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 54 | png_push_read_sig(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 55 | break; |
| 56 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 57 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 58 | case PNG_READ_CHUNK_MODE: |
| 59 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 60 | png_push_read_chunk(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 61 | break; |
| 62 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 63 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 64 | case PNG_READ_IDAT_MODE: |
| 65 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 66 | png_push_read_IDAT(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 67 | break; |
| 68 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 69 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 70 | #if defined(PNG_READ_tEXt_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 71 | case PNG_READ_tEXt_MODE: |
| 72 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 73 | png_push_read_tEXt(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 74 | break; |
| 75 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 76 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 77 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 78 | #if defined(PNG_READ_zTXt_SUPPORTED) |
| 79 | case PNG_READ_zTXt_MODE: |
| 80 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 81 | png_push_read_zTXt(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 82 | break; |
| 83 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 84 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 85 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 86 | #if defined(PNG_READ_iTXt_SUPPORTED) |
| 87 | case PNG_READ_iTXt_MODE: |
| 88 | { |
| 89 | png_push_read_iTXt(png_ptr, info_ptr); |
| 90 | break; |
| 91 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 92 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 93 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 94 | case PNG_SKIP_MODE: |
| 95 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 96 | png_push_crc_finish(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 97 | break; |
| 98 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 99 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 100 | default: |
| 101 | { |
| 102 | png_ptr->buffer_size = 0; |
| 103 | break; |
| 104 | } |
| 105 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 106 | } |
| 107 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 108 | /* Read any remaining signature bytes from the stream and compare them with |
| 109 | * the correct PNG signature. It is possible that this routine is called |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 110 | * with bytes already read from the signature, either because they have been |
| 111 | * checked by the calling application, or because of multiple calls to this |
| 112 | * routine. |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 113 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 114 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 115 | png_push_read_sig(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 116 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 117 | png_size_t num_checked = png_ptr->sig_bytes, |
| 118 | num_to_check = 8 - num_checked; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 119 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 120 | if (png_ptr->buffer_size < num_to_check) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 121 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 122 | num_to_check = png_ptr->buffer_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 123 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 124 | |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 125 | png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 126 | num_to_check); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 127 | png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 128 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 129 | if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 130 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 131 | if (num_checked < 4 && |
| 132 | png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) |
| 133 | png_error(png_ptr, "Not a PNG file"); |
| 134 | else |
| 135 | png_error(png_ptr, "PNG file corrupted by ASCII conversion"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 136 | } |
| 137 | else |
| 138 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 139 | if (png_ptr->sig_bytes >= 8) |
| 140 | { |
| 141 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
| 142 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 143 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 144 | } |
| 145 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 146 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 147 | png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 148 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 149 | #ifdef PNG_USE_LOCAL_ARRAYS |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 150 | PNG_CONST PNG_IHDR; |
| 151 | PNG_CONST PNG_IDAT; |
| 152 | PNG_CONST PNG_IEND; |
| 153 | PNG_CONST PNG_PLTE; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 154 | #if defined(PNG_READ_bKGD_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 155 | PNG_CONST PNG_bKGD; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 156 | #endif |
| 157 | #if defined(PNG_READ_cHRM_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 158 | PNG_CONST PNG_cHRM; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 159 | #endif |
| 160 | #if defined(PNG_READ_gAMA_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 161 | PNG_CONST PNG_gAMA; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 162 | #endif |
| 163 | #if defined(PNG_READ_hIST_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 164 | PNG_CONST PNG_hIST; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 165 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 166 | #if defined(PNG_READ_iCCP_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 167 | PNG_CONST PNG_iCCP; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 168 | #endif |
| 169 | #if defined(PNG_READ_iTXt_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 170 | PNG_CONST PNG_iTXt; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 171 | #endif |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 172 | #if defined(PNG_READ_oFFs_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 173 | PNG_CONST PNG_oFFs; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 174 | #endif |
| 175 | #if defined(PNG_READ_pCAL_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 176 | PNG_CONST PNG_pCAL; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 177 | #endif |
| 178 | #if defined(PNG_READ_pHYs_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 179 | PNG_CONST PNG_pHYs; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 180 | #endif |
| 181 | #if defined(PNG_READ_sBIT_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 182 | PNG_CONST PNG_sBIT; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 183 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 184 | #if defined(PNG_READ_sCAL_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 185 | PNG_CONST PNG_sCAL; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 186 | #endif |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 187 | #if defined(PNG_READ_sRGB_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 188 | PNG_CONST PNG_sRGB; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 189 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 190 | #if defined(PNG_READ_sPLT_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 191 | PNG_CONST PNG_sPLT; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 192 | #endif |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 193 | #if defined(PNG_READ_tEXt_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 194 | PNG_CONST PNG_tEXt; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 195 | #endif |
| 196 | #if defined(PNG_READ_tIME_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 197 | PNG_CONST PNG_tIME; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 198 | #endif |
| 199 | #if defined(PNG_READ_tRNS_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 200 | PNG_CONST PNG_tRNS; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 201 | #endif |
| 202 | #if defined(PNG_READ_zTXt_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 203 | PNG_CONST PNG_zTXt; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 204 | #endif |
| 205 | #endif /* PNG_USE_LOCAL_ARRAYS */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 206 | /* First we make sure we have enough data for the 4 byte chunk name |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 207 | * and the 4 byte chunk length before proceeding with decoding the |
| 208 | * 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 |
| 210 | * end of every chunk (except IDAT, which is handled separately). |
| 211 | */ |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 212 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 213 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 214 | png_byte chunk_length[4]; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 215 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 216 | if (png_ptr->buffer_size < 8) |
| 217 | { |
| 218 | png_push_save_buffer(png_ptr); |
| 219 | return; |
| 220 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 221 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 222 | png_push_fill_buffer(png_ptr, chunk_length, 4); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 223 | png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 224 | png_reset_crc(png_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 225 | png_crc_read(png_ptr, png_ptr->chunk_name, 4); |
Glenn Randers-Pehrson | eb58091 | 2008-07-30 14:47:09 -0500 | [diff] [blame] | 226 | png_check_chunk_name(png_ptr, png_ptr->chunk_name); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 227 | png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 228 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 229 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 230 | if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 231 | if (png_ptr->mode & PNG_AFTER_IDAT) |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 232 | png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
| 233 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 234 | if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 235 | { |
Glenn Randers-Pehrson | eb58091 | 2008-07-30 14:47:09 -0500 | [diff] [blame] | 236 | if (png_ptr->push_length != 13) |
| 237 | png_error(png_ptr, "Invalid IHDR length"); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 238 | |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 239 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 240 | { |
| 241 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 242 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 243 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 244 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 245 | png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 246 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 247 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 248 | else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) |
| 249 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 250 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 251 | { |
| 252 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 253 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 254 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 255 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 256 | png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); |
| 257 | |
| 258 | png_ptr->process_mode = PNG_READ_DONE_MODE; |
| 259 | png_push_have_end(png_ptr, info_ptr); |
| 260 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 261 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 262 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 263 | else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) |
| 264 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 265 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 266 | { |
| 267 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 268 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 269 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 270 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 271 | if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
| 272 | png_ptr->mode |= PNG_HAVE_IDAT; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 273 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 274 | png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 275 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 276 | if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) |
| 277 | png_ptr->mode |= PNG_HAVE_PLTE; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 278 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 279 | else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
| 280 | { |
| 281 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 282 | png_error(png_ptr, "Missing IHDR before IDAT"); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 283 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 284 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
| 285 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
| 286 | png_error(png_ptr, "Missing PLTE before IDAT"); |
| 287 | } |
| 288 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 289 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 290 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 291 | else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 292 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 293 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 294 | { |
| 295 | png_push_save_buffer(png_ptr); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 296 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 297 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 298 | png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 299 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 300 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 301 | else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 302 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 303 | /* If we reach an IDAT chunk, this means we have read all of the |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 304 | * header chunks, and we can start reading the image (or if this |
| 305 | * is called after the image has been read - we have an error). |
| 306 | */ |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 307 | |
| 308 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 309 | png_error(png_ptr, "Missing IHDR before IDAT"); |
| 310 | |
| 311 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
| 312 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
| 313 | png_error(png_ptr, "Missing PLTE before IDAT"); |
Glenn Randers-Pehrson | 73d57cb | 2002-03-25 18:49:08 -0600 | [diff] [blame] | 314 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 315 | if (png_ptr->mode & PNG_HAVE_IDAT) |
| 316 | { |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 317 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 318 | if (png_ptr->push_length == 0) |
| 319 | return; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 320 | |
| 321 | if (png_ptr->mode & PNG_AFTER_IDAT) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 322 | png_benign_error(png_ptr, "Too many IDATs found"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 323 | } |
| 324 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 325 | png_ptr->idat_size = png_ptr->push_length; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 326 | png_ptr->mode |= PNG_HAVE_IDAT; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 327 | png_ptr->process_mode = PNG_READ_IDAT_MODE; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 328 | png_push_have_info(png_ptr, info_ptr); |
| 329 | png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; |
| 330 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 331 | return; |
| 332 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 333 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 334 | #if defined(PNG_READ_gAMA_SUPPORTED) |
| 335 | else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) |
| 336 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 337 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 338 | { |
| 339 | png_push_save_buffer(png_ptr); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 340 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 341 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 342 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 343 | png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 344 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 345 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 346 | #endif |
| 347 | #if defined(PNG_READ_sBIT_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 348 | else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 349 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 350 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 351 | { |
| 352 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 353 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 354 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 355 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 356 | png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 357 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 358 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 359 | #endif |
| 360 | #if defined(PNG_READ_cHRM_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 361 | else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 362 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 363 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 364 | { |
| 365 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 366 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 367 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 368 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 369 | png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 370 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 371 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 372 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 373 | #if defined(PNG_READ_sRGB_SUPPORTED) |
| 374 | else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) |
| 375 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 376 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 377 | { |
| 378 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 379 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 380 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 381 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 382 | png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); |
| 383 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 384 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 385 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 386 | #if defined(PNG_READ_iCCP_SUPPORTED) |
| 387 | else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) |
| 388 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 389 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 390 | { |
| 391 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 392 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 393 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 394 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 395 | png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); |
| 396 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 397 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 398 | #endif |
| 399 | #if defined(PNG_READ_sPLT_SUPPORTED) |
| 400 | else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) |
| 401 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 402 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 403 | { |
| 404 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 405 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 406 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 407 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 408 | png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); |
| 409 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 410 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 411 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 412 | #if defined(PNG_READ_tRNS_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 413 | else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 414 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 415 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 416 | { |
| 417 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 418 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 419 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 420 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 421 | png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 422 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 423 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 424 | #endif |
| 425 | #if defined(PNG_READ_bKGD_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 426 | else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 427 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 428 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 429 | { |
| 430 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 431 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 432 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 433 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 434 | png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 435 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 436 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 437 | #endif |
| 438 | #if defined(PNG_READ_hIST_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 439 | else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 440 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 441 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 442 | { |
| 443 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 444 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 445 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 446 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 447 | png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 448 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 449 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 450 | #endif |
| 451 | #if defined(PNG_READ_pHYs_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 452 | else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 453 | { |
| 454 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 455 | { |
| 456 | png_push_save_buffer(png_ptr); |
| 457 | return; |
| 458 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 459 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 460 | png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 461 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 462 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 463 | #endif |
| 464 | #if defined(PNG_READ_oFFs_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 465 | else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 466 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 467 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 468 | { |
| 469 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 470 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 471 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 472 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 473 | png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 474 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 475 | #endif |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 476 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 477 | #if defined(PNG_READ_pCAL_SUPPORTED) |
| 478 | else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) |
| 479 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 480 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 481 | { |
| 482 | png_push_save_buffer(png_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 483 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 484 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 485 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 486 | png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 487 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 488 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 489 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 490 | #if defined(PNG_READ_sCAL_SUPPORTED) |
| 491 | else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) |
| 492 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 493 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 494 | { |
| 495 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 496 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 497 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 498 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 499 | png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 500 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 501 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 502 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 503 | #if defined(PNG_READ_tIME_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 504 | else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 505 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 506 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 507 | { |
| 508 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 509 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 510 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 511 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 512 | png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 513 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 514 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 515 | #endif |
| 516 | #if defined(PNG_READ_tEXt_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 517 | else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 518 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 519 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 520 | { |
| 521 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 522 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 523 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 524 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 525 | png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 526 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 527 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 528 | #endif |
| 529 | #if defined(PNG_READ_zTXt_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 530 | else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 531 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 532 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 533 | { |
| 534 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 535 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 536 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 537 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 538 | png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 539 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 540 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 541 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 542 | #if defined(PNG_READ_iTXt_SUPPORTED) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 543 | else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 544 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 545 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 546 | { |
| 547 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 548 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 549 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 550 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 551 | png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); |
| 552 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 553 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 554 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 555 | else |
| 556 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 557 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 558 | { |
| 559 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 560 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 561 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 562 | png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 563 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 564 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 565 | png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 566 | } |
| 567 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 568 | void /* PRIVATE */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 569 | png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 570 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 571 | png_ptr->process_mode = PNG_SKIP_MODE; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 572 | png_ptr->skip_length = skip; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 573 | } |
| 574 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 575 | void /* PRIVATE */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 576 | png_push_crc_finish(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 577 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 578 | if (png_ptr->skip_length && png_ptr->save_buffer_size) |
| 579 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 580 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 581 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 582 | if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size) |
| 583 | save_size = (png_size_t)png_ptr->skip_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 584 | else |
| 585 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 586 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 587 | png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 588 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 589 | png_ptr->skip_length -= save_size; |
| 590 | png_ptr->buffer_size -= save_size; |
| 591 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 592 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 593 | } |
| 594 | if (png_ptr->skip_length && png_ptr->current_buffer_size) |
| 595 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 596 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 597 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 598 | if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size) |
| 599 | save_size = (png_size_t)png_ptr->skip_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 600 | else |
| 601 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 602 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 603 | png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 604 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 605 | png_ptr->skip_length -= save_size; |
| 606 | png_ptr->buffer_size -= save_size; |
| 607 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 608 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 609 | } |
| 610 | if (!png_ptr->skip_length) |
| 611 | { |
| 612 | if (png_ptr->buffer_size < 4) |
| 613 | { |
| 614 | png_push_save_buffer(png_ptr); |
| 615 | return; |
| 616 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 617 | |
| 618 | png_crc_finish(png_ptr, 0); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 619 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 620 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 621 | } |
| 622 | |
Glenn Randers-Pehrson | 25d8224 | 2002-05-01 11:51:26 -0500 | [diff] [blame] | 623 | void PNGAPI |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 624 | png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 625 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 626 | png_bytep ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 627 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 628 | if (png_ptr == NULL) |
| 629 | return; |
| 630 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 631 | ptr = buffer; |
| 632 | if (png_ptr->save_buffer_size) |
| 633 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 634 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 635 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 636 | if (length < png_ptr->save_buffer_size) |
| 637 | save_size = length; |
| 638 | else |
| 639 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 640 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 641 | png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 642 | length -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 643 | ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 644 | png_ptr->buffer_size -= save_size; |
| 645 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 646 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 647 | } |
| 648 | if (length && png_ptr->current_buffer_size) |
| 649 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 650 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 651 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 652 | if (length < png_ptr->current_buffer_size) |
| 653 | save_size = length; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 654 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 655 | else |
| 656 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 657 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 658 | png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 659 | png_ptr->buffer_size -= save_size; |
| 660 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 661 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 662 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 663 | } |
| 664 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 665 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 666 | png_push_save_buffer(png_structp png_ptr) |
| 667 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 668 | if (png_ptr->save_buffer_size) |
| 669 | { |
| 670 | if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) |
| 671 | { |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 672 | png_size_t i, istop; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 673 | png_bytep sp; |
| 674 | png_bytep dp; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 675 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 676 | istop = png_ptr->save_buffer_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 677 | for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 678 | i < istop; i++, sp++, dp++) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 679 | { |
| 680 | *dp = *sp; |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > |
| 685 | png_ptr->save_buffer_max) |
| 686 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 687 | png_size_t new_max; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 688 | png_bytep old_buffer; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 689 | |
Glenn Randers-Pehrson | e647462 | 2006-03-04 16:50:47 -0600 | [diff] [blame] | 690 | if (png_ptr->save_buffer_size > PNG_SIZE_MAX - |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame] | 691 | (png_ptr->current_buffer_size + 256)) |
| 692 | { |
| 693 | png_error(png_ptr, "Potential overflow of save_buffer"); |
| 694 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 695 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 696 | new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 697 | old_buffer = png_ptr->save_buffer; |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 698 | png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, |
| 699 | (png_size_t)new_max); |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 700 | png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); |
| 701 | png_free(png_ptr, old_buffer); |
| 702 | png_ptr->save_buffer_max = new_max; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 703 | } |
| 704 | if (png_ptr->current_buffer_size) |
| 705 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 706 | png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, |
| 707 | png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 708 | png_ptr->save_buffer_size += png_ptr->current_buffer_size; |
| 709 | png_ptr->current_buffer_size = 0; |
| 710 | } |
| 711 | png_ptr->save_buffer_ptr = png_ptr->save_buffer; |
| 712 | png_ptr->buffer_size = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 713 | } |
| 714 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 715 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 716 | png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 717 | png_size_t buffer_length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 718 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 719 | png_ptr->current_buffer = buffer; |
| 720 | png_ptr->current_buffer_size = buffer_length; |
| 721 | png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; |
| 722 | png_ptr->current_buffer_ptr = png_ptr->current_buffer; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 723 | } |
| 724 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 725 | void /* PRIVATE */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 726 | png_push_read_IDAT(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 727 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 728 | #ifdef PNG_USE_LOCAL_ARRAYS |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 729 | PNG_CONST PNG_IDAT; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 730 | #endif |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 731 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 732 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 733 | png_byte chunk_length[4]; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 734 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 735 | if (png_ptr->buffer_size < 8) |
| 736 | { |
| 737 | png_push_save_buffer(png_ptr); |
| 738 | return; |
| 739 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 740 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 741 | png_push_fill_buffer(png_ptr, chunk_length, 4); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 742 | png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 743 | png_reset_crc(png_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 744 | png_crc_read(png_ptr, png_ptr->chunk_name, 4); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 745 | png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 746 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 747 | if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 748 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 749 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 750 | if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 751 | png_error(png_ptr, "Not enough compressed data"); |
| 752 | return; |
| 753 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 754 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 755 | png_ptr->idat_size = png_ptr->push_length; |
| 756 | } |
| 757 | if (png_ptr->idat_size && png_ptr->save_buffer_size) |
| 758 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 759 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 760 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 761 | if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 762 | { |
| 763 | save_size = (png_size_t)png_ptr->idat_size; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 764 | |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 765 | /* check for overflow */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 766 | if ((png_uint_32)save_size != png_ptr->idat_size) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 767 | png_error(png_ptr, "save_size overflowed in pngpread"); |
| 768 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 769 | else |
| 770 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 771 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 772 | png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 773 | |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 774 | if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) |
| 775 | png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 776 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 777 | png_ptr->idat_size -= save_size; |
| 778 | png_ptr->buffer_size -= save_size; |
| 779 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 780 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 781 | } |
| 782 | if (png_ptr->idat_size && png_ptr->current_buffer_size) |
| 783 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 784 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 785 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 786 | if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 787 | { |
| 788 | save_size = (png_size_t)png_ptr->idat_size; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 789 | |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 790 | /* check for overflow */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 791 | if ((png_uint_32)save_size != png_ptr->idat_size) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 792 | png_error(png_ptr, "save_size overflowed in pngpread"); |
| 793 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 794 | else |
| 795 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 796 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 797 | png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 798 | if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) |
| 799 | png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 800 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 801 | png_ptr->idat_size -= save_size; |
| 802 | png_ptr->buffer_size -= save_size; |
| 803 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 804 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 805 | } |
| 806 | if (!png_ptr->idat_size) |
| 807 | { |
| 808 | if (png_ptr->buffer_size < 4) |
| 809 | { |
| 810 | png_push_save_buffer(png_ptr); |
| 811 | return; |
| 812 | } |
| 813 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 814 | png_crc_finish(png_ptr, 0); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 815 | png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 816 | png_ptr->mode |= PNG_AFTER_IDAT; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 817 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 818 | } |
| 819 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 820 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 821 | png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 822 | png_size_t buffer_length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 823 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 824 | int ret; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 825 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 826 | if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length) |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 827 | png_benign_error(png_ptr, "Extra compression data"); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 828 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 829 | png_ptr->zstream.next_in = buffer; |
| 830 | png_ptr->zstream.avail_in = (uInt)buffer_length; |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 831 | for (;;) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 832 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 833 | ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 834 | if (ret != Z_OK) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 835 | { |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 836 | if (ret == Z_STREAM_END) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 837 | { |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 838 | if (png_ptr->zstream.avail_in) |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 839 | png_benign_error(png_ptr, "Extra compressed data"); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 840 | |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 841 | if (!(png_ptr->zstream.avail_out)) |
| 842 | { |
| 843 | png_push_process_row(png_ptr); |
| 844 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 845 | |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 846 | png_ptr->mode |= PNG_AFTER_IDAT; |
| 847 | png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
| 848 | break; |
| 849 | } |
| 850 | else if (ret == Z_BUF_ERROR) |
| 851 | break; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 852 | |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 853 | else |
| 854 | png_error(png_ptr, "Decompression Error"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 855 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 856 | if (!(png_ptr->zstream.avail_out)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 857 | { |
Glenn Randers-Pehrson | d020e9d | 2002-06-28 09:34:00 -0500 | [diff] [blame] | 858 | if (( |
| 859 | #if defined(PNG_READ_INTERLACING_SUPPORTED) |
| 860 | png_ptr->interlaced && png_ptr->pass > 6) || |
| 861 | (!png_ptr->interlaced && |
| 862 | #endif |
Glenn Randers-Pehrson | dff799e | 2004-08-07 21:42:49 -0500 | [diff] [blame] | 863 | png_ptr->row_number == png_ptr->num_rows)) |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 864 | { |
Glenn Randers-Pehrson | 8a7df00 | 2002-08-15 22:02:57 -0500 | [diff] [blame] | 865 | if (png_ptr->zstream.avail_in) |
| 866 | png_warning(png_ptr, "Too much data in IDAT chunks"); |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 867 | png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
| 868 | break; |
| 869 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 870 | png_push_process_row(png_ptr); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 871 | png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; |
| 872 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 873 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 874 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 875 | else |
| 876 | break; |
| 877 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 878 | } |
| 879 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 880 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 881 | png_push_process_row(png_structp png_ptr) |
| 882 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 883 | png_ptr->row_info.color_type = png_ptr->color_type; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 884 | png_ptr->row_info.width = png_ptr->iwidth; |
| 885 | png_ptr->row_info.channels = png_ptr->channels; |
| 886 | png_ptr->row_info.bit_depth = png_ptr->bit_depth; |
| 887 | png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 888 | |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 889 | png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, |
| 890 | png_ptr->row_info.width); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 891 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 892 | png_read_filter_row(png_ptr, &(png_ptr->row_info), |
| 893 | png_ptr->row_buf + 1, png_ptr->prev_row + 1, |
| 894 | (int)(png_ptr->row_buf[0])); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 895 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 896 | png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 897 | |
Glenn Randers-Pehrson | 73b029f | 2004-11-26 17:28:09 -0600 | [diff] [blame] | 898 | if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 899 | png_do_read_transformations(png_ptr); |
| 900 | |
| 901 | #if defined(PNG_READ_INTERLACING_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 902 | /* blow up interlaced rows to full size */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 903 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 904 | { |
| 905 | if (png_ptr->pass < 6) |
Glenn Randers-Pehrson | 231e687 | 2001-01-12 15:13:06 -0600 | [diff] [blame] | 906 | /* old interface (pre-1.0.9): |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 907 | png_do_read_interlace(&(png_ptr->row_info), |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 908 | png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); |
Glenn Randers-Pehrson | 231e687 | 2001-01-12 15:13:06 -0600 | [diff] [blame] | 909 | */ |
| 910 | png_do_read_interlace(png_ptr); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 911 | |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 912 | switch (png_ptr->pass) |
| 913 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 914 | case 0: |
| 915 | { |
| 916 | int i; |
| 917 | for (i = 0; i < 8 && png_ptr->pass == 0; i++) |
| 918 | { |
| 919 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 920 | png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 921 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 922 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 923 | if (png_ptr->pass == 2) /* pass 1 might be empty */ |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 924 | { |
| 925 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 926 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 927 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 928 | png_read_push_finish_row(png_ptr); |
| 929 | } |
| 930 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 931 | |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 932 | if (png_ptr->pass == 4 && png_ptr->height <= 4) |
| 933 | { |
| 934 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 935 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 936 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 937 | png_read_push_finish_row(png_ptr); |
| 938 | } |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 939 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 940 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 941 | if (png_ptr->pass == 6 && png_ptr->height <= 4) |
| 942 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 943 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 944 | png_read_push_finish_row(png_ptr); |
| 945 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 946 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 947 | break; |
| 948 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 949 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 950 | case 1: |
| 951 | { |
| 952 | int i; |
| 953 | for (i = 0; i < 8 && png_ptr->pass == 1; i++) |
| 954 | { |
| 955 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 956 | png_read_push_finish_row(png_ptr); |
| 957 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 958 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 959 | if (png_ptr->pass == 2) /* skip top 4 generated rows */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 960 | { |
| 961 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 962 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 963 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 964 | png_read_push_finish_row(png_ptr); |
| 965 | } |
| 966 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 967 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 968 | break; |
| 969 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 970 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 971 | case 2: |
| 972 | { |
| 973 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 974 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 975 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 976 | { |
| 977 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 978 | png_read_push_finish_row(png_ptr); |
| 979 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 980 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 981 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 982 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 983 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 984 | png_read_push_finish_row(png_ptr); |
| 985 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 986 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 987 | if (png_ptr->pass == 4) /* pass 3 might be empty */ |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 988 | { |
| 989 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 990 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 991 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 992 | png_read_push_finish_row(png_ptr); |
| 993 | } |
| 994 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 995 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 996 | break; |
| 997 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 998 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 999 | case 3: |
| 1000 | { |
| 1001 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1002 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1003 | for (i = 0; i < 4 && png_ptr->pass == 3; i++) |
| 1004 | { |
| 1005 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1006 | png_read_push_finish_row(png_ptr); |
| 1007 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1008 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 1009 | if (png_ptr->pass == 4) /* skip top two generated rows */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1010 | { |
| 1011 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1012 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1013 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1014 | png_read_push_finish_row(png_ptr); |
| 1015 | } |
| 1016 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1017 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1018 | break; |
| 1019 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1020 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1021 | case 4: |
| 1022 | { |
| 1023 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1024 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1025 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1026 | { |
| 1027 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1028 | png_read_push_finish_row(png_ptr); |
| 1029 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1030 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1031 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1032 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1033 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1034 | png_read_push_finish_row(png_ptr); |
| 1035 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1036 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 1037 | if (png_ptr->pass == 6) /* pass 5 might be empty */ |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1038 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1039 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1040 | png_read_push_finish_row(png_ptr); |
| 1041 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1042 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1043 | break; |
| 1044 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1045 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1046 | case 5: |
| 1047 | { |
| 1048 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1049 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1050 | for (i = 0; i < 2 && png_ptr->pass == 5; i++) |
| 1051 | { |
| 1052 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1053 | png_read_push_finish_row(png_ptr); |
| 1054 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1055 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 1056 | if (png_ptr->pass == 6) /* skip top generated row */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1057 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1058 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1059 | png_read_push_finish_row(png_ptr); |
| 1060 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1061 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1062 | break; |
| 1063 | } |
| 1064 | case 6: |
| 1065 | { |
| 1066 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1067 | png_read_push_finish_row(png_ptr); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1068 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1069 | if (png_ptr->pass != 6) |
| 1070 | break; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1071 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1072 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1073 | png_read_push_finish_row(png_ptr); |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | else |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1078 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1079 | { |
| 1080 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1081 | png_read_push_finish_row(png_ptr); |
| 1082 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1083 | } |
| 1084 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1085 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1086 | png_read_push_finish_row(png_structp png_ptr) |
| 1087 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 1088 | #ifdef PNG_USE_LOCAL_ARRAYS |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1089 | /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1090 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1091 | /* Start of interlace block */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1092 | PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1093 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1094 | /* Offset to next interlace block */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1095 | PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1096 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1097 | /* Start of interlace block in the y direction */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1098 | PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1099 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1100 | /* Offset to next interlace block in the y direction */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1101 | PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1102 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1103 | /* Height of interlace block. This is not currently used - if you need |
| 1104 | * it, uncomment it here and in png.h |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1105 | PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1106 | */ |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 1107 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1108 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1109 | png_ptr->row_number++; |
| 1110 | if (png_ptr->row_number < png_ptr->num_rows) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1111 | return; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1112 | |
Glenn Randers-Pehrson | a31c74f | 2009-05-18 15:52:01 -0500 | [diff] [blame] | 1113 | #if defined(PNG_READ_INTERLACING_SUPPORTED) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1114 | if (png_ptr->interlaced) |
| 1115 | { |
| 1116 | png_ptr->row_number = 0; |
Glenn Randers-Pehrson | a31c74f | 2009-05-18 15:52:01 -0500 | [diff] [blame] | 1117 | png_memset(png_ptr->prev_row, 0, |
| 1118 | png_ptr->rowbytes + 1); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1119 | do |
| 1120 | { |
| 1121 | png_ptr->pass++; |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1122 | if ((png_ptr->pass == 1 && png_ptr->width < 5) || |
| 1123 | (png_ptr->pass == 3 && png_ptr->width < 3) || |
| 1124 | (png_ptr->pass == 5 && png_ptr->width < 2)) |
| 1125 | png_ptr->pass++; |
| 1126 | |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 1127 | if (png_ptr->pass > 7) |
| 1128 | png_ptr->pass--; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1129 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1130 | if (png_ptr->pass >= 7) |
| 1131 | break; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1132 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1133 | png_ptr->iwidth = (png_ptr->width + |
| 1134 | png_pass_inc[png_ptr->pass] - 1 - |
| 1135 | png_pass_start[png_ptr->pass]) / |
| 1136 | png_pass_inc[png_ptr->pass]; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1137 | |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1138 | png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, |
Glenn Randers-Pehrson | dff799e | 2004-08-07 21:42:49 -0500 | [diff] [blame] | 1139 | png_ptr->iwidth) + 1; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1140 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1141 | if (png_ptr->transformations & PNG_INTERLACE) |
| 1142 | break; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1143 | |
| 1144 | png_ptr->num_rows = (png_ptr->height + |
| 1145 | png_pass_yinc[png_ptr->pass] - 1 - |
| 1146 | png_pass_ystart[png_ptr->pass]) / |
| 1147 | png_pass_yinc[png_ptr->pass]; |
| 1148 | |
| 1149 | } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1150 | } |
Glenn Randers-Pehrson | a31c74f | 2009-05-18 15:52:01 -0500 | [diff] [blame] | 1151 | #endif /* PNG_READ_INTERLACING_SUPPORTED */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1152 | } |
| 1153 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1154 | #if defined(PNG_READ_tEXt_SUPPORTED) |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1155 | void /* PRIVATE */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1156 | png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1157 | length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1158 | { |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1159 | if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 1160 | { |
| 1161 | png_error(png_ptr, "Out of place tEXt"); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1162 | info_ptr = info_ptr; /* to quiet some compiler warnings */ |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 1163 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1164 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1165 | #ifdef PNG_MAX_MALLOC_64K |
| 1166 | png_ptr->skip_length = 0; /* This may not be necessary */ |
| 1167 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1168 | if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1169 | { |
| 1170 | png_warning(png_ptr, "tEXt chunk too large to fit in memory"); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1171 | png_ptr->skip_length = length - (png_uint_32)65535L; |
| 1172 | length = (png_uint_32)65535L; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1173 | } |
| 1174 | #endif |
| 1175 | |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1176 | png_ptr->current_text = (png_charp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1177 | (png_size_t)(length + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1178 | png_ptr->current_text[length] = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1179 | png_ptr->current_text_ptr = png_ptr->current_text; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1180 | png_ptr->current_text_size = (png_size_t)length; |
| 1181 | png_ptr->current_text_left = (png_size_t)length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1182 | png_ptr->process_mode = PNG_READ_tEXt_MODE; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1183 | } |
| 1184 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1185 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1186 | png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1187 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1188 | if (png_ptr->buffer_size && png_ptr->current_text_left) |
| 1189 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1190 | png_size_t text_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1191 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1192 | if (png_ptr->buffer_size < png_ptr->current_text_left) |
| 1193 | text_size = png_ptr->buffer_size; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1194 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1195 | else |
| 1196 | text_size = png_ptr->current_text_left; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1197 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1198 | png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1199 | png_ptr->current_text_left -= text_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1200 | png_ptr->current_text_ptr += text_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1201 | } |
| 1202 | if (!(png_ptr->current_text_left)) |
| 1203 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1204 | png_textp text_ptr; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1205 | png_charp text; |
| 1206 | png_charp key; |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1207 | int ret; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1208 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1209 | if (png_ptr->buffer_size < 4) |
| 1210 | { |
| 1211 | png_push_save_buffer(png_ptr); |
| 1212 | return; |
| 1213 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1214 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1215 | png_push_crc_finish(png_ptr); |
| 1216 | |
| 1217 | #if defined(PNG_MAX_MALLOC_64K) |
| 1218 | if (png_ptr->skip_length) |
| 1219 | return; |
| 1220 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1221 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1222 | key = png_ptr->current_text; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1223 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1224 | for (text = key; *text; text++) |
| 1225 | /* empty loop */ ; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1226 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1227 | if (text < key + png_ptr->current_text_size) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1228 | text++; |
| 1229 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1230 | text_ptr = (png_textp)png_malloc(png_ptr, |
| 1231 | png_sizeof(png_text)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1232 | text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; |
| 1233 | text_ptr->key = key; |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1234 | #ifdef PNG_iTXt_SUPPORTED |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 1235 | text_ptr->lang = NULL; |
| 1236 | text_ptr->lang_key = NULL; |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1237 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1238 | text_ptr->text = text; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1239 | |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1240 | ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1241 | |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 1242 | png_free(png_ptr, key); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1243 | png_free(png_ptr, text_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1244 | png_ptr->current_text = NULL; |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1245 | |
| 1246 | if (ret) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1247 | png_warning(png_ptr, "Insufficient memory to store text chunk"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1248 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1249 | } |
| 1250 | #endif |
| 1251 | |
| 1252 | #if defined(PNG_READ_zTXt_SUPPORTED) |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1253 | void /* PRIVATE */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1254 | png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1255 | length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1256 | { |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1257 | if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 1258 | { |
| 1259 | png_error(png_ptr, "Out of place zTXt"); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1260 | info_ptr = info_ptr; /* to quiet some compiler warnings */ |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 1261 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1262 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1263 | #ifdef PNG_MAX_MALLOC_64K |
| 1264 | /* We can't handle zTXt chunks > 64K, since we don't have enough space |
| 1265 | * to be able to store the uncompressed data. Actually, the threshold |
| 1266 | * is probably around 32K, but it isn't as definite as 64K is. |
| 1267 | */ |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1268 | if (length > (png_uint_32)65535L) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1269 | { |
| 1270 | png_warning(png_ptr, "zTXt chunk too large to fit in memory"); |
| 1271 | png_push_crc_skip(png_ptr, length); |
| 1272 | return; |
| 1273 | } |
| 1274 | #endif |
| 1275 | |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1276 | png_ptr->current_text = (png_charp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1277 | (png_size_t)(length + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1278 | png_ptr->current_text[length] = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1279 | png_ptr->current_text_ptr = png_ptr->current_text; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1280 | png_ptr->current_text_size = (png_size_t)length; |
| 1281 | png_ptr->current_text_left = (png_size_t)length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1282 | png_ptr->process_mode = PNG_READ_zTXt_MODE; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1283 | } |
| 1284 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1285 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1286 | png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1287 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1288 | if (png_ptr->buffer_size && png_ptr->current_text_left) |
| 1289 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1290 | png_size_t text_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1291 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1292 | if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1293 | text_size = png_ptr->buffer_size; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1294 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1295 | else |
| 1296 | text_size = png_ptr->current_text_left; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1297 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1298 | png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1299 | png_ptr->current_text_left -= text_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1300 | png_ptr->current_text_ptr += text_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1301 | } |
| 1302 | if (!(png_ptr->current_text_left)) |
| 1303 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1304 | png_textp text_ptr; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1305 | png_charp text; |
| 1306 | png_charp key; |
| 1307 | int ret; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1308 | png_size_t text_size, key_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1309 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1310 | if (png_ptr->buffer_size < 4) |
| 1311 | { |
| 1312 | png_push_save_buffer(png_ptr); |
| 1313 | return; |
| 1314 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1315 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1316 | png_push_crc_finish(png_ptr); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1317 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1318 | key = png_ptr->current_text; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1319 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1320 | for (text = key; *text; text++) |
| 1321 | /* empty loop */ ; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1322 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1323 | /* zTXt can't have zero text */ |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1324 | if (text >= key + png_ptr->current_text_size) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1325 | { |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1326 | png_ptr->current_text = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1327 | png_free(png_ptr, key); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1328 | return; |
| 1329 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1330 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1331 | text++; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1332 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1333 | if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1334 | { |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1335 | png_ptr->current_text = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1336 | png_free(png_ptr, key); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1337 | return; |
| 1338 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1339 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1340 | text++; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1341 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1342 | png_ptr->zstream.next_in = (png_bytep )text; |
| 1343 | png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size - |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1344 | (text - key)); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1345 | png_ptr->zstream.next_out = png_ptr->zbuf; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1346 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1347 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1348 | key_size = text - key; |
| 1349 | text_size = 0; |
| 1350 | text = NULL; |
| 1351 | ret = Z_STREAM_END; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1352 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1353 | while (png_ptr->zstream.avail_in) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1354 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1355 | ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1356 | if (ret != Z_OK && ret != Z_STREAM_END) |
| 1357 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1358 | inflateReset(&png_ptr->zstream); |
| 1359 | png_ptr->zstream.avail_in = 0; |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1360 | png_ptr->current_text = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1361 | png_free(png_ptr, key); |
| 1362 | png_free(png_ptr, text); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1363 | return; |
| 1364 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1365 | if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1366 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1367 | if (text == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1368 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1369 | text = (png_charp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1370 | (png_ptr->zbuf_size |
| 1371 | - png_ptr->zstream.avail_out + key_size + 1)); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1372 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1373 | png_memcpy(text + key_size, png_ptr->zbuf, |
| 1374 | png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1375 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1376 | png_memcpy(text, key, key_size); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1377 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1378 | text_size = key_size + png_ptr->zbuf_size - |
| 1379 | png_ptr->zstream.avail_out; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1380 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1381 | *(text + text_size) = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1382 | } |
| 1383 | else |
| 1384 | { |
| 1385 | png_charp tmp; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1386 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1387 | tmp = text; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1388 | text = (png_charp)png_malloc(png_ptr, text_size + |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1389 | (png_ptr->zbuf_size |
Glenn Randers-Pehrson | a5fa5c9 | 2008-09-06 07:06:22 -0500 | [diff] [blame] | 1390 | - png_ptr->zstream.avail_out + 1)); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1391 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1392 | png_memcpy(text, tmp, text_size); |
| 1393 | png_free(png_ptr, tmp); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1394 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1395 | png_memcpy(text + text_size, png_ptr->zbuf, |
| 1396 | png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1397 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1398 | text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; |
| 1399 | *(text + text_size) = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1400 | } |
| 1401 | if (ret != Z_STREAM_END) |
| 1402 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1403 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 1404 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | else |
| 1408 | { |
| 1409 | break; |
| 1410 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1411 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1412 | if (ret == Z_STREAM_END) |
| 1413 | break; |
| 1414 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1415 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1416 | inflateReset(&png_ptr->zstream); |
| 1417 | png_ptr->zstream.avail_in = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1418 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1419 | if (ret != Z_STREAM_END) |
| 1420 | { |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1421 | png_ptr->current_text = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1422 | png_free(png_ptr, key); |
| 1423 | png_free(png_ptr, text); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1424 | return; |
| 1425 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1426 | |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1427 | png_ptr->current_text = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1428 | png_free(png_ptr, key); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1429 | key = text; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1430 | text += key_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1431 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1432 | text_ptr = (png_textp)png_malloc(png_ptr, |
| 1433 | png_sizeof(png_text)); |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1434 | text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; |
| 1435 | text_ptr->key = key; |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1436 | #ifdef PNG_iTXt_SUPPORTED |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 1437 | text_ptr->lang = NULL; |
| 1438 | text_ptr->lang_key = NULL; |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1439 | #endif |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1440 | text_ptr->text = text; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1441 | |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1442 | ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1443 | |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 1444 | png_free(png_ptr, key); |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1445 | png_free(png_ptr, text_ptr); |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1446 | |
| 1447 | if (ret) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1448 | png_warning(png_ptr, "Insufficient memory to store text chunk"); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1449 | } |
| 1450 | } |
| 1451 | #endif |
| 1452 | |
| 1453 | #if defined(PNG_READ_iTXt_SUPPORTED) |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1454 | void /* PRIVATE */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1455 | png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1456 | length) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1457 | { |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1458 | if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1459 | { |
| 1460 | png_error(png_ptr, "Out of place iTXt"); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1461 | info_ptr = info_ptr; /* to quiet some compiler warnings */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | #ifdef PNG_MAX_MALLOC_64K |
| 1465 | png_ptr->skip_length = 0; /* This may not be necessary */ |
| 1466 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1467 | if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1468 | { |
| 1469 | png_warning(png_ptr, "iTXt chunk too large to fit in memory"); |
| 1470 | png_ptr->skip_length = length - (png_uint_32)65535L; |
| 1471 | length = (png_uint_32)65535L; |
| 1472 | } |
| 1473 | #endif |
| 1474 | |
| 1475 | png_ptr->current_text = (png_charp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1476 | (png_size_t)(length + 1)); |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1477 | png_ptr->current_text[length] = '\0'; |
| 1478 | png_ptr->current_text_ptr = png_ptr->current_text; |
| 1479 | png_ptr->current_text_size = (png_size_t)length; |
| 1480 | png_ptr->current_text_left = (png_size_t)length; |
| 1481 | png_ptr->process_mode = PNG_READ_iTXt_MODE; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1482 | } |
| 1483 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1484 | void /* PRIVATE */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1485 | png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) |
| 1486 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1487 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1488 | if (png_ptr->buffer_size && png_ptr->current_text_left) |
| 1489 | { |
| 1490 | png_size_t text_size; |
| 1491 | |
| 1492 | if (png_ptr->buffer_size < png_ptr->current_text_left) |
| 1493 | text_size = png_ptr->buffer_size; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1494 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1495 | else |
| 1496 | text_size = png_ptr->current_text_left; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1497 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1498 | png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); |
| 1499 | png_ptr->current_text_left -= text_size; |
| 1500 | png_ptr->current_text_ptr += text_size; |
| 1501 | } |
| 1502 | if (!(png_ptr->current_text_left)) |
| 1503 | { |
| 1504 | png_textp text_ptr; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1505 | png_charp key; |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1506 | int comp_flag; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1507 | png_charp lang; |
| 1508 | png_charp lang_key; |
| 1509 | png_charp text; |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1510 | int ret; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1511 | |
| 1512 | if (png_ptr->buffer_size < 4) |
| 1513 | { |
| 1514 | png_push_save_buffer(png_ptr); |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | png_push_crc_finish(png_ptr); |
| 1519 | |
| 1520 | #if defined(PNG_MAX_MALLOC_64K) |
| 1521 | if (png_ptr->skip_length) |
| 1522 | return; |
| 1523 | #endif |
| 1524 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1525 | key = png_ptr->current_text; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1526 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1527 | for (lang = key; *lang; lang++) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1528 | /* empty loop */ ; |
| 1529 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1530 | if (lang < key + png_ptr->current_text_size - 3) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1531 | lang++; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1532 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1533 | comp_flag = *lang++; |
| 1534 | lang++; /* skip comp_type, always zero */ |
| 1535 | |
| 1536 | for (lang_key = lang; *lang_key; lang_key++) |
| 1537 | /* empty loop */ ; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1538 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1539 | lang_key++; /* skip NUL separator */ |
| 1540 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1541 | text=lang_key; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1542 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1543 | if (lang_key < key + png_ptr->current_text_size - 1) |
| 1544 | { |
| 1545 | for (; *text; text++) |
| 1546 | /* empty loop */ ; |
| 1547 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1548 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1549 | if (text < key + png_ptr->current_text_size) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1550 | text++; |
| 1551 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1552 | text_ptr = (png_textp)png_malloc(png_ptr, |
| 1553 | png_sizeof(png_text)); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1554 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1555 | text_ptr->compression = comp_flag + 2; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1556 | text_ptr->key = key; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1557 | text_ptr->lang = lang; |
| 1558 | text_ptr->lang_key = lang_key; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1559 | text_ptr->text = text; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1560 | text_ptr->text_length = 0; |
| 1561 | text_ptr->itxt_length = png_strlen(text); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1562 | |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1563 | ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1564 | |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1565 | png_ptr->current_text = NULL; |
| 1566 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1567 | png_free(png_ptr, text_ptr); |
Glenn Randers-Pehrson | 07748d1 | 2002-05-25 11:12:10 -0500 | [diff] [blame] | 1568 | if (ret) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1569 | png_warning(png_ptr, "Insufficient memory to store iTXt chunk"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1570 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1571 | } |
| 1572 | #endif |
| 1573 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1574 | /* This function is called when we haven't found a handler for this |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1575 | * chunk. If there isn't a problem with the chunk itself (ie a bad chunk |
| 1576 | * name or a critical chunk), the chunk is (currently) silently ignored. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1577 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1578 | void /* PRIVATE */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1579 | png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 |
| 1580 | length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1581 | { |
Glenn Randers-Pehrson | 895a9c9 | 2008-07-25 08:51:18 -0500 | [diff] [blame] | 1582 | png_uint_32 skip = 0; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1583 | |
| 1584 | if (!(png_ptr->chunk_name[0] & 0x20)) |
| 1585 | { |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1586 | #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1587 | if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != |
| 1588 | PNG_HANDLE_CHUNK_ALWAYS |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1589 | #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1590 | && png_ptr->read_user_chunk_fn == NULL |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1591 | #endif |
| 1592 | ) |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1593 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1594 | png_chunk_error(png_ptr, "unknown critical chunk"); |
| 1595 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1596 | info_ptr = info_ptr; /* to quiet some compiler warnings */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1597 | } |
| 1598 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1599 | #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
| 1600 | if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) |
| 1601 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1602 | #ifdef PNG_MAX_MALLOC_64K |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1603 | if (length > (png_uint_32)65535L) |
| 1604 | { |
| 1605 | png_warning(png_ptr, "unknown chunk too large to fit in memory"); |
| 1606 | skip = length - (png_uint_32)65535L; |
| 1607 | length = (png_uint_32)65535L; |
| 1608 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1609 | #endif |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1610 | png_memcpy((png_charp)png_ptr->unknown_chunk.name, |
| 1611 | (png_charp)png_ptr->chunk_name, |
| 1612 | png_sizeof(png_ptr->unknown_chunk.name)); |
Glenn Randers-Pehrson | 895a9c9 | 2008-07-25 08:51:18 -0500 | [diff] [blame] | 1613 | png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1] |
| 1614 | = '\0'; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1615 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1616 | png_ptr->unknown_chunk.size = (png_size_t)length; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1617 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1618 | if (length == 0) |
| 1619 | png_ptr->unknown_chunk.data = NULL; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1620 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1621 | else |
| 1622 | { |
| 1623 | png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, |
| 1624 | (png_size_t)length); |
| 1625 | png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); |
| 1626 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1627 | |
Glenn Randers-Pehrson | e1eff58 | 2001-04-14 20:15:41 -0500 | [diff] [blame] | 1628 | #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1629 | if (png_ptr->read_user_chunk_fn != NULL) |
| 1630 | { |
| 1631 | /* callback to user unknown chunk handler */ |
| 1632 | int ret; |
| 1633 | ret = (*(png_ptr->read_user_chunk_fn)) |
| 1634 | (png_ptr, &png_ptr->unknown_chunk); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1635 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1636 | if (ret < 0) |
| 1637 | png_chunk_error(png_ptr, "error in user chunk"); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1638 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1639 | if (ret == 0) |
| 1640 | { |
| 1641 | if (!(png_ptr->chunk_name[0] & 0x20)) |
| 1642 | if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != |
| 1643 | PNG_HANDLE_CHUNK_ALWAYS) |
| 1644 | png_chunk_error(png_ptr, "unknown critical chunk"); |
| 1645 | png_set_unknown_chunks(png_ptr, info_ptr, |
| 1646 | &png_ptr->unknown_chunk, 1); |
| 1647 | } |
| 1648 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1649 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1650 | else |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1651 | #endif |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1652 | png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); |
| 1653 | png_free(png_ptr, png_ptr->unknown_chunk.data); |
| 1654 | png_ptr->unknown_chunk.data = NULL; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1655 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1656 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1657 | else |
| 1658 | #endif |
| 1659 | skip=length; |
| 1660 | png_push_crc_skip(png_ptr, skip); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1661 | } |
| 1662 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1663 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1664 | png_push_have_info(png_structp png_ptr, png_infop info_ptr) |
| 1665 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1666 | if (png_ptr->info_fn != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1667 | (*(png_ptr->info_fn))(png_ptr, info_ptr); |
| 1668 | } |
| 1669 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1670 | void /* PRIVATE */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1671 | png_push_have_end(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1672 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1673 | if (png_ptr->end_fn != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1674 | (*(png_ptr->end_fn))(png_ptr, info_ptr); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1675 | } |
| 1676 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1677 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1678 | png_push_have_row(png_structp png_ptr, png_bytep row) |
| 1679 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1680 | if (png_ptr->row_fn != NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1681 | (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, |
| 1682 | (int)png_ptr->pass); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1683 | } |
| 1684 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1685 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1686 | png_progressive_combine_row (png_structp png_ptr, |
| 1687 | png_bytep old_row, png_bytep new_row) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1688 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 1689 | #ifdef PNG_USE_LOCAL_ARRAYS |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1690 | PNG_CONST int FARDATA png_pass_dsp_mask[7] = |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 1691 | {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 1692 | #endif |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1693 | if (png_ptr == NULL) |
| 1694 | return; |
| 1695 | |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 1696 | if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1697 | png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1698 | } |
| 1699 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1700 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1701 | png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1702 | png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, |
| 1703 | png_progressive_end_ptr end_fn) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1704 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1705 | if (png_ptr == NULL) |
| 1706 | return; |
| 1707 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1708 | png_ptr->info_fn = info_fn; |
| 1709 | png_ptr->row_fn = row_fn; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1710 | png_ptr->end_fn = end_fn; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1711 | |
Glenn Randers-Pehrson | 25d8224 | 2002-05-01 11:51:26 -0500 | [diff] [blame] | 1712 | png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1713 | } |
| 1714 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1715 | png_voidp PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1716 | png_get_progressive_ptr(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1717 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1718 | if (png_ptr == NULL) |
| 1719 | return (NULL); |
| 1720 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1721 | return png_ptr->io_ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1722 | } |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 1723 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |