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