Subversion Repositories Kolibri OS

Rev

Rev 1897 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1897 Rev 3928
Line 1... Line 1...
1
/* pngpread.c - read a png file in push mode
1
/* pngpread.c - read a png file in push mode
2
 *
2
 *
3
 * Last changed in libpng 1.5.1 [February 3, 2011]
3
 * Last changed in libpng 1.6.0 [February 14, 2013]
4
 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
4
 * Copyright (c) 1998-2013 Glenn Randers-Pehrson
5
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
5
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
6
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7
 *
7
 *
8
 * This code is released under the libpng license.
8
 * This code is released under the libpng license.
9
 * For conditions of distribution and use, see the disclaimer
9
 * For conditions of distribution and use, see the disclaimer
Line 25... Line 25...
25
#define PNG_READ_iTXt_MODE  7
25
#define PNG_READ_iTXt_MODE  7
26
#define PNG_ERROR_MODE      8
26
#define PNG_ERROR_MODE      8
27
 
27
 
Line 28... Line 28...
28
void PNGAPI
28
void PNGAPI
29
png_process_data(png_structp png_ptr, png_infop info_ptr,
29
png_process_data(png_structrp png_ptr, png_inforp info_ptr,
30
    png_bytep buffer, png_size_t buffer_size)
30
    png_bytep buffer, png_size_t buffer_size)
31
{
31
{
32
   if (png_ptr == NULL || info_ptr == NULL)
32
   if (png_ptr == NULL || info_ptr == NULL)
33
      return;
33
      return;
Line 40... Line 40...
40
   }
40
   }
41
}
41
}
42
 
42
 
Line 43... Line 43...
43
png_size_t PNGAPI
43
png_size_t PNGAPI
44
png_process_data_pause(png_structp png_ptr, int save)
44
png_process_data_pause(png_structrp png_ptr, int save)
45
{
45
{
46
   if (png_ptr != NULL)
46
   if (png_ptr != NULL)
47
   {
47
   {
48
      /* It's easiest for the caller if we do the save, then the caller doesn't
48
      /* It's easiest for the caller if we do the save, then the caller doesn't
49
       * have to supply the same data again:
49
       * have to supply the same data again:
Line 67... Line 67...
67
   return 0;
67
   return 0;
68
}
68
}
Line 69... Line 69...
69
 
69
 
70
png_uint_32 PNGAPI
70
png_uint_32 PNGAPI
71
png_process_data_skip(png_structp png_ptr)
71
png_process_data_skip(png_structrp png_ptr)
72
{
72
{
Line 73... Line 73...
73
   png_uint_32 remaining = 0;
73
   png_uint_32 remaining = 0;
74
 
74
 
Line 101... Line 101...
101
/* What we do with the incoming data depends on what we were previously
101
/* What we do with the incoming data depends on what we were previously
102
 * doing before we ran out of data...
102
 * doing before we ran out of data...
103
 */
103
 */
104
void /* PRIVATE */
104
void /* PRIVATE */
105
png_process_some_data(png_structp png_ptr, png_infop info_ptr)
105
png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
106
{
106
{
107
   if (png_ptr == NULL)
107
   if (png_ptr == NULL)
108
      return;
108
      return;
Line 109... Line 109...
109
 
109
 
Line 126... Line 126...
126
         png_push_read_IDAT(png_ptr);
126
         png_push_read_IDAT(png_ptr);
127
         break;
127
         break;
128
      }
128
      }
129
 
129
 
Line 130... Line -...
130
#ifdef PNG_READ_tEXt_SUPPORTED
-
 
131
      case PNG_READ_tEXt_MODE:
-
 
132
      {
-
 
133
         png_push_read_tEXt(png_ptr, info_ptr);
-
 
134
         break;
-
 
135
      }
-
 
136
 
-
 
137
#endif
-
 
138
#ifdef PNG_READ_zTXt_SUPPORTED
-
 
139
      case PNG_READ_zTXt_MODE:
-
 
140
      {
-
 
141
         png_push_read_zTXt(png_ptr, info_ptr);
-
 
142
         break;
-
 
143
      }
-
 
144
 
-
 
145
#endif
-
 
146
#ifdef PNG_READ_iTXt_SUPPORTED
-
 
147
      case PNG_READ_iTXt_MODE:
-
 
148
      {
-
 
149
         png_push_read_iTXt(png_ptr, info_ptr);
-
 
150
         break;
-
 
151
      }
-
 
152
 
-
 
153
#endif
-
 
154
      case PNG_SKIP_MODE:
130
      case PNG_SKIP_MODE:
155
      {
131
      {
156
         png_push_crc_finish(png_ptr);
132
         png_push_crc_finish(png_ptr);
157
         break;
133
         break;
158
      }
134
      }
Line 171... Line 147...
171
 * checked by the calling application, or because of multiple calls to this
147
 * checked by the calling application, or because of multiple calls to this
172
 * routine.
148
 * routine.
173
 */
149
 */
174
void /* PRIVATE */
150
void /* PRIVATE */
175
png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
151
png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
176
{
152
{
177
   png_size_t num_checked = png_ptr->sig_bytes,
153
   png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ 
178
             num_to_check = 8 - num_checked;
154
             num_to_check = 8 - num_checked;
179
 
155
 
Line 180... Line 156...
180
   if (png_ptr->buffer_size < num_to_check)
156
   if (png_ptr->buffer_size < num_to_check)
181
   {
157
   {
182
      num_to_check = png_ptr->buffer_size;
158
      num_to_check = png_ptr->buffer_size;
Line 204... Line 180...
204
   }
180
   }
205
}
181
}
206
 
182
 
