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