Line 207... Line 183...
207
void /* PRIVATE */
183
void /* PRIVATE */
208
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
184
png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
209
{
185
{
210
      PNG_IHDR;
-
 
211
      PNG_IDAT;
-
 
212
      PNG_IEND;
-
 
213
      PNG_PLTE;
186
   png_uint_32 chunk_name;
214
#ifdef PNG_READ_bKGD_SUPPORTED
187
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
215
      PNG_bKGD;
-
 
216
#endif
-
 
217
#ifdef PNG_READ_cHRM_SUPPORTED
-
 
218
      PNG_cHRM;
-
 
219
#endif
-
 
220
#ifdef PNG_READ_gAMA_SUPPORTED
-
 
221
      PNG_gAMA;
-
 
222
#endif
-
 
223
#ifdef PNG_READ_hIST_SUPPORTED
188
   int keep; /* unknown handling method */
224
      PNG_hIST;
-
 
225
#endif
-
 
226
#ifdef PNG_READ_iCCP_SUPPORTED
-
 
227
      PNG_iCCP;
-
 
228
#endif
-
 
229
#ifdef PNG_READ_iTXt_SUPPORTED
-
 
230
      PNG_iTXt;
-
 
231
#endif
-
 
232
#ifdef PNG_READ_oFFs_SUPPORTED
-
 
233
      PNG_oFFs;
-
 
234
#endif
-
 
235
#ifdef PNG_READ_pCAL_SUPPORTED
-
 
236
      PNG_pCAL;
-
 
237
#endif
-
 
238
#ifdef PNG_READ_pHYs_SUPPORTED
-
 
239
      PNG_pHYs;
-
 
240
#endif
-
 
241
#ifdef PNG_READ_sBIT_SUPPORTED
-
 
242
      PNG_sBIT;
-
 
243
#endif
-
 
244
#ifdef PNG_READ_sCAL_SUPPORTED
-
 
245
      PNG_sCAL;
-
 
246
#endif
-
 
247
#ifdef PNG_READ_sRGB_SUPPORTED
-
 
248
      PNG_sRGB;
-
 
249
#endif
-
 
250
#ifdef PNG_READ_sPLT_SUPPORTED
-
 
251
      PNG_sPLT;
-
 
252
#endif
-
 
253
#ifdef PNG_READ_tEXt_SUPPORTED
-
 
254
      PNG_tEXt;
-
 
255
#endif
-
 
256
#ifdef PNG_READ_tIME_SUPPORTED
-
 
257
      PNG_tIME;
-
 
258
#endif
-
 
259
#ifdef PNG_READ_tRNS_SUPPORTED
-
 
260
      PNG_tRNS;
-
 
261
#endif
-
 
262
#ifdef PNG_READ_zTXt_SUPPORTED
-
 
263
      PNG_zTXt;
-
 
264
#endif
189
#endif
Line 265... Line 190...
265
 
190
 
266
   /* First we make sure we have enough data for the 4 byte chunk name
191
   /* First we make sure we have enough data for the 4 byte chunk name
267
    * and the 4 byte chunk length before proceeding with decoding the
192
    * and the 4 byte chunk length before proceeding with decoding the
Line 271... Line 196...
271
    */
196
    */
272
   if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
197
   if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
273
   {
198
   {
274
      png_byte chunk_length[4];
199
      png_byte chunk_length[4];
275
 
200
      png_byte chunk_tag[4];
-
 
201
 
Line 276... Line 202...
276
      if (png_ptr->buffer_size < 8)
202
      if (png_ptr->buffer_size < 8)
277
      {
203
      {
278
         png_push_save_buffer(png_ptr);
204
         png_push_save_buffer(png_ptr);
279
         return;
205
         return;
280
      }
206
      }
Line 281... Line 207...
281
 
207
 
282
      png_push_fill_buffer(png_ptr, chunk_length, 4);
208
      png_push_fill_buffer(png_ptr, chunk_length, 4);
283
      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
209
      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
284
      png_reset_crc(png_ptr);
210
      png_reset_crc(png_ptr);
-
 
211
      png_crc_read(png_ptr, chunk_tag, 4);
285
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
212
      png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
286
      png_check_chunk_name(png_ptr, png_ptr->chunk_name);
213
      png_check_chunk_name(png_ptr, png_ptr->chunk_name);
287
      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
214
      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
Line 288... Line 215...
288
   }
215
   }
-
 
216
 
-
 
217
   chunk_name = png_ptr->chunk_name;
-
 
218
 
289
 
219
   if (chunk_name == png_IDAT)
290
   if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
220
   {
Line -... Line 221...
-
 
221
      if (png_ptr->mode & PNG_AFTER_IDAT)
-
 
222
         png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
-
 
223
 
-
 
224
      /* If we reach an IDAT chunk, this means we have read all of the
291
      if (png_ptr->mode & PNG_AFTER_IDAT)
225
       * header chunks, and we can start reading the image (or if this
-
 
226
       * is called after the image has been read - we have an error).
-
 
227
       */
-
 
228
      if (!(png_ptr->mode & PNG_HAVE_IHDR))
-
 
229
         png_error(png_ptr, "Missing IHDR before IDAT");
-
 
230
 
-
 
231
      else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
-
 
232
          !(png_ptr->mode & PNG_HAVE_PLTE))
-
 
233
         png_error(png_ptr, "Missing PLTE before IDAT");
-
 
234
 
-
 
235
      png_ptr->mode |= PNG_HAVE_IDAT;
-
 
236
 
-
 
237
      if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
-
 
238
         if (png_ptr->push_length == 0)
-
 
239
            return;
-
 
240
 
-
 
241
      if (png_ptr->mode & PNG_AFTER_IDAT)
-
 
242
         png_benign_error(png_ptr, "Too many IDATs found");
292
         png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
243
   }
293
 
244
 
294
   if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
245
   if (chunk_name == png_IHDR)
Line 295... Line 246...
295
   {
246
   {
Line 304... Line 255...
304
 
255
 
Line 305... Line 256...
305
      png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
256
      png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
306
   }
257
   }
Line 307... Line 258...
307
 
258
 
308
   else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
259
   else if (chunk_name == png_IEND)
309
   {
260
   {
310
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
261
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
311
      {
262
      {
312
         png_push_save_buffer(png_ptr);
263
         png_push_save_buffer(png_ptr);
Line 319... Line 270...
319
      png_push_have_end(png_ptr, info_ptr);
270
      png_push_have_end(png_ptr, info_ptr);
320
   }
271
   }
321
 
272
 
Line 322... Line 273...
322
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
273
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
323
   else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
274
   else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
324
   {
275
   {
325
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
276
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
326
      {
277
      {
327
         png_push_save_buffer(png_ptr);
278
         png_push_save_buffer(png_ptr);
328
         return;
279
         return;
329
      }
280
      }
Line 330... Line -...
330
 
-
 
331
      if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
-
 
332
         png_ptr->mode |= PNG_HAVE_IDAT;
-
 
333
 
281
 
Line 334... Line 282...
334
      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
282
      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep);
335
 
283
 
336
      if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
-
 
337
         png_ptr->mode |= PNG_HAVE_PLTE;
-
 
338
 
-
 
339
      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
-
 
340
      {
-
 
341
         if (!(png_ptr->mode & PNG_HAVE_IHDR))
-
 
342
            png_error(png_ptr, "Missing IHDR before IDAT");
-
 
343
 
-
 
344
         else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
-
 
345
             !(png_ptr->mode & PNG_HAVE_PLTE))
-
 
346
            png_error(png_ptr, "Missing PLTE before IDAT");
284
      if (chunk_name == png_PLTE)
Line 347... Line 285...
347
      }
285
         png_ptr->mode |= PNG_HAVE_PLTE;
348
   }
286
   }
349
 
287
 
350
#endif
288
#endif
351
   else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
289
   else if (chunk_name == png_PLTE)
352
   {
290
   {
353
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
291
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
354
      {
292
      {
355
         png_push_save_buffer(png_ptr);
293
         png_push_save_buffer(png_ptr);
356
         return;
294
         return;
Line 357... Line 295...
357
      }
295
      }
358
      png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
-
 
359
   }
-
 
360
 
-
 
361
   else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
-
 
362
   {
-
 
363
      /* If we reach an IDAT chunk, this means we have read all of the
-
 
364
       * header chunks, and we can start reading the image (or if this
-
 
365
       * is called after the image has been read - we have an error).
-
 
366
       */
-
 
367
 
-
 
368
      if (!(png_ptr->mode & PNG_HAVE_IHDR))
-
 
369
         png_error(png_ptr, "Missing IHDR before IDAT");
-
 
370
 
-
 
371
      else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
-
 
372
          !(png_ptr->mode & PNG_HAVE_PLTE))
296
      png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
373
         png_error(png_ptr, "Missing PLTE before IDAT");
-
 
374
 
-
 
375
      if (png_ptr->mode & PNG_HAVE_IDAT)
-
 
376
      {
-
 
377
         if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
-
 
378
            if (png_ptr->push_length == 0)
-
 
379
               return;
-
 
380
 
-
 
381
         if (png_ptr->mode & PNG_AFTER_IDAT)
297
   }
382
            png_benign_error(png_ptr, "Too many IDATs found");
-
 
383
      }
298
 
384
 
299
   else if (chunk_name == png_IDAT)
385
      png_ptr->idat_size = png_ptr->push_length;
300
   {
386
      png_ptr->mode |= PNG_HAVE_IDAT;
301
      png_ptr->idat_size = png_ptr->push_length;
387
      png_ptr->process_mode = PNG_READ_IDAT_MODE;
302
      png_ptr->process_mode = PNG_READ_IDAT_MODE;
388
      png_push_have_info(png_ptr, info_ptr);
303
      png_push_have_info(png_ptr, info_ptr);
389
      png_ptr->zstream.avail_out =
304
      png_ptr->zstream.avail_out =
390
          (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
305
          (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
Line 391... Line 306...
391
          png_ptr->iwidth) + 1;
306
          png_ptr->iwidth) + 1;
392
      png_ptr->zstream.next_out = png_ptr->row_buf;
307
      png_ptr->zstream.next_out = png_ptr->row_buf;
393
      return;
308
      return;
394
   }
309
   }
395
 
310
 
396
#ifdef PNG_READ_gAMA_SUPPORTED
311
#ifdef PNG_READ_gAMA_SUPPORTED
397
   else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
312
   else if (png_ptr->chunk_name == png_gAMA)
Line 406... Line 321...
406
   }
321
   }
407
 
322
 
Line 408... Line 323...
408
#endif
323
#endif
409
#ifdef PNG_READ_sBIT_SUPPORTED
324
#ifdef PNG_READ_sBIT_SUPPORTED
410
   else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
325
   else if (png_ptr->chunk_name == png_sBIT)
411
   {
326
   {
412
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
327
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
413
      {
328
      {
414
         png_push_save_buffer(png_ptr);
329
         png_push_save_buffer(png_ptr);
415
         return;
330
         return;
Line 419... Line 334...
419
   }
334
   }
420
 
335
 
Line 421... Line 336...
421
#endif
336
#endif
422
#ifdef PNG_READ_cHRM_SUPPORTED
337
#ifdef PNG_READ_cHRM_SUPPORTED
423
   else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
338
   else if (png_ptr->chunk_name == png_cHRM)
424
   {
339
   {
425
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
340
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
426
      {
341
      {
427
         png_push_save_buffer(png_ptr);
342
         png_push_save_buffer(png_ptr);
428
         return;
343
         return;
Line 432... Line 347...
432
   }
347
   }
433
 
348
 
Line 434... Line 349...
434
#endif
349
#endif
435
#ifdef PNG_READ_sRGB_SUPPORTED
350
#ifdef PNG_READ_sRGB_SUPPORTED
436
   else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
351
   else if (chunk_name == png_sRGB)
437
   {
352
   {
438
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
353
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
439
      {
354
      {
440
         png_push_save_buffer(png_ptr);
355
         png_push_save_buffer(png_ptr);
441
         return;
356
         return;
Line 445... Line 360...
445
   }
360
   }
446
 
361
 
Line 447... Line 362...
447
#endif
362
#endif
448
#ifdef PNG_READ_iCCP_SUPPORTED
363
#ifdef PNG_READ_iCCP_SUPPORTED
449
   else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
364
   else if (png_ptr->chunk_name == png_iCCP)
450
   {
365
   {
451
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
366
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
452
      {
367
      {
453
         png_push_save_buffer(png_ptr);
368
         png_push_save_buffer(png_ptr);
454
         return;
369
         return;
Line 458... Line 373...
458
   }
373
   }
459
 
374
 
Line 460... Line 375...
460
#endif
375
#endif
461
#ifdef PNG_READ_sPLT_SUPPORTED
376
#ifdef PNG_READ_sPLT_SUPPORTED
462
   else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
377
   else if (chunk_name == png_sPLT)
463
   {
378
   {
464
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
379
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
465
      {
380
      {
466
         png_push_save_buffer(png_ptr);
381
         png_push_save_buffer(png_ptr);
467
         return;
382
         return;
Line 471... Line 386...
471
   }
386
   }
472
 
387
 
Line 473... Line 388...
473
#endif
388
#endif
474
#ifdef PNG_READ_tRNS_SUPPORTED
389
#ifdef PNG_READ_tRNS_SUPPORTED
475
   else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
390
   else if (chunk_name == png_tRNS)
476
   {
391
   {
477
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
392
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
478
      {
393
      {
479
         png_push_save_buffer(png_ptr);
394
         png_push_save_buffer(png_ptr);
480
         return;
395
         return;
Line 484... Line 399...
484
   }
399
   }
485
 
400
 
Line 486... Line 401...
486
#endif
401
#endif
487
#ifdef PNG_READ_bKGD_SUPPORTED
402
#ifdef PNG_READ_bKGD_SUPPORTED
488
   else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
403
   else if (chunk_name == png_bKGD)
489
   {
404
   {
490
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
405
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
491
      {
406
      {
492
         png_push_save_buffer(png_ptr);
407
         png_push_save_buffer(png_ptr);
493
         return;
408
         return;
Line 497... Line 412...
497
   }
412
   }
498
 
413
 
Line 499... Line 414...
499
#endif
414
#endif
500
#ifdef PNG_READ_hIST_SUPPORTED
415
#ifdef PNG_READ_hIST_SUPPORTED
501
   else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
416
   else if (chunk_name == png_hIST)
502
   {
417
   {
503
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
418
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
504
      {
419
      {
505
         png_push_save_buffer(png_ptr);
420
         png_push_save_buffer(png_ptr);
506
         return;
421
         return;
Line 510... Line 425...
510
   }
425
   }
511
 
426
 
Line 512... Line 427...
512
#endif
427
#endif
513
#ifdef PNG_READ_pHYs_SUPPORTED
428
#ifdef PNG_READ_pHYs_SUPPORTED
514
   else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
429
   else if (chunk_name == png_pHYs)
515
   {
430
   {
516
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
431
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
517
      {
432
      {
518
         png_push_save_buffer(png_ptr);
433
         png_push_save_buffer(png_ptr);
519
         return;
434
         return;
Line 523... Line 438...
523
   }
438
   }
524
 
439
 
Line 525... Line 440...
525
#endif
440
#endif
526
#ifdef PNG_READ_oFFs_SUPPORTED
441
#ifdef PNG_READ_oFFs_SUPPORTED
527
   else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
442
   else if (chunk_name == png_oFFs)
528
   {
443
   {
529
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
444
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
530
      {
445
      {
531
         png_push_save_buffer(png_ptr);
446
         png_push_save_buffer(png_ptr);
532
         return;
447
         return;
Line 536... Line 451...
536
   }
451
   }
537
#endif
452
#endif
538
 
453
 
Line 539... Line 454...
539
#ifdef PNG_READ_pCAL_SUPPORTED
454
#ifdef PNG_READ_pCAL_SUPPORTED
540
   else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
455
   else if (chunk_name == png_pCAL)
541
   {
456
   {
542
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
457
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
543
      {
458
      {
544
         png_push_save_buffer(png_ptr);
459
         png_push_save_buffer(png_ptr);
545
         return;
460
         return;
Line 549... Line 464...
549
   }
464
   }
550
 
465
 
Line 551... Line 466...
551
#endif
466
#endif
552
#ifdef PNG_READ_sCAL_SUPPORTED
467
#ifdef PNG_READ_sCAL_SUPPORTED
553
   else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
468
   else if (chunk_name == png_sCAL)
554
   {
469
   {
555
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
470
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
556
      {
471
      {
557
         png_push_save_buffer(png_ptr);
472
         png_push_save_buffer(png_ptr);
558
         return;
473
         return;
Line 562... Line 477...
562
   }
477
   }
563
 
478
 
Line 564... Line 479...
564
#endif
479
#endif
565
#ifdef PNG_READ_tIME_SUPPORTED
480
#ifdef PNG_READ_tIME_SUPPORTED
566
   else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
481
   else if (chunk_name == png_tIME)
567
   {
482
   {
568
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
483
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
569
      {
484
      {
570
         png_push_save_buffer(png_ptr);
485
         png_push_save_buffer(png_ptr);
571
         return;
486
         return;
Line 575... Line 490...
575
   }
490
   }
576
 
491
 
Line 577... Line 492...
577
#endif
492
#endif
578
#ifdef PNG_READ_tEXt_SUPPORTED
493
#ifdef PNG_READ_tEXt_SUPPORTED
579
   else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
494
   else if (chunk_name == png_tEXt)
580
   {
495
   {
581
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
496
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
582
      {
497
      {
583
         png_push_save_buffer(png_ptr);
498
         png_push_save_buffer(png_ptr);
584
         return;
499
         return;
585
      }
500
      }
Line 586... Line 501...
586
 
501
 
587
      png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
502
      png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
Line 588... Line 503...
588
   }
503
   }
589
 
504
 
590
#endif
505
#endif
591
#ifdef PNG_READ_zTXt_SUPPORTED
506
#ifdef PNG_READ_zTXt_SUPPORTED
592
   else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
507
   else if (chunk_name == png_zTXt)
593
   {
508
   {
594
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
509
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
595
      {
510
      {
596
         png_push_save_buffer(png_ptr);
511
         png_push_save_buffer(png_ptr);
Line 597... Line 512...
597
         return;
512
         return;
598
      }
513
      }
Line 599... Line 514...
599
 
514
 
600
      png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
515
      png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
601
   }
516
   }
602
 
517
 
603
#endif
518
#endif
604
#ifdef PNG_READ_iTXt_SUPPORTED
519
#ifdef PNG_READ_iTXt_SUPPORTED
605
   else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
520
   else if (chunk_name == png_iTXt)
606
   {
521
   {
607
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
522
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Line 608... Line 523...
608
      {
523
      {
609
         png_push_save_buffer(png_ptr);
524
         png_push_save_buffer(png_ptr);
Line 610... Line 525...
610
         return;
525
         return;
611
      }
526
      }
612
 
527
 
613
      png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
528
      png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
614
   }
529
   }
615
 
530
 
616
#endif
531
#endif
617
   else
532
   else
618
   {
533
   {
-
 
534
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
619
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
535
      {
Line 620... Line 536...
620
      {
536
         png_push_save_buffer(png_ptr);
621
         png_push_save_buffer(png_ptr);
537
         return;
Line 622... Line 538...
622
         return;
538
      }
623
      }
539
      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
624
      png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
540
         PNG_HANDLE_CHUNK_AS_DEFAULT);
625
   }
541
   }
626
 
542
 
627
   png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
543
   png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
Line 628... Line 544...
628
}
544
}
629
 
545
 
630
void /* PRIVATE */
546
void /* PRIVATE */
631
png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
547
png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip)
632
{
548
{
633
   png_ptr->process_mode = PNG_SKIP_MODE;
549
   png_ptr->process_mode = PNG_SKIP_MODE;
634
   png_ptr->skip_length = skip;
550
   png_ptr->skip_length = skip;
Line 713... Line 629...
713
 
629
 
Line 714... Line 630...
714
      else
630
      else
715
         save_size = png_ptr->save_buffer_size;
631
         save_size = png_ptr->save_buffer_size;
Line 716... Line 632...
716
 
632
 
717
      png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
633
      memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
718
      length -= save_size;
634
      length -= save_size;
719
      ptr += save_size;
635
      ptr += save_size;
720
      png_ptr->buffer_size -= save_size;
636
      png_ptr->buffer_size -= save_size;
721
      png_ptr->save_buffer_size -= save_size;
637
      png_ptr->save_buffer_size -= save_size;
Line 730... Line 646...
730
 
646
 
Line 731... Line 647...
731
      else
647
      else
732
         save_size = png_ptr->current_buffer_size;
648
         save_size = png_ptr->current_buffer_size;
Line 733... Line 649...
733
 
649
 
734
      png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
650
      memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
735
      png_ptr->buffer_size -= save_size;
651
      png_ptr->buffer_size -= save_size;
736
      png_ptr->current_buffer_size -= save_size;
652
      png_ptr->current_buffer_size -= save_size;
737
      png_ptr->current_buffer_ptr += save_size;
653
      png_ptr->current_buffer_ptr += save_size;
738
   }
654
   }
Line 739... Line 655...
739
}
655
}
740
 
656
 
741
void /* PRIVATE */
657
void /* PRIVATE */
742
png_push_save_buffer(png_structp png_ptr)
658
png_push_save_buffer(png_structrp png_ptr)
743
{
659
{
744
   if (png_ptr->save_buffer_size)
660
   if (png_ptr->save_buffer_size)
745
   {
661
   {
Line 779... Line 695...
779
         png_free(png_ptr, old_buffer);
695
         png_free(png_ptr, old_buffer);
780
         png_error(png_ptr, "Insufficient memory for save_buffer");
696
         png_error(png_ptr, "Insufficient memory for save_buffer");
781
      }
697
      }
782
 
698
 
Line 783... Line 699...
783
      png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
699
      memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
784
      png_free(png_ptr, old_buffer);
700
      png_free(png_ptr, old_buffer);
785
      png_ptr->save_buffer_max = new_max;
701
      png_ptr->save_buffer_max = new_max;
786
   }
702
   }
787
   if (png_ptr->current_buffer_size)
703
   if (png_ptr->current_buffer_size)
788
   {
704
   {
789
      png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
705
      memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
790
         png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
706
         png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
791
      png_ptr->save_buffer_size += png_ptr->current_buffer_size;
707
      png_ptr->save_buffer_size += png_ptr->current_buffer_size;
792
      png_ptr->current_buffer_size = 0;
708
      png_ptr->current_buffer_size = 0;
793
   }
709
   }
794
   png_ptr->save_buffer_ptr = png_ptr->save_buffer;
710
   png_ptr->save_buffer_ptr = png_ptr->save_buffer;
795
   png_ptr->buffer_size = 0;
711
   png_ptr->buffer_size = 0;
796
}
712
}
Line 797... Line 713...
797
 
713
 
798
void /* PRIVATE */
714
void /* PRIVATE */
799
png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
715
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
800
   png_size_t buffer_length)
716
   png_size_t buffer_length)
801
{
717
{
802
   png_ptr->current_buffer = buffer;
718
   png_ptr->current_buffer = buffer;
803
   png_ptr->current_buffer_size = buffer_length;
719
   png_ptr->current_buffer_size = buffer_length;
804
   png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
720
   png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
805
   png_ptr->current_buffer_ptr = png_ptr->current_buffer;
721
   png_ptr->current_buffer_ptr = png_ptr->current_buffer;
Line 806... Line 722...
806
}
722
}
807
 
723
 
808
void /* PRIVATE */
724
void /* PRIVATE */
809
png_push_read_IDAT(png_structp png_ptr)
-
 
810
{
725
png_push_read_IDAT(png_structrp png_ptr)
811
   PNG_IDAT;
726
{
812
   if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
727
   if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
-
 
728
   {
Line -... Line 729...
-
 
729
      png_byte chunk_length[4];
813
   {
730
      png_byte chunk_tag[4];
814
      png_byte chunk_length[4];
731
 
815
 
732
      /* TODO: this code can be commoned up with the same code in push_read */
816
      if (png_ptr->buffer_size < 8)
733
      if (png_ptr->buffer_size < 8)
817
      {
734
      {
Line 818... Line 735...
818
         png_push_save_buffer(png_ptr);
735
         png_push_save_buffer(png_ptr);
819
         return;
736
         return;
820
      }
737
      }
821
 
738
 
-
 
739
      png_push_fill_buffer(png_ptr, chunk_length, 4);
822
      png_push_fill_buffer(png_ptr, chunk_length, 4);
740
      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
Line 823... Line 741...
823
      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
741
      png_reset_crc(png_ptr);
824
      png_reset_crc(png_ptr);
742
      png_crc_read(png_ptr, chunk_tag, 4);
825
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
743
      png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
Line 826... Line 744...
826
      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
744
      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
827
 
745
 
Line 828... Line 746...
828
      if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
746
      if (png_ptr->chunk_name != png_IDAT)
829
      {
747
      {
Line 830... Line 748...
830
         png_ptr->process_mode = PNG_READ_CHUNK_MODE;
748
         png_ptr->process_mode = PNG_READ_CHUNK_MODE;
831
 
749
 
-
 
750
         if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
832
         if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
751
            png_error(png_ptr, "Not enough compressed data");
833
            png_error(png_ptr, "Not enough compressed data");
752
 
834
 
753
         return;
835
         return;
754
      }
Line 899... Line 818...
899
 
818
 
Line 900... Line 819...
900
      png_crc_finish(png_ptr, 0);
819
      png_crc_finish(png_ptr, 0);
901
      png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
820
      png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
902
      png_ptr->mode |= PNG_AFTER_IDAT;
821
      png_ptr->mode |= PNG_AFTER_IDAT;
-
 
822
      png_ptr->zowner = 0;
903
   }
823
   }
904
}
824
}
Line 905... Line 825...
905
 
825
 
906
void /* PRIVATE */
826
void /* PRIVATE */
907
png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
827
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
908
   png_size_t buffer_length)
828
   png_size_t buffer_length)
909
{
829
{
910
   /* The caller checks for a non-zero buffer length. */
830
   /* The caller checks for a non-zero buffer length. */
911
   if (!(buffer_length > 0) || buffer == NULL)
831
   if (!(buffer_length > 0) || buffer == NULL)
Line 915... Line 835...
915
    * before returning, calling the row callback as required to
835
    * before returning, calling the row callback as required to
916
    * handle the uncompressed results.
836
    * handle the uncompressed results.
917
    */
837
    */
918
   png_ptr->zstream.next_in = buffer;
838
   png_ptr->zstream.next_in = buffer;
919
   png_ptr->zstream.avail_in = (uInt)buffer_length;
839
   /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */
-
 
840
   png_ptr->zstream.avail_in = (uInt)buffer_length;
920
 
841
 
Line 921... Line 842...
921
   /* Keep going until the decompressed data is all processed
842
   /* Keep going until the decompressed data is all processed
922
    * or the stream marked as finished.
843
    * or the stream marked as finished.
923
    */
844
    */
924
   while (png_ptr->zstream.avail_in > 0 &&
845
   while (png_ptr->zstream.avail_in > 0 &&
925
          !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
846
      !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
926
   {
847
   {
927
      int ret;
848
      int ret;
Line 928... Line 849...
928
 
849
 
929
      /* We have data for zlib, but we must check that zlib
850
      /* We have data for zlib, but we must check that zlib
930
       * has someplace to put the results.  It doesn't matter
851
       * has someplace to put the results.  It doesn't matter
931
       * if we don't expect any results -- it may be the input
852
       * if we don't expect any results -- it may be the input
932
       * data is just the LZ end code.
853
       * data is just the LZ end code.
933
       */
854
       */
934
      if (!(png_ptr->zstream.avail_out > 0))
855
      if (!(png_ptr->zstream.avail_out > 0))
935
      {
856
      {
936
         png_ptr->zstream.avail_out =
857
         /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */
937
             (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
858
         png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth,
Line 938... Line 859...
938
             png_ptr->iwidth) + 1;
859
             png_ptr->iwidth) + 1);
939
 
860
 
Line 940... Line 861...
940
         png_ptr->zstream.next_out = png_ptr->row_buf;
861
         png_ptr->zstream.next_out = png_ptr->row_buf;
Line 952... Line 873...
952
      /* Check for any failure before proceeding. */
873
      /* Check for any failure before proceeding. */
953
      if (ret != Z_OK && ret != Z_STREAM_END)
874
      if (ret != Z_OK && ret != Z_STREAM_END)
954
      {
875
      {
955
         /* Terminate the decompression. */
876
         /* Terminate the decompression. */
956
         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
877
         png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
-
 
878
         png_ptr->zowner = 0;
Line 957... Line 879...
957
 
879
 
958
         /* This may be a truncated stream (missing or
880
         /* This may be a truncated stream (missing or
959
          * damaged end code).  Treat that as a warning.
881
          * damaged end code).  Treat that as a warning.
960
          */
882
          */
Line 980... Line 902...
980
             png_ptr->pass > 6)
902
             png_ptr->pass > 6)
981
         {
903
         {
982
            /* Extra data. */
904
            /* Extra data. */
983
            png_warning(png_ptr, "Extra compressed data in IDAT");
905
            png_warning(png_ptr, "Extra compressed data in IDAT");
984
            png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
906
            png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
985
 
907
            png_ptr->zowner = 0;
-
 
908
 
Line 986... Line 909...
986
            /* Do no more processing; skip the unprocessed
909
            /* Do no more processing; skip the unprocessed
987
             * input check below.
910
             * input check below.
988
             */
911
             */
989
            return;
912
            return;
Line 995... Line 918...
995
      }
918
      }
996
 
919
 
Line 997... Line 920...
997
      /* And check for the end of the stream. */
920
      /* And check for the end of the stream. */
998
      if (ret == Z_STREAM_END)
921
      if (ret == Z_STREAM_END)
999
         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
922
         png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
1000
   }
923
   }
Line 1001... Line 924...
1001
 
924
 
1002
   /* All the data should have been processed, if anything
925
   /* All the data should have been processed, if anything
1003
    * is left at this point we have bytes of IDAT data
926
    * is left at this point we have bytes of IDAT data
Line 1007... Line 930...
1007
      png_warning(png_ptr, "Extra compression data in IDAT");
930
      png_warning(png_ptr, "Extra compression data in IDAT");
1008
}
931
}
1009
 
932
 
Line 1010... Line 933...
1010
void /* PRIVATE */
933
void /* PRIVATE */
1011
png_push_process_row(png_structp png_ptr)
934
png_push_process_row(png_structrp png_ptr)
1012
{
935
{
1013
   png_ptr->row_info.color_type = png_ptr->color_type;
936
   /* 1.5.6: row_info moved out of png_struct to a local here. */
1014
   png_ptr->row_info.width = png_ptr->iwidth;
937
   png_row_info row_info;
1015
   png_ptr->row_info.channels = png_ptr->channels;
-
 
1016
   png_ptr->row_info.bit_depth = png_ptr->bit_depth;
-
 
1017
   png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
-
 
Line -... Line 938...
-
 
938
 
-
 
939
   row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */
-
 
940
   row_info.color_type = png_ptr->color_type;
-
 
941
   row_info.bit_depth = png_ptr->bit_depth;
-
 
942
   row_info.channels = png_ptr->channels;
1018
 
943
   row_info.pixel_depth = png_ptr->pixel_depth;
-
 
944
   row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);
-
 
945
 
-
 
946
   if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
-
 
947
   {
-
 
948
      if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
1019
   png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
949
         png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
-
 
950
            png_ptr->prev_row + 1, png_ptr->row_buf[0]);
-
 
951
      else
-
 
952
         png_error(png_ptr, "bad adaptive filter value");
-
 
953
   }
-
 
954
 
-
 
955
   /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before
-
 
956
    * 1.5.6, while the buffer really is this big in current versions of libpng
-
 
957
    * it may not be in the future, so this was changed just to copy the
-
 
958
    * interlaced row count:
-
 
959
    */
Line 1020... Line 960...
1020
       png_ptr->row_info.width);
960
   memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
1021
 
961
 
1022
   png_read_filter_row(png_ptr, &(png_ptr->row_info),
962
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
-
 
963
   if (png_ptr->transformations)
Line -... Line 964...
-
 
964
      png_do_read_transformations(png_ptr, &row_info);
-
 
965
#endif
-
 
966
 
-
 
967
   /* The transformed pixel depth should match the depth now in row_info. */
-
 
968
   if (png_ptr->transformed_pixel_depth == 0)
-
 
969
   {
-
 
970
      png_ptr->transformed_pixel_depth = row_info.pixel_depth;
-
 
971
      if (row_info.pixel_depth > png_ptr->maximum_pixel_depth)
-
 
972
         png_error(png_ptr, "progressive row overflow");
1023
       png_ptr->row_buf + 1, png_ptr->prev_row + 1,
973
   }
Line 1024... Line -...
1024
       (int)(png_ptr->row_buf[0]));
-
 
1025
 
-
 
Line 1026... Line 974...
1026
   png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
974
 
1027
 
975
   else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth)
1028
   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
976
      png_error(png_ptr, "internal progressive row size calculation error");
1029
      png_do_read_transformations(png_ptr);
977
 
1030
 
978
 
1031
#ifdef PNG_READ_INTERLACING_SUPPORTED
-
 
1032
   /* Blow up interlaced rows to full size */
979
#ifdef PNG_READ_INTERLACING_SUPPORTED
1033
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
-
 
1034
   {
-
 
1035
      if (png_ptr->pass < 6)
980
   /* Blow up interlaced rows to full size */
Line 1036... Line 981...
1036
/*       old interface (pre-1.0.9):
981
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
1037
         png_do_read_interlace(&(png_ptr->row_info),
982
   {
1038
             png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
983
      if (png_ptr->pass < 6)
1039
 */
984
         png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
Line 1214... Line 1159...
1214
   }
1159
   }
1215
}
1160
}
1216
 
1161
 
Line 1217... Line 1162...
1217
void /* PRIVATE */
1162
void /* PRIVATE */
1218
png_read_push_finish_row(png_structp png_ptr)
1163
png_read_push_finish_row(png_structrp png_ptr)
1219
{
1164
{
-
 
1165
#ifdef PNG_READ_INTERLACING_SUPPORTED
1220
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1166
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
Line 1221... Line 1167...
1221
 
1167
 
1222
   /* Start of interlace block */
1168
   /* Start of interlace block */
Line 1223... Line 1169...
1223
   PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1169
   static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1224
 
1170
 
Line 1225... Line 1171...
1225
   /* Offset to next interlace block */
1171
   /* Offset to next interlace block */
1226
   PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1172
   static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
Line 1227... Line 1173...
1227
 
1173
 
1228
   /* Start of interlace block in the y direction */
1174
   /* Start of interlace block in the y direction */
Line 1229... Line 1175...
1229
   PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1175
   static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1230
 
1176
 
1231
   /* Offset to next interlace block in the y direction */
1177
   /* Offset to next interlace block in the y direction */
1232
   PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1178
   static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
-
 
1179
 
Line 1233... Line 1180...
1233
 
1180
   /* Height of interlace block.  This is not currently used - if you need
1234
   /* Height of interlace block.  This is not currently used - if you need
1181
    * it, uncomment it here and in png.h
1235
    * it, uncomment it here and in png.h
1182
   static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
Line 1236... Line 1183...
1236
   PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
1183
   */
1237
   */
1184
#endif
1238
 
1185
 
1239
   png_ptr->row_number++;
1186
   png_ptr->row_number++;
1240
   if (png_ptr->row_number < png_ptr->num_rows)
1187
   if (png_ptr->row_number < png_ptr->num_rows)
Line 1241... Line 1188...
1241
      return;
1188
      return;
1242
 
1189
 
1243
#ifdef PNG_READ_INTERLACING_SUPPORTED
1190
#ifdef PNG_READ_INTERLACING_SUPPORTED
1244
   if (png_ptr->interlaced)
1191
   if (png_ptr->interlaced)
Line 1277... Line 1224...
1277
   }
1224
   }
1278
#endif /* PNG_READ_INTERLACING_SUPPORTED */
1225
#endif /* PNG_READ_INTERLACING_SUPPORTED */
1279
}
1226
}
1280
 
1227
 
Line 1281... Line -...
1281
#ifdef PNG_READ_tEXt_SUPPORTED
-
 
1282
void /* PRIVATE */
-
 
1283
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
-
 
1284
    length)
-
 
1285
{
-
 
1286
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
-
 
1287
      {
-
 
1288
         PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
-
 
1289
         png_error(png_ptr, "Out of place tEXt");
-
 
1290
         /*NOT REACHED*/
-
 
1291
      }
-
 
1292
 
-
 
1293
#ifdef PNG_MAX_MALLOC_64K
-
 
1294
   png_ptr->skip_length = 0;  /* This may not be necessary */
-
 
1295
 
-
 
1296
   if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
-
 
1297
   {
-
 
1298
      png_warning(png_ptr, "tEXt chunk too large to fit in memory");
-
 
1299
      png_ptr->skip_length = length - (png_uint_32)65535L;
-
 
1300
      length = (png_uint_32)65535L;
-
 
1301
   }
-
 
1302
#endif
-
 
1303
 
-
 
1304
   png_ptr->current_text = (png_charp)png_malloc(png_ptr,
-
 
1305
       (png_size_t)(length + 1));
-
 
1306
   png_ptr->current_text[length] = '\0';
-
 
1307
   png_ptr->current_text_ptr = png_ptr->current_text;
-
 
1308
   png_ptr->current_text_size = (png_size_t)length;
-
 
1309
   png_ptr->current_text_left = (png_size_t)length;
-
 
1310
   png_ptr->process_mode = PNG_READ_tEXt_MODE;
-
 
1311
}
-
 
1312
 
-
 
1313
void /* PRIVATE */
1228
void /* PRIVATE */
1314
png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
-
 
1315
{
-
 
1316
   if (png_ptr->buffer_size && png_ptr->current_text_left)
-
 
1317
   {
-
 
1318
      png_size_t text_size;
-
 
1319
 
-
 
1320
      if (png_ptr->buffer_size < png_ptr->current_text_left)
-
 
1321
         text_size = png_ptr->buffer_size;
-
 
1322
 
-
 
1323
      else
-
 
1324
         text_size = png_ptr->current_text_left;
-
 
1325
 
-
 
1326
      png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
-
 
1327
      png_ptr->current_text_left -= text_size;
-
 
1328
      png_ptr->current_text_ptr += text_size;
-
 
1329
   }
-
 
1330
   if (!(png_ptr->current_text_left))
-
 
1331
   {
-
 
1332
      png_textp text_ptr;
-
 
1333
      png_charp text;
-
 
1334
      png_charp key;
-
 
1335
      int ret;
-
 
1336
 
-
 
1337
      if (png_ptr->buffer_size < 4)
-
 
1338
      {
-
 
1339
         png_push_save_buffer(png_ptr);
-
 
1340
         return;
-
 
1341
      }
-
 
1342
 
-
 
1343
      png_push_crc_finish(png_ptr);
-
 
1344
 
-
 
1345
#ifdef PNG_MAX_MALLOC_64K
-
 
1346
      if (png_ptr->skip_length)
-
 
1347
         return;
-
 
1348
#endif
-
 
1349
 
-
 
1350
      key = png_ptr->current_text;
-
 
1351
 
-
 
1352
      for (text = key; *text; text++)
-
 
1353
         /* Empty loop */ ;
-
 
1354
 
-
 
1355
      if (text < key + png_ptr->current_text_size)
-
 
1356
         text++;
-
 
1357
 
-
 
1358
      text_ptr = (png_textp)png_malloc(png_ptr, png_sizeof(png_text));
-
 
1359
      text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
-
 
1360
      text_ptr->key = key;
-
 
1361
      text_ptr->itxt_length = 0;
-
 
1362
      text_ptr->lang = NULL;
-
 
1363
      text_ptr->lang_key = NULL;
-
 
1364
      text_ptr->text = text;
-
 
1365
 
-
 
1366
      ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
-
 
1367
 
-
 
1368
      png_free(png_ptr, key);
-
 
1369
      png_free(png_ptr, text_ptr);
-
 
1370
      png_ptr->current_text = NULL;
-
 
1371
 
-
 
1372
      if (ret)
-
 
1373
         png_warning(png_ptr, "Insufficient memory to store text chunk");
-
 
1374
   }
-
 
1375
}
-
 
1376
#endif
-
 
1377
 
-
 
1378
#ifdef PNG_READ_zTXt_SUPPORTED
-
 
1379
void /* PRIVATE */
-
 
1380
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
-
 
1381
   length)
-
 
1382
{
-
 
1383
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
-
 
1384
   {
-
 
1385
      PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
-
 
1386
      png_error(png_ptr, "Out of place zTXt");
-
 
1387
      /*NOT REACHED*/
-
 
1388
   }
-
 
1389
 
-
 
1390
#ifdef PNG_MAX_MALLOC_64K
-
 
1391
   /* We can't handle zTXt chunks > 64K, since we don't have enough space
-
 
1392
    * to be able to store the uncompressed data.  Actually, the threshold
-
 
1393
    * is probably around 32K, but it isn't as definite as 64K is.
-
 
1394
    */
-
 
1395
   if (length > (png_uint_32)65535L)
-
 
1396
   {
-
 
1397
      png_warning(png_ptr, "zTXt chunk too large to fit in memory");
-
 
1398
      png_push_crc_skip(png_ptr, length);
-
 
1399
      return;
-
 
1400
   }
-
 
1401
#endif
-
 
1402
 
-
 
1403
   png_ptr->current_text = (png_charp)png_malloc(png_ptr,
-
 
1404
       (png_size_t)(length + 1));
-
 
1405
   png_ptr->current_text[length] = '\0';
-
 
1406
   png_ptr->current_text_ptr = png_ptr->current_text;
-
 
1407
   png_ptr->current_text_size = (png_size_t)length;
-
 
1408
   png_ptr->current_text_left = (png_size_t)length;
-
 
1409
   png_ptr->process_mode = PNG_READ_zTXt_MODE;
-
 
1410
}
-
 
1411
 
-
 
1412
void /* PRIVATE */
-
 
1413
png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
-
 
1414
{
-
 
1415
   if (png_ptr->buffer_size && png_ptr->current_text_left)
-
 
1416
   {
-
 
1417
      png_size_t text_size;
-
 
1418
 
-
 
1419
      if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
-
 
1420
         text_size = png_ptr->buffer_size;
-
 
1421
 
-
 
1422
      else
-
 
1423
         text_size = png_ptr->current_text_left;
-
 
1424
 
-
 
1425
      png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
-
 
1426
      png_ptr->current_text_left -= text_size;
-
 
1427
      png_ptr->current_text_ptr += text_size;
-
 
1428
   }
-
 
1429
   if (!(png_ptr->current_text_left))
-
 
1430
   {
-
 
1431
      png_textp text_ptr;
-
 
1432
      png_charp text;
-
 
1433
      png_charp key;
-
 
1434
      int ret;
-
 
1435
      png_size_t text_size, key_size;
-
 
1436
 
-
 
1437
      if (png_ptr->buffer_size < 4)
-
 
1438
      {
-
 
1439
         png_push_save_buffer(png_ptr);
-
 
1440
         return;
-
 
1441
      }
-
 
1442
 
-
 
1443
      png_push_crc_finish(png_ptr);
-
 
1444
 
-
 
1445
      key = png_ptr->current_text;
-
 
1446
 
-
 
1447
      for (text = key; *text; text++)
-
 
1448
         /* Empty loop */ ;
-
 
1449
 
-
 
1450
      /* zTXt can't have zero text */
-
 
1451
      if (text >= key + png_ptr->current_text_size)
-
 
1452
      {
-
 
1453
         png_ptr->current_text = NULL;
-
 
1454
         png_free(png_ptr, key);
-
 
1455
         return;
-
 
1456
      }
-
 
1457
 
-
 
1458
      text++;
-
 
1459
 
-
 
1460
      if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */
-
 
1461
      {
-
 
1462
         png_ptr->current_text = NULL;
-
 
1463
         png_free(png_ptr, key);
-
 
1464
         return;
-
 
1465
      }
-
 
1466
 
-
 
1467
      text++;
-
 
1468
 
-
 
1469
      png_ptr->zstream.next_in = (png_bytep)text;
-
 
1470
      png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
-
 
1471
          (text - key));
-
 
1472
      png_ptr->zstream.next_out = png_ptr->zbuf;
-
 
1473
      png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
-
 
1474
 
-
 
1475
      key_size = text - key;
-
 
1476
      text_size = 0;
-
 
1477
      text = NULL;
-
 
1478
      ret = Z_STREAM_END;
-
 
1479
 
-
 
1480
      while (png_ptr->zstream.avail_in)
-
 
1481
      {
-
 
1482
         ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
-
 
1483
         if (ret != Z_OK && ret != Z_STREAM_END)
-
 
1484
         {
-
 
1485
            inflateReset(&png_ptr->zstream);
-
 
1486
            png_ptr->zstream.avail_in = 0;
-
 
1487
            png_ptr->current_text = NULL;
-
 
1488
            png_free(png_ptr, key);
-
 
1489
            png_free(png_ptr, text);
-
 
1490
            return;
-
 
1491
         }
-
 
1492
 
-
 
1493
         if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
-
 
1494
         {
-
 
1495
            if (text == NULL)
-
 
1496
            {
-
 
1497
               text = (png_charp)png_malloc(png_ptr,
-
 
1498
                   (png_ptr->zbuf_size
-
 
1499
                   - png_ptr->zstream.avail_out + key_size + 1));
-
 
1500
 
-
 
1501
               png_memcpy(text + key_size, png_ptr->zbuf,
-
 
1502
                   png_ptr->zbuf_size - png_ptr->zstream.avail_out);
-
 
1503
 
-
 
1504
               png_memcpy(text, key, key_size);
-
 
1505
 
-
 
1506
               text_size = key_size + png_ptr->zbuf_size -
-
 
1507
                   png_ptr->zstream.avail_out;
-
 
1508
 
-
 
1509
               *(text + text_size) = '\0';
-
 
1510
            }
-
 
1511
 
-
 
1512
            else
-
 
1513
            {
-
 
1514
               png_charp tmp;
-
 
1515
 
-
 
1516
               tmp = text;
-
 
1517
               text = (png_charp)png_malloc(png_ptr, text_size +
-
 
1518
                   (png_ptr->zbuf_size
-
 
1519
                   - png_ptr->zstream.avail_out + 1));
-
 
1520
 
-
 
1521
               png_memcpy(text, tmp, text_size);
-
 
1522
               png_free(png_ptr, tmp);
-
 
1523
 
-
 
1524
               png_memcpy(text + text_size, png_ptr->zbuf,
-
 
1525
                   png_ptr->zbuf_size - png_ptr->zstream.avail_out);
-
 
1526
 
-
 
1527
               text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
-
 
1528
               *(text + text_size) = '\0';
-
 
1529
            }
-
 
1530
 
-
 
1531
            if (ret != Z_STREAM_END)
-
 
1532
            {
-
 
1533
               png_ptr->zstream.next_out = png_ptr->zbuf;
-
 
1534
               png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
-
 
1535
            }
-
 
1536
         }
-
 
1537
         else
-
 
1538
         {
-
 
1539
            break;
-
 
1540
         }
-
 
1541
 
-
 
1542
         if (ret == Z_STREAM_END)
-
 
1543
            break;
-
 
1544
      }
-
 
1545
 
-
 
1546
      inflateReset(&png_ptr->zstream);
-
 
1547
      png_ptr->zstream.avail_in = 0;
-
 
1548
 
-
 
1549
      if (ret != Z_STREAM_END)
-
 
1550
      {
-
 
1551
         png_ptr->current_text = NULL;
-
 
1552
         png_free(png_ptr, key);
-
 
1553
         png_free(png_ptr, text);
-
 
1554
         return;
-
 
1555
      }
-
 
1556
 
-
 
1557
      png_ptr->current_text = NULL;
-
 
1558
      png_free(png_ptr, key);
-
 
1559
      key = text;
-
 
1560
      text += key_size;
-
 
1561
 
-
 
1562
      text_ptr = (png_textp)png_malloc(png_ptr,
-
 
1563
          png_sizeof(png_text));
-
 
1564
      text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
-
 
1565
      text_ptr->key = key;
-
 
1566
      text_ptr->itxt_length = 0;
-
 
1567
      text_ptr->lang = NULL;
-
 
1568
      text_ptr->lang_key = NULL;
-
 
1569
      text_ptr->text = text;
-
 
1570
 
-
 
1571
      ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
-
 
1572
 
-
 
1573
      png_free(png_ptr, key);
-
 
1574
      png_free(png_ptr, text_ptr);
-
 
1575
 
-
 
1576
      if (ret)
-
 
1577
         png_warning(png_ptr, "Insufficient memory to store text chunk");
-
 
1578
   }
-
 
1579
}
-
 
1580
#endif
-
 
1581
 
-
 
1582
#ifdef PNG_READ_iTXt_SUPPORTED
-
 
1583
void /* PRIVATE */
-
 
1584
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
-
 
1585
    length)
-
 
1586
{
-
 
1587
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
-
 
1588
   {
-
 
1589
      PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
-
 
1590
      png_error(png_ptr, "Out of place iTXt");
-
 
1591
      /*NOT REACHED*/
-
 
1592
   }
-
 
1593
 
-
 
1594
#ifdef PNG_MAX_MALLOC_64K
-
 
1595
   png_ptr->skip_length = 0;  /* This may not be necessary */
-
 
1596
 
-
 
1597
   if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
-
 
1598
   {
-
 
1599
      png_warning(png_ptr, "iTXt chunk too large to fit in memory");
-
 
1600
      png_ptr->skip_length = length - (png_uint_32)65535L;
-
 
1601
      length = (png_uint_32)65535L;
-
 
1602
   }
-
 
1603
#endif
-
 
1604
 
-
 
1605
   png_ptr->current_text = (png_charp)png_malloc(png_ptr,
-
 
1606
       (png_size_t)(length + 1));
-
 
1607
   png_ptr->current_text[length] = '\0';
-
 
1608
   png_ptr->current_text_ptr = png_ptr->current_text;
-
 
1609
   png_ptr->current_text_size = (png_size_t)length;
-
 
1610
   png_ptr->current_text_left = (png_size_t)length;
-
 
1611
   png_ptr->process_mode = PNG_READ_iTXt_MODE;
-
 
1612
}
-
 
1613
 
-
 
1614
void /* PRIVATE */
-
 
1615
png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
-
 
1616
{
-
 
1617
 
-
 
1618
   if (png_ptr->buffer_size && png_ptr->current_text_left)
-
 
1619
   {
-
 
1620
      png_size_t text_size;
-
 
1621
 
-
 
1622
      if (png_ptr->buffer_size < png_ptr->current_text_left)
-
 
1623
         text_size = png_ptr->buffer_size;
-
 
1624
 
-
 
1625
      else
-
 
1626
         text_size = png_ptr->current_text_left;
-
 
1627
 
-
 
1628
      png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
-
 
1629
      png_ptr->current_text_left -= text_size;
-
 
1630
      png_ptr->current_text_ptr += text_size;
-
 
1631
   }
-
 
1632
 
-
 
1633
   if (!(png_ptr->current_text_left))
-
 
1634
   {
-
 
1635
      png_textp text_ptr;
-
 
1636
      png_charp key;
-
 
1637
      int comp_flag;
-
 
1638
      png_charp lang;
-
 
1639
      png_charp lang_key;
-
 
1640
      png_charp text;
-
 
1641
      int ret;
-
 
1642
 
-
 
1643
      if (png_ptr->buffer_size < 4)
-
 
1644
      {
-
 
1645
         png_push_save_buffer(png_ptr);
-
 
1646
         return;
-
 
1647
      }
-
 
1648
 
-
 
1649
      png_push_crc_finish(png_ptr);
-
 
1650
 
-
 
1651
#ifdef PNG_MAX_MALLOC_64K
-
 
1652
      if (png_ptr->skip_length)
-
 
1653
         return;
-
 
1654
#endif
-
 
1655
 
-
 
1656
      key = png_ptr->current_text;
-
 
1657
 
-
 
1658
      for (lang = key; *lang; lang++)
-
 
1659
         /* Empty loop */ ;
-
 
1660
 
-
 
1661
      if (lang < key + png_ptr->current_text_size - 3)
-
 
1662
         lang++;
-
 
1663
 
-
 
1664
      comp_flag = *lang++;
-
 
1665
      lang++;     /* Skip comp_type, always zero */
-
 
1666
 
-
 
1667
      for (lang_key = lang; *lang_key; lang_key++)
-
 
1668
         /* Empty loop */ ;
-
 
1669
 
-
 
1670
      lang_key++;        /* Skip NUL separator */
-
 
1671
 
-
 
1672
      text=lang_key;
-
 
1673
 
-
 
1674
      if (lang_key < key + png_ptr->current_text_size - 1)
-
 
1675
      {
-
 
1676
         for (; *text; text++)
-
 
1677
            /* Empty loop */ ;
-
 
1678
      }
-
 
1679
 
-
 
1680
      if (text < key + png_ptr->current_text_size)
-
 
1681
         text++;
-
 
1682
 
-
 
1683
      text_ptr = (png_textp)png_malloc(png_ptr,
-
 
1684
          png_sizeof(png_text));
-
 
1685
 
-
 
1686
      text_ptr->compression = comp_flag + 2;
-
 
1687
      text_ptr->key = key;
-
 
1688
      text_ptr->lang = lang;
-
 
1689
      text_ptr->lang_key = lang_key;
-
 
1690
      text_ptr->text = text;
-
 
1691
      text_ptr->text_length = 0;
-
 
1692
      text_ptr->itxt_length = png_strlen(text);
-
 
1693
 
-
 
1694
      ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
-
 
1695
 
-
 
1696
      png_ptr->current_text = NULL;
-
 
1697
 
-
 
1698
      png_free(png_ptr, text_ptr);
-
 
1699
      if (ret)
-
 
1700
         png_warning(png_ptr, "Insufficient memory to store iTXt chunk");
-
 
1701
   }
-
 
1702
}
-
 
1703
#endif
-
 
1704
 
-
 
1705
/* This function is called when we haven't found a handler for this
-
 
1706
 * chunk.  If there isn't a problem with the chunk itself (ie a bad chunk
-
 
1707
 * name or a critical chunk), the chunk is (currently) silently ignored.
-
 
1708
 */
-
 
1709
void /* PRIVATE */
-
 
1710
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
-
 
1711
    length)
-
 
1712
{
-
 
1713
   png_uint_32 skip = 0;
-
 
1714
 
-
 
1715
   if (!(png_ptr->chunk_name[0] & 0x20))
-
 
1716
   {
-
 
1717
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
-
 
1718
      if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
-
 
1719
          PNG_HANDLE_CHUNK_ALWAYS
-
 
1720
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
-
 
1721
          && png_ptr->read_user_chunk_fn == NULL
-
 
1722
#endif
-
 
1723
          )
-
 
1724
#endif
-
 
1725
         png_chunk_error(png_ptr, "unknown critical chunk");
-
 
1726
 
-
 
1727
      PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
-
 
1728
   }
-
 
1729
 
-
 
1730
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
-
 
1731
   if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
-
 
1732
   {
-
 
1733
#ifdef PNG_MAX_MALLOC_64K
-
 
1734
      if (length > (png_uint_32)65535L)
-
 
1735
      {
-
 
1736
         png_warning(png_ptr, "unknown chunk too large to fit in memory");
-
 
1737
         skip = length - (png_uint_32)65535L;
-
 
1738
         length = (png_uint_32)65535L;
-
 
1739
      }
-
 
1740
#endif
-
 
1741
      png_memcpy((png_charp)png_ptr->unknown_chunk.name,
-
 
1742
          (png_charp)png_ptr->chunk_name,
-
 
1743
          png_sizeof(png_ptr->unknown_chunk.name));
-
 
1744
      png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1]
-
 
1745
          = '\0';
-
 
1746
 
-
 
1747
      png_ptr->unknown_chunk.size = (png_size_t)length;
-
 
1748
 
-
 
1749
      if (length == 0)
-
 
1750
         png_ptr->unknown_chunk.data = NULL;
-
 
1751
 
-
 
1752
      else
-
 
1753
      {
-
 
1754
         png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
-
 
1755
             (png_size_t)length);
-
 
1756
         png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
-
 
1757
      }
-
 
1758
 
-
 
1759
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
-
 
1760
      if (png_ptr->read_user_chunk_fn != NULL)
-
 
1761
      {
-
 
1762
         /* Callback to user unknown chunk handler */
-
 
1763
         int ret;
-
 
1764
         ret = (*(png_ptr->read_user_chunk_fn))
-
 
1765
             (png_ptr, &png_ptr->unknown_chunk);
-
 
1766
 
-
 
1767
         if (ret < 0)
-
 
1768
            png_chunk_error(png_ptr, "error in user chunk");
-
 
1769
 
-
 
1770
         if (ret == 0)
-
 
1771
         {
-
 
1772
            if (!(png_ptr->chunk_name[0] & 0x20))
-
 
1773
               if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
-
 
1774
                   PNG_HANDLE_CHUNK_ALWAYS)
-
 
1775
                  png_chunk_error(png_ptr, "unknown critical chunk");
-
 
1776
            png_set_unknown_chunks(png_ptr, info_ptr,
-
 
1777
                &png_ptr->unknown_chunk, 1);
-
 
1778
         }
-
 
1779
      }
-
 
1780
 
-
 
1781
      else
-
 
1782
#endif
-
 
1783
         png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
-
 
1784
      png_free(png_ptr, png_ptr->unknown_chunk.data);
-
 
1785
      png_ptr->unknown_chunk.data = NULL;
-
 
1786
   }
-
 
1787
 
-
 
1788
   else
-
 
1789
#endif
-
 
1790
      skip=length;
-
 
1791
   png_push_crc_skip(png_ptr, skip);
-
 
1792
}
-
 
1793
 
-
 
1794
void /* PRIVATE */
-
 
1795
png_push_have_info(png_structp png_ptr, png_infop info_ptr)
1229
png_push_have_info(png_structrp png_ptr, png_inforp info_ptr)
1796
{
1230
{
1797
   if (png_ptr->info_fn != NULL)
1231
   if (png_ptr->info_fn != NULL)
1798
      (*(png_ptr->info_fn))(png_ptr, info_ptr);
1232
      (*(png_ptr->info_fn))(png_ptr, info_ptr);
1799
}
1233
}
Line 1800... Line 1234...
1800
 
1234
 
1801
void /* PRIVATE */
1235
void /* PRIVATE */
1802
png_push_have_end(png_structp png_ptr, png_infop info_ptr)
1236
png_push_have_end(png_structrp png_ptr, png_inforp info_ptr)
1803
{
1237
{
1804
   if (png_ptr->end_fn != NULL)
1238
   if (png_ptr->end_fn != NULL)
1805
      (*(png_ptr->end_fn))(png_ptr, info_ptr);
1239
      (*(png_ptr->end_fn))(png_ptr, info_ptr);
Line 1806... Line 1240...
1806
}
1240
}
1807
 
1241
 
1808
void /* PRIVATE */
1242
void /* PRIVATE */
1809
png_push_have_row(png_structp png_ptr, png_bytep row)
1243
png_push_have_row(png_structrp png_ptr, png_bytep row)
1810
{
1244
{
1811
   if (png_ptr->row_fn != NULL)
1245
   if (png_ptr->row_fn != NULL)
1812
      (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
1246
      (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
Line -... Line 1247...
-
 
1247
         (int)png_ptr->pass);
1813
         (int)png_ptr->pass);
1248
}
1814
}
1249
 
1815
 
1250
#ifdef PNG_READ_INTERLACING_SUPPORTED
1816
void PNGAPI
1251
void PNGAPI
1817
png_progressive_combine_row (png_structp png_ptr, png_bytep old_row,
-
 
1818
    png_const_bytep new_row)
-
 
1819
{
-
 
1820
   PNG_CONST int FARDATA png_pass_dsp_mask[7] =
1252
png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row,
1821
      {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
1253
    png_const_bytep new_row)
Line -... Line 1254...
-
 
1254
{
1822
 
1255
   if (png_ptr == NULL)
-
 
1256
      return;
-
 
1257
 
-
 
1258
   /* new_row is a flag here - if it is NULL then the app callback was called
1823
   if (png_ptr == NULL)
1259
    * from an empty row (see the calls to png_struct::row_fn below), otherwise
1824
      return;
1260
    * it must be png_ptr->row_buf+1
-
 
1261
    */
Line 1825... Line 1262...
1825
 
1262
   if (new_row != NULL)
1826
   if (new_row != NULL)    /* new_row must == png_ptr->row_buf here. */
1263
      png_combine_row(png_ptr, old_row, 1/*display*/);
1827
      png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
1264
}
1828
}
1265
#endif /* PNG_READ_INTERLACING_SUPPORTED */
1829
 
1266
 
1830
void PNGAPI
1267
void PNGAPI
1831
png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
1268
png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr,
Line 1842... Line 1279...
1842
   png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1279
   png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1843
}
1280
}
Line 1844... Line 1281...
1844
 
1281
 
1845
png_voidp PNGAPI
1282
png_voidp PNGAPI
1846
png_get_progressive_ptr(png_const_structp png_ptr)
1283
png_get_progressive_ptr(png_const_structrp png_ptr)
1847
{
1284
{
1848
   if (png_ptr == NULL)
1285
   if (png_ptr == NULL)
Line 1849... Line 1286...
1849
      return (NULL);
1286
      return (NULL);