~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to frmts/png/libpng/pngpread.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/* pngpread.c - read a png file in push mode
3
3
 *
4
 
 * Last changed in libpng 1.2.32 [September 18, 2008]
5
 
 * For conditions of distribution and use, see copyright notice in png.h
6
 
 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
 
4
 * Last changed in libpng 1.2.44 [June 26, 2010]
 
5
 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
7
6
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
7
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
 
8
 *
 
9
 * This code is released under the libpng license.
 
10
 * For conditions of distribution and use, see the disclaimer
 
11
 * and license in png.h
9
12
 */
10
13
 
11
14
#define PNG_INTERNAL
 
15
#define PNG_NO_PEDANTIC_WARNINGS
12
16
#include "png.h"
13
17
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
14
18
 
15
 
/* push model modes */
 
19
/* Push model modes */
16
20
#define PNG_READ_SIG_MODE   0
17
21
#define PNG_READ_CHUNK_MODE 1
18
22
#define PNG_READ_IDAT_MODE  2
27
31
png_process_data(png_structp png_ptr, png_infop info_ptr,
28
32
   png_bytep buffer, png_size_t buffer_size)
29
33
{
30
 
   if (png_ptr == NULL || info_ptr == NULL) return;
 
34
   if (png_ptr == NULL || info_ptr == NULL)
 
35
      return;
 
36
 
31
37
   png_push_restore_buffer(png_ptr, buffer, buffer_size);
32
38
 
33
39
   while (png_ptr->buffer_size)
42
48
void /* PRIVATE */
43
49
png_process_some_data(png_structp png_ptr, png_infop info_ptr)
44
50
{
45
 
   if (png_ptr == NULL) return;
 
51
   if (png_ptr == NULL)
 
52
      return;
 
53
 
46
54
   switch (png_ptr->process_mode)
47
55
   {
48
56
      case PNG_READ_SIG_MODE:
50
58
         png_push_read_sig(png_ptr, info_ptr);
51
59
         break;
52
60
      }
 
61
 
53
62
      case PNG_READ_CHUNK_MODE:
54
63
      {
55
64
         png_push_read_chunk(png_ptr, info_ptr);
56
65
         break;
57
66
      }
 
67
 
58
68
      case PNG_READ_IDAT_MODE:
59
69
      {
60
70
         png_push_read_IDAT(png_ptr);
61
71
         break;
62
72
      }
63
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
73
 
 
74
#ifdef PNG_READ_tEXt_SUPPORTED
64
75
      case PNG_READ_tEXt_MODE:
65
76
      {
66
77
         png_push_read_tEXt(png_ptr, info_ptr);
67
78
         break;
68
79
      }
 
80
 
69
81
#endif
70
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
82
#ifdef PNG_READ_zTXt_SUPPORTED
71
83
      case PNG_READ_zTXt_MODE:
72
84
      {
73
85
         png_push_read_zTXt(png_ptr, info_ptr);
74
86
         break;
75
87
      }
 
88
 
76
89
#endif
77
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
90
#ifdef PNG_READ_iTXt_SUPPORTED
78
91
      case PNG_READ_iTXt_MODE:
79
92
      {
80
93
         png_push_read_iTXt(png_ptr, info_ptr);
81
94
         break;
82
95
      }
 
96
 
83
97
#endif
84
98
      case PNG_SKIP_MODE:
85
99
      {
86
100
         png_push_crc_finish(png_ptr);
87
101
         break;
88
102
      }
 
103
 
89
104
      default:
90
105
      {
91
106
         png_ptr->buffer_size = 0;
140
155
      PNG_CONST PNG_IDAT;
141
156
      PNG_CONST PNG_IEND;
142
157
      PNG_CONST PNG_PLTE;
143
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
158
#ifdef PNG_READ_bKGD_SUPPORTED
144
159
      PNG_CONST PNG_bKGD;
145
160
#endif
146
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
161
#ifdef PNG_READ_cHRM_SUPPORTED
147
162
      PNG_CONST PNG_cHRM;
148
163
#endif
149
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
164
#ifdef PNG_READ_gAMA_SUPPORTED
150
165
      PNG_CONST PNG_gAMA;
151
166
#endif
152
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
167
#ifdef PNG_READ_hIST_SUPPORTED
153
168
      PNG_CONST PNG_hIST;
154
169
#endif
155
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
170
#ifdef PNG_READ_iCCP_SUPPORTED
156
171
      PNG_CONST PNG_iCCP;
157
172
#endif
158
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
173
#ifdef PNG_READ_iTXt_SUPPORTED
159
174
      PNG_CONST PNG_iTXt;
160
175
#endif
161
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
176
#ifdef PNG_READ_oFFs_SUPPORTED
162
177
      PNG_CONST PNG_oFFs;
163
178
#endif
164
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
179
#ifdef PNG_READ_pCAL_SUPPORTED
165
180
      PNG_CONST PNG_pCAL;
166
181
#endif
167
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
182
#ifdef PNG_READ_pHYs_SUPPORTED
168
183
      PNG_CONST PNG_pHYs;
169
184
#endif
170
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
185
#ifdef PNG_READ_sBIT_SUPPORTED
171
186
      PNG_CONST PNG_sBIT;
172
187
#endif
173
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
188
#ifdef PNG_READ_sCAL_SUPPORTED
174
189
      PNG_CONST PNG_sCAL;
175
190
#endif
176
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
191
#ifdef PNG_READ_sRGB_SUPPORTED
177
192
      PNG_CONST PNG_sRGB;
178
193
#endif
179
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
194
#ifdef PNG_READ_sPLT_SUPPORTED
180
195
      PNG_CONST PNG_sPLT;
181
196
#endif
182
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
197
#ifdef PNG_READ_tEXt_SUPPORTED
183
198
      PNG_CONST PNG_tEXt;
184
199
#endif
185
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
200
#ifdef PNG_READ_tIME_SUPPORTED
186
201
      PNG_CONST PNG_tIME;
187
202
#endif
188
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
203
#ifdef PNG_READ_tRNS_SUPPORTED
189
204
      PNG_CONST PNG_tRNS;
190
205
#endif
191
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
206
#ifdef PNG_READ_zTXt_SUPPORTED
192
207
      PNG_CONST PNG_zTXt;
193
208
#endif
194
209
#endif /* PNG_USE_LOCAL_ARRAYS */
 
210
 
195
211
   /* First we make sure we have enough data for the 4 byte chunk name
196
212
    * and the 4 byte chunk length before proceeding with decoding the
197
213
    * chunk data.  To fully decode each of these chunks, we also make
224
240
   {
225
241
      if (png_ptr->push_length != 13)
226
242
         png_error(png_ptr, "Invalid IHDR length");
 
243
 
227
244
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
228
245
      {
229
246
         png_push_save_buffer(png_ptr);
230
247
         return;
231
248
      }
 
249
 
232
250
      png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
233
251
   }
 
252
 
234
253
   else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
235
254
   {
236
255
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
238
257
         png_push_save_buffer(png_ptr);
239
258
         return;
240
259
      }
 
260
 
241
261
      png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
242
262
 
243
263
      png_ptr->process_mode = PNG_READ_DONE_MODE;
244
264
      png_push_have_end(png_ptr, info_ptr);
245
265
   }
 
266
 
246
267
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
247
268
   else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
248
269
   {
251
272
         png_push_save_buffer(png_ptr);
252
273
         return;
253
274
      }
 
275
 
254
276
      if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
255
277
         png_ptr->mode |= PNG_HAVE_IDAT;
 
278
 
256
279
      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
 
280
 
257
281
      if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
258
282
         png_ptr->mode |= PNG_HAVE_PLTE;
 
283
 
259
284
      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
260
285
      {
261
286
         if (!(png_ptr->mode & PNG_HAVE_IHDR))
262
287
            png_error(png_ptr, "Missing IHDR before IDAT");
 
288
 
263
289
         else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
264
290
                  !(png_ptr->mode & PNG_HAVE_PLTE))
265
291
            png_error(png_ptr, "Missing PLTE before IDAT");
266
292
      }
267
293
   }
 
294
 
268
295
#endif
269
296
   else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
270
297
   {
275
302
      }
276
303
      png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
277
304
   }
 
305
 
278
306
   else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
279
307
   {
280
308
      /* If we reach an IDAT chunk, this means we have read all of the
281
309
       * header chunks, and we can start reading the image (or if this
282
310
       * is called after the image has been read - we have an error).
283
311
       */
284
 
     if (!(png_ptr->mode & PNG_HAVE_IHDR))
285
 
       png_error(png_ptr, "Missing IHDR before IDAT");
286
 
     else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
287
 
         !(png_ptr->mode & PNG_HAVE_PLTE))
288
 
       png_error(png_ptr, "Missing PLTE before IDAT");
 
312
 
 
313
      if (!(png_ptr->mode & PNG_HAVE_IHDR))
 
314
         png_error(png_ptr, "Missing IHDR before IDAT");
 
315
 
 
316
      else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
 
317
          !(png_ptr->mode & PNG_HAVE_PLTE))
 
318
         png_error(png_ptr, "Missing PLTE before IDAT");
289
319
 
290
320
      if (png_ptr->mode & PNG_HAVE_IDAT)
291
321
      {
292
322
         if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
293
 
           if (png_ptr->push_length == 0)
294
 
              return;
 
323
            if (png_ptr->push_length == 0)
 
324
               return;
295
325
 
296
326
         if (png_ptr->mode & PNG_AFTER_IDAT)
297
327
            png_error(png_ptr, "Too many IDAT's found");
301
331
      png_ptr->mode |= PNG_HAVE_IDAT;
302
332
      png_ptr->process_mode = PNG_READ_IDAT_MODE;
303
333
      png_push_have_info(png_ptr, info_ptr);
304
 
      png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
 
334
      png_ptr->zstream.avail_out =
 
335
          (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
 
336
          png_ptr->iwidth) + 1;
305
337
      png_ptr->zstream.next_out = png_ptr->row_buf;
306
338
      return;
307
339
   }
308
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
340
 
 
341
#ifdef PNG_READ_gAMA_SUPPORTED
309
342
   else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
310
343
   {
311
344
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
313
346
         png_push_save_buffer(png_ptr);
314
347
         return;
315
348
      }
 
349
 
316
350
      png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
317
351
   }
 
352
 
318
353
#endif
319
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
354
#ifdef PNG_READ_sBIT_SUPPORTED
320
355
   else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
321
356
   {
322
357
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
324
359
         png_push_save_buffer(png_ptr);
325
360
         return;
326
361
      }
 
362
 
327
363
      png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
328
364
   }
 
365
 
329
366
#endif
330
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
367
#ifdef PNG_READ_cHRM_SUPPORTED
331
368
   else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
332
369
   {
333
370
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
335
372
         png_push_save_buffer(png_ptr);
336
373
         return;
337
374
      }
 
375
 
338
376
      png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
339
377
   }
 
378
 
340
379
#endif
341
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
380
#ifdef PNG_READ_sRGB_SUPPORTED
342
381
   else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
343
382
   {
344
383
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
346
385
         png_push_save_buffer(png_ptr);
347
386
         return;
348
387
      }
 
388
 
349
389
      png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
350
390
   }
 
391
 
351
392
#endif
352
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
393
#ifdef PNG_READ_iCCP_SUPPORTED
353
394
   else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
354
395
   {
355
396
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
357
398
         png_push_save_buffer(png_ptr);
358
399
         return;
359
400
      }
 
401
 
360
402
      png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
361
403
   }
 
404
 
362
405
#endif
363
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
406
#ifdef PNG_READ_sPLT_SUPPORTED
364
407
   else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
365
408
   {
366
409
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
368
411
         png_push_save_buffer(png_ptr);
369
412
         return;
370
413
      }
 
414
 
371
415
      png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
372
416
   }
 
417
 
373
418
#endif
374
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
419
#ifdef PNG_READ_tRNS_SUPPORTED
375
420
   else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
376
421
   {
377
422
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
379
424
         png_push_save_buffer(png_ptr);
380
425
         return;
381
426
      }
 
427
 
382
428
      png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
383
429
   }
 
430
 
384
431
#endif
385
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
432
#ifdef PNG_READ_bKGD_SUPPORTED
386
433
   else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
387
434
   {
388
435
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
390
437
         png_push_save_buffer(png_ptr);
391
438
         return;
392
439
      }
 
440
 
393
441
      png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
394
442
   }
 
443
 
395
444
#endif
396
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
445
#ifdef PNG_READ_hIST_SUPPORTED
397
446
   else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
398
447
   {
399
448
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
401
450
         png_push_save_buffer(png_ptr);
402
451
         return;
403
452
      }
 
453
 
404
454
      png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
405
455
   }
 
456
 
406
457
#endif
407
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
458
#ifdef PNG_READ_pHYs_SUPPORTED
408
459
   else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
409
460
   {
410
461
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
412
463
         png_push_save_buffer(png_ptr);
413
464
         return;
414
465
      }
 
466
 
415
467
      png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
416
468
   }
 
469
 
417
470
#endif
418
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
471
#ifdef PNG_READ_oFFs_SUPPORTED
419
472
   else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
420
473
   {
421
474
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
423
476
         png_push_save_buffer(png_ptr);
424
477
         return;
425
478
      }
 
479
 
426
480
      png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
427
481
   }
428
482
#endif
429
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
483
 
 
484
#ifdef PNG_READ_pCAL_SUPPORTED
430
485
   else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
431
486
   {
432
487
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
434
489
         png_push_save_buffer(png_ptr);
435
490
         return;
436
491
      }
 
492
 
437
493
      png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
438
494
   }
 
495
 
439
496
#endif
440
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
497
#ifdef PNG_READ_sCAL_SUPPORTED
441
498
   else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
442
499
   {
443
500
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
445
502
         png_push_save_buffer(png_ptr);
446
503
         return;
447
504
      }
 
505
 
448
506
      png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
449
507
   }
 
508
 
450
509
#endif
451
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
510
#ifdef PNG_READ_tIME_SUPPORTED
452
511
   else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
453
512
   {
454
513
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
456
515
         png_push_save_buffer(png_ptr);
457
516
         return;
458
517
      }
 
518
 
459
519
      png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
460
520
   }
 
521
 
461
522
#endif
462
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
523
#ifdef PNG_READ_tEXt_SUPPORTED
463
524
   else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
464
525
   {
465
526
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
467
528
         png_push_save_buffer(png_ptr);
468
529
         return;
469
530
      }
 
531
 
470
532
      png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
471
533
   }
 
534
 
472
535
#endif
473
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
536
#ifdef PNG_READ_zTXt_SUPPORTED
474
537
   else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
475
538
   {
476
539
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
478
541
         png_push_save_buffer(png_ptr);
479
542
         return;
480
543
      }
 
544
 
481
545
      png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
482
546
   }
 
547
 
483
548
#endif
484
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
549
#ifdef PNG_READ_iTXt_SUPPORTED
485
550
   else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
486
551
   {
487
552
      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
489
554
         png_push_save_buffer(png_ptr);
490
555
         return;
491
556
      }
 
557
 
492
558
      png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
493
559
   }
 
560
 
494
561
#endif
495
562
   else
496
563
   {
565
632
{
566
633
   png_bytep ptr;
567
634
 
568
 
   if (png_ptr == NULL) return;
 
635
   if (png_ptr == NULL)
 
636
      return;
 
637
 
569
638
   ptr = buffer;
570
639
   if (png_ptr->save_buffer_size)
571
640
   {
589
658
 
590
659
      if (length < png_ptr->current_buffer_size)
591
660
         save_size = length;
 
661
 
592
662
      else
593
663
         save_size = png_ptr->current_buffer_size;
594
664
 
629
699
      {
630
700
        png_error(png_ptr, "Potential overflow of save_buffer");
631
701
      }
 
702
 
632
703
      new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
633
704
      old_buffer = png_ptr->save_buffer;
634
 
      png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
 
705
      png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr,
635
706
         (png_uint_32)new_max);
 
707
      if (png_ptr->save_buffer == NULL)
 
708
      {
 
709
        png_free(png_ptr, old_buffer);
 
710
        png_error(png_ptr, "Insufficient memory for save_buffer");
 
711
      }
636
712
      png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
637
713
      png_free(png_ptr, old_buffer);
638
714
      png_ptr->save_buffer_max = new_max;
697
773
      if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
698
774
      {
699
775
         save_size = (png_size_t)png_ptr->idat_size;
700
 
         /* check for overflow */
 
776
 
 
777
         /* Check for overflow */
701
778
         if ((png_uint_32)save_size != png_ptr->idat_size)
702
779
            png_error(png_ptr, "save_size overflowed in pngpread");
703
780
      }
705
782
         save_size = png_ptr->save_buffer_size;
706
783
 
707
784
      png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
708
 
      if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
709
 
         png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
 
785
 
 
786
      png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
 
787
 
710
788
      png_ptr->idat_size -= save_size;
711
789
      png_ptr->buffer_size -= save_size;
712
790
      png_ptr->save_buffer_size -= save_size;
719
797
      if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
720
798
      {
721
799
         save_size = (png_size_t)png_ptr->idat_size;
722
 
         /* check for overflow */
 
800
 
 
801
         /* Check for overflow */
723
802
         if ((png_uint_32)save_size != png_ptr->idat_size)
724
803
            png_error(png_ptr, "save_size overflowed in pngpread");
725
804
      }
727
806
         save_size = png_ptr->current_buffer_size;
728
807
 
729
808
      png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
730
 
      if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
731
 
        png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
 
809
 
 
810
      png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
732
811
 
733
812
      png_ptr->idat_size -= save_size;
734
813
      png_ptr->buffer_size -= save_size;
753
832
png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
754
833
   png_size_t buffer_length)
755
834
{
756
 
   int ret;
757
 
 
758
 
   if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
759
 
      png_error(png_ptr, "Extra compression data");
760
 
 
 
835
   /* The caller checks for a non-zero buffer length. */
 
836
   if (!(buffer_length > 0) || buffer == NULL)
 
837
      png_error(png_ptr, "No IDAT data (internal error)");
 
838
 
 
839
   /* This routine must process all the data it has been given
 
840
    * before returning, calling the row callback as required to
 
841
    * handle the uncompressed results.
 
842
    */
761
843
   png_ptr->zstream.next_in = buffer;
762
844
   png_ptr->zstream.avail_in = (uInt)buffer_length;
763
 
   for (;;)
 
845
 
 
846
   /* Keep going until the decompressed data is all processed
 
847
    * or the stream marked as finished.
 
848
    */
 
849
   while (png_ptr->zstream.avail_in > 0 &&
 
850
          !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
764
851
   {
765
 
      ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
766
 
      if (ret != Z_OK)
767
 
      {
768
 
         if (ret == Z_STREAM_END)
 
852
      int ret;
 
853
 
 
854
      /* We have data for zlib, but we must check that zlib
 
855
       * has somewhere to put the results.  It doesn't matter
 
856
       * if we don't expect any results -- it may be the input
 
857
       * data is just the LZ end code.
 
858
       */
 
859
      if (!(png_ptr->zstream.avail_out > 0))
 
860
      {
 
861
         png_ptr->zstream.avail_out =
 
862
             (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
 
863
             png_ptr->iwidth) + 1;
 
864
         png_ptr->zstream.next_out = png_ptr->row_buf;
 
865
      }
 
866
 
 
867
      /* Using Z_SYNC_FLUSH here means that an unterminated
 
868
       * LZ stream can still be handled (a stream with a missing
 
869
       * end code), otherwise (Z_NO_FLUSH) a future zlib
 
870
       * implementation might defer output and, therefore,
 
871
       * change the current behavior.  (See comments in inflate.c
 
872
       * for why this doesn't happen at present with zlib 1.2.5.)
 
873
       */
 
874
      ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH);
 
875
 
 
876
      /* Check for any failure before proceeding. */
 
877
      if (ret != Z_OK && ret != Z_STREAM_END)
 
878
      {
 
879
         /* Terminate the decompression. */
 
880
         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
 
881
 
 
882
         /* This may be a truncated stream (missing or
 
883
          * damaged end code).  Treat that as a warning.
 
884
          */
 
885
         if (png_ptr->row_number >= png_ptr->num_rows ||
 
886
             png_ptr->pass > 6)
 
887
            png_warning(png_ptr, "Truncated compressed data in IDAT");
 
888
         else
 
889
            png_error(png_ptr, "Decompression error in IDAT");
 
890
 
 
891
         /* Skip the check on unprocessed input */
 
892
         return;
 
893
      }
 
894
 
 
895
      /* Did inflate output any data? */
 
896
      if (png_ptr->zstream.next_out != png_ptr->row_buf)
 
897
      {
 
898
         /* Is this unexpected data after the last row?
 
899
          * If it is, artificially terminate the LZ output
 
900
          * here.
 
901
          */
 
902
         if (png_ptr->row_number >= png_ptr->num_rows ||
 
903
             png_ptr->pass > 6)
769
904
         {
770
 
            if (png_ptr->zstream.avail_in)
771
 
               png_error(png_ptr, "Extra compressed data");
772
 
            if (!(png_ptr->zstream.avail_out))
773
 
            {
774
 
               png_push_process_row(png_ptr);
775
 
            }
776
 
 
777
 
            png_ptr->mode |= PNG_AFTER_IDAT;
 
905
            /* Extra data. */
 
906
            png_warning(png_ptr, "Extra compressed data in IDAT");
778
907
            png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
779
 
            break;
780
 
         }
781
 
         else if (ret == Z_BUF_ERROR)
782
 
            break;
783
 
         else
784
 
            png_error(png_ptr, "Decompression Error");
785
 
      }
786
 
      if (!(png_ptr->zstream.avail_out))
787
 
      {
788
 
         if ((
789
 
#if defined(PNG_READ_INTERLACING_SUPPORTED)
790
 
             png_ptr->interlaced && png_ptr->pass > 6) ||
791
 
             (!png_ptr->interlaced &&
792
 
#endif
793
 
             png_ptr->row_number == png_ptr->num_rows))
794
 
         {
795
 
           if (png_ptr->zstream.avail_in)
796
 
             png_warning(png_ptr, "Too much data in IDAT chunks");
797
 
           png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
798
 
           break;
799
 
         }
800
 
         png_push_process_row(png_ptr);
801
 
         png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
802
 
         png_ptr->zstream.next_out = png_ptr->row_buf;
803
 
      }
804
 
      else
805
 
         break;
 
908
            /* Do no more processing; skip the unprocessed
 
909
             * input check below.
 
910
             */
 
911
            return;
 
912
         }
 
913
 
 
914
         /* Do we have a complete row? */
 
915
         if (png_ptr->zstream.avail_out == 0)
 
916
            png_push_process_row(png_ptr);
 
917
      }
 
918
 
 
919
      /* And check for the end of the stream. */
 
920
      if (ret == Z_STREAM_END)
 
921
         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
806
922
   }
 
923
 
 
924
   /* All the data should have been processed, if anything
 
925
    * is left at this point we have bytes of IDAT data
 
926
    * after the zlib end code.
 
927
    */
 
928
   if (png_ptr->zstream.avail_in > 0)
 
929
      png_warning(png_ptr, "Extra compression data");
807
930
}
808
931
 
809
932
void /* PRIVATE */
819
942
       png_ptr->row_info.width);
820
943
 
821
944
   png_read_filter_row(png_ptr, &(png_ptr->row_info),
822
 
      png_ptr->row_buf + 1, png_ptr->prev_row + 1,
823
 
      (int)(png_ptr->row_buf[0]));
 
945
       png_ptr->row_buf + 1, png_ptr->prev_row + 1,
 
946
       (int)(png_ptr->row_buf[0]));
824
947
 
825
948
   png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
826
949
      png_ptr->rowbytes + 1);
828
951
   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
829
952
      png_do_read_transformations(png_ptr);
830
953
 
831
 
#if defined(PNG_READ_INTERLACING_SUPPORTED)
832
 
   /* blow up interlaced rows to full size */
 
954
#ifdef PNG_READ_INTERLACING_SUPPORTED
 
955
   /* Blow up interlaced rows to full size */
833
956
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
834
957
   {
835
958
      if (png_ptr->pass < 6)
836
959
/*       old interface (pre-1.0.9):
837
960
         png_do_read_interlace(&(png_ptr->row_info),
838
 
            png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
 
961
             png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
839
962
 */
840
963
         png_do_read_interlace(png_ptr);
841
964
 
847
970
            for (i = 0; i < 8 && png_ptr->pass == 0; i++)
848
971
            {
849
972
               png_push_have_row(png_ptr, png_ptr->row_buf + 1);
850
 
               png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
 
973
               png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */
851
974
            }
852
 
            if (png_ptr->pass == 2) /* pass 1 might be empty */
 
975
 
 
976
            if (png_ptr->pass == 2) /* Pass 1 might be empty */
853
977
            {
854
978
               for (i = 0; i < 4 && png_ptr->pass == 2; i++)
855
979
               {
857
981
                  png_read_push_finish_row(png_ptr);
858
982
               }
859
983
            }
 
984
 
860
985
            if (png_ptr->pass == 4 && png_ptr->height <= 4)
861
986
            {
862
987
               for (i = 0; i < 2 && png_ptr->pass == 4; i++)
865
990
                  png_read_push_finish_row(png_ptr);
866
991
               }
867
992
            }
 
993
 
868
994
            if (png_ptr->pass == 6 && png_ptr->height <= 4)
869
995
            {
870
 
                png_push_have_row(png_ptr, png_bytep_NULL);
 
996
                  png_push_have_row(png_ptr, png_bytep_NULL);
871
997
                png_read_push_finish_row(png_ptr);
872
998
            }
 
999
 
873
1000
            break;
874
1001
         }
 
1002
 
875
1003
         case 1:
876
1004
         {
877
1005
            int i;
880
1008
               png_push_have_row(png_ptr, png_ptr->row_buf + 1);
881
1009
               png_read_push_finish_row(png_ptr);
882
1010
            }
883
 
            if (png_ptr->pass == 2) /* skip top 4 generated rows */
 
1011
 
 
1012
            if (png_ptr->pass == 2) /* Skip top 4 generated rows */
884
1013
            {
885
1014
               for (i = 0; i < 4 && png_ptr->pass == 2; i++)
886
1015
               {
888
1017
                  png_read_push_finish_row(png_ptr);
889
1018
               }
890
1019
            }
 
1020
 
891
1021
            break;
892
1022
         }
 
1023
 
893
1024
         case 2:
894
1025
         {
895
1026
            int i;
 
1027
 
896
1028
            for (i = 0; i < 4 && png_ptr->pass == 2; i++)
897
1029
            {
898
1030
               png_push_have_row(png_ptr, png_ptr->row_buf + 1);
899
1031
               png_read_push_finish_row(png_ptr);
900
1032
            }
 
1033
 
901
1034
            for (i = 0; i < 4 && png_ptr->pass == 2; i++)
902
1035
            {
903
 
               png_push_have_row(png_ptr, png_bytep_NULL);
 
1036
                  png_push_have_row(png_ptr, png_bytep_NULL);
904
1037
               png_read_push_finish_row(png_ptr);
905
1038
            }
906
 
            if (png_ptr->pass == 4) /* pass 3 might be empty */
 
1039
 
 
1040
            if (png_ptr->pass == 4) /* Pass 3 might be empty */
907
1041
            {
908
1042
               for (i = 0; i < 2 && png_ptr->pass == 4; i++)
909
1043
               {
911
1045
                  png_read_push_finish_row(png_ptr);
912
1046
               }
913
1047
            }
 
1048
 
914
1049
            break;
915
1050
         }
 
1051
 
916
1052
         case 3:
917
1053
         {
918
1054
            int i;
 
1055
 
919
1056
            for (i = 0; i < 4 && png_ptr->pass == 3; i++)
920
1057
            {
921
1058
               png_push_have_row(png_ptr, png_ptr->row_buf + 1);
922
1059
               png_read_push_finish_row(png_ptr);
923
1060
            }
924
 
            if (png_ptr->pass == 4) /* skip top two generated rows */
 
1061
 
 
1062
            if (png_ptr->pass == 4) /* Skip top two generated rows */
925
1063
            {
926
1064
               for (i = 0; i < 2 && png_ptr->pass == 4; i++)
927
1065
               {
929
1067
                  png_read_push_finish_row(png_ptr);
930
1068
               }
931
1069
            }
 
1070
 
932
1071
            break;
933
1072
         }
 
1073
 
934
1074
         case 4:
935
1075
         {
936
1076
            int i;
 
1077
 
937
1078
            for (i = 0; i < 2 && png_ptr->pass == 4; i++)
938
1079
            {
939
1080
               png_push_have_row(png_ptr, png_ptr->row_buf + 1);
940
1081
               png_read_push_finish_row(png_ptr);
941
1082
            }
 
1083
 
942
1084
            for (i = 0; i < 2 && png_ptr->pass == 4; i++)
943
1085
            {
944
 
               png_push_have_row(png_ptr, png_bytep_NULL);
 
1086
                  png_push_have_row(png_ptr, png_bytep_NULL);
945
1087
               png_read_push_finish_row(png_ptr);
946
1088
            }
947
 
            if (png_ptr->pass == 6) /* pass 5 might be empty */
 
1089
 
 
1090
            if (png_ptr->pass == 6) /* Pass 5 might be empty */
948
1091
            {
949
 
               png_push_have_row(png_ptr, png_bytep_NULL);
 
1092
                  png_push_have_row(png_ptr, png_bytep_NULL);
950
1093
               png_read_push_finish_row(png_ptr);
951
1094
            }
 
1095
 
952
1096
            break;
953
1097
         }
 
1098
 
954
1099
         case 5:
955
1100
         {
956
1101
            int i;
 
1102
 
957
1103
            for (i = 0; i < 2 && png_ptr->pass == 5; i++)
958
1104
            {
959
1105
               png_push_have_row(png_ptr, png_ptr->row_buf + 1);
960
1106
               png_read_push_finish_row(png_ptr);
961
1107
            }
962
 
            if (png_ptr->pass == 6) /* skip top generated row */
 
1108
 
 
1109
            if (png_ptr->pass == 6) /* Skip top generated row */
963
1110
            {
964
 
               png_push_have_row(png_ptr, png_bytep_NULL);
 
1111
                  png_push_have_row(png_ptr, png_bytep_NULL);
965
1112
               png_read_push_finish_row(png_ptr);
966
1113
            }
 
1114
 
967
1115
            break;
968
1116
         }
969
1117
         case 6:
970
1118
         {
971
1119
            png_push_have_row(png_ptr, png_ptr->row_buf + 1);
972
1120
            png_read_push_finish_row(png_ptr);
 
1121
 
973
1122
            if (png_ptr->pass != 6)
974
1123
               break;
975
 
            png_push_have_row(png_ptr, png_bytep_NULL);
 
1124
 
 
1125
                  png_push_have_row(png_ptr, png_bytep_NULL);
976
1126
            png_read_push_finish_row(png_ptr);
977
1127
         }
978
1128
      }
989
1139
png_read_push_finish_row(png_structp png_ptr)
990
1140
{
991
1141
#ifdef PNG_USE_LOCAL_ARRAYS
992
 
   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
 
1142
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
993
1143
 
994
 
   /* start of interlace block */
 
1144
   /* Start of interlace block */
995
1145
   PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
996
1146
 
997
 
   /* offset to next interlace block */
 
1147
   /* Offset to next interlace block */
998
1148
   PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
999
1149
 
1000
 
   /* start of interlace block in the y direction */
 
1150
   /* Start of interlace block in the y direction */
1001
1151
   PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1002
1152
 
1003
 
   /* offset to next interlace block in the y direction */
 
1153
   /* Offset to next interlace block in the y direction */
1004
1154
   PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1005
1155
 
1006
1156
   /* Height of interlace block.  This is not currently used - if you need
1013
1163
   if (png_ptr->row_number < png_ptr->num_rows)
1014
1164
      return;
1015
1165
 
 
1166
#ifdef PNG_READ_INTERLACING_SUPPORTED
1016
1167
   if (png_ptr->interlaced)
1017
1168
   {
1018
1169
      png_ptr->row_number = 0;
1028
1179
 
1029
1180
         if (png_ptr->pass > 7)
1030
1181
            png_ptr->pass--;
 
1182
 
1031
1183
         if (png_ptr->pass >= 7)
1032
1184
            break;
1033
1185
 
1036
1188
            png_pass_start[png_ptr->pass]) /
1037
1189
            png_pass_inc[png_ptr->pass];
1038
1190
 
1039
 
         png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
1040
 
            png_ptr->iwidth) + 1;
1041
 
 
1042
1191
         if (png_ptr->transformations & PNG_INTERLACE)
1043
1192
            break;
1044
1193
 
1049
1198
 
1050
1199
      } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
1051
1200
   }
 
1201
#endif /* PNG_READ_INTERLACING_SUPPORTED */
1052
1202
}
1053
1203
 
1054
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
1204
#ifdef PNG_READ_tEXt_SUPPORTED
1055
1205
void /* PRIVATE */
1056
1206
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1057
1207
   length)
1059
1209
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1060
1210
      {
1061
1211
         png_error(png_ptr, "Out of place tEXt");
1062
 
         info_ptr = info_ptr; /* to quiet some compiler warnings */
 
1212
         info_ptr = info_ptr; /* To quiet some compiler warnings */
1063
1213
      }
1064
1214
 
1065
1215
#ifdef PNG_MAX_MALLOC_64K
1091
1241
 
1092
1242
      if (png_ptr->buffer_size < png_ptr->current_text_left)
1093
1243
         text_size = png_ptr->buffer_size;
 
1244
 
1094
1245
      else
1095
1246
         text_size = png_ptr->current_text_left;
 
1247
 
1096
1248
      png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1097
1249
      png_ptr->current_text_left -= text_size;
1098
1250
      png_ptr->current_text_ptr += text_size;
1112
1264
 
1113
1265
      png_push_crc_finish(png_ptr);
1114
1266
 
1115
 
#if defined(PNG_MAX_MALLOC_64K)
 
1267
#ifdef PNG_MAX_MALLOC_64K
1116
1268
      if (png_ptr->skip_length)
1117
1269
         return;
1118
1270
#endif
1120
1272
      key = png_ptr->current_text;
1121
1273
 
1122
1274
      for (text = key; *text; text++)
1123
 
         /* empty loop */ ;
 
1275
         /* Empty loop */ ;
1124
1276
 
1125
1277
      if (text < key + png_ptr->current_text_size)
1126
1278
         text++;
1147
1299
}
1148
1300
#endif
1149
1301
 
1150
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
1302
#ifdef PNG_READ_zTXt_SUPPORTED
1151
1303
void /* PRIVATE */
1152
1304
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1153
1305
   length)
1155
1307
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1156
1308
      {
1157
1309
         png_error(png_ptr, "Out of place zTXt");
1158
 
         info_ptr = info_ptr; /* to quiet some compiler warnings */
 
1310
         info_ptr = info_ptr; /* To quiet some compiler warnings */
1159
1311
      }
1160
1312
 
1161
1313
#ifdef PNG_MAX_MALLOC_64K
1189
1341
 
1190
1342
      if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
1191
1343
         text_size = png_ptr->buffer_size;
 
1344
 
1192
1345
      else
1193
1346
         text_size = png_ptr->current_text_left;
 
1347
 
1194
1348
      png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1195
1349
      png_ptr->current_text_left -= text_size;
1196
1350
      png_ptr->current_text_ptr += text_size;
1214
1368
      key = png_ptr->current_text;
1215
1369
 
1216
1370
      for (text = key; *text; text++)
1217
 
         /* empty loop */ ;
 
1371
         /* Empty loop */ ;
1218
1372
 
1219
1373
      /* zTXt can't have zero text */
1220
1374
      if (text >= key + png_ptr->current_text_size)
1226
1380
 
1227
1381
      text++;
1228
1382
 
1229
 
      if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
 
1383
      if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */
1230
1384
      {
1231
1385
         png_ptr->current_text = NULL;
1232
1386
         png_free(png_ptr, key);
1265
1419
               text = (png_charp)png_malloc(png_ptr,
1266
1420
                     (png_uint_32)(png_ptr->zbuf_size
1267
1421
                     - png_ptr->zstream.avail_out + key_size + 1));
 
1422
 
1268
1423
               png_memcpy(text + key_size, png_ptr->zbuf,
1269
1424
                  png_ptr->zbuf_size - png_ptr->zstream.avail_out);
 
1425
 
1270
1426
               png_memcpy(text, key, key_size);
 
1427
 
1271
1428
               text_size = key_size + png_ptr->zbuf_size -
1272
1429
                  png_ptr->zstream.avail_out;
 
1430
 
1273
1431
               *(text + text_size) = '\0';
1274
1432
            }
1275
1433
            else
1280
1438
               text = (png_charp)png_malloc(png_ptr, text_size +
1281
1439
                  (png_uint_32)(png_ptr->zbuf_size 
1282
1440
                  - png_ptr->zstream.avail_out + 1));
 
1441
 
1283
1442
               png_memcpy(text, tmp, text_size);
1284
1443
               png_free(png_ptr, tmp);
 
1444
 
1285
1445
               png_memcpy(text + text_size, png_ptr->zbuf,
1286
1446
                  png_ptr->zbuf_size - png_ptr->zstream.avail_out);
 
1447
 
1287
1448
               text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
1288
1449
               *(text + text_size) = '\0';
1289
1450
            }
1339
1500
}
1340
1501
#endif
1341
1502
 
1342
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
1503
#ifdef PNG_READ_iTXt_SUPPORTED
1343
1504
void /* PRIVATE */
1344
1505
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1345
1506
   length)
1347
1508
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1348
1509
      {
1349
1510
         png_error(png_ptr, "Out of place iTXt");
1350
 
         info_ptr = info_ptr; /* to quiet some compiler warnings */
 
1511
         info_ptr = info_ptr; /* To quiet some compiler warnings */
1351
1512
      }
1352
1513
 
1353
1514
#ifdef PNG_MAX_MALLOC_64K
1380
1541
 
1381
1542
      if (png_ptr->buffer_size < png_ptr->current_text_left)
1382
1543
         text_size = png_ptr->buffer_size;
 
1544
 
1383
1545
      else
1384
1546
         text_size = png_ptr->current_text_left;
 
1547
 
1385
1548
      png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1386
1549
      png_ptr->current_text_left -= text_size;
1387
1550
      png_ptr->current_text_ptr += text_size;
1404
1567
 
1405
1568
      png_push_crc_finish(png_ptr);
1406
1569
 
1407
 
#if defined(PNG_MAX_MALLOC_64K)
 
1570
#ifdef PNG_MAX_MALLOC_64K
1408
1571
      if (png_ptr->skip_length)
1409
1572
         return;
1410
1573
#endif
1412
1575
      key = png_ptr->current_text;
1413
1576
 
1414
1577
      for (lang = key; *lang; lang++)
1415
 
         /* empty loop */ ;
 
1578
         /* Empty loop */ ;
1416
1579
 
1417
1580
      if (lang < key + png_ptr->current_text_size - 3)
1418
1581
         lang++;
1419
1582
 
1420
1583
      comp_flag = *lang++;
1421
 
      lang++;     /* skip comp_type, always zero */
 
1584
      lang++;     /* Skip comp_type, always zero */
1422
1585
 
1423
1586
      for (lang_key = lang; *lang_key; lang_key++)
1424
 
         /* empty loop */ ;
1425
 
      lang_key++;        /* skip NUL separator */
 
1587
         /* Empty loop */ ;
 
1588
 
 
1589
      lang_key++;        /* Skip NUL separator */
1426
1590
 
1427
1591
      text=lang_key;
 
1592
 
1428
1593
      if (lang_key < key + png_ptr->current_text_size - 1)
1429
1594
      {
1430
1595
        for (; *text; text++)
1431
 
           /* empty loop */ ;
 
1596
           /* Empty loop */ ;
1432
1597
      }
1433
1598
 
1434
1599
      if (text < key + png_ptr->current_text_size)
1436
1601
 
1437
1602
      text_ptr = (png_textp)png_malloc(png_ptr,
1438
1603
         (png_uint_32)png_sizeof(png_text));
 
1604
 
1439
1605
      text_ptr->compression = comp_flag + 2;
1440
1606
      text_ptr->key = key;
1441
1607
      text_ptr->lang = lang;
1450
1616
 
1451
1617
      png_free(png_ptr, text_ptr);
1452
1618
      if (ret)
1453
 
        png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
 
1619
         png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
1454
1620
   }
1455
1621
}
1456
1622
#endif
1467
1633
 
1468
1634
   if (!(png_ptr->chunk_name[0] & 0x20))
1469
1635
   {
1470
 
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
 
1636
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1471
1637
      if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1472
1638
         PNG_HANDLE_CHUNK_ALWAYS
1473
 
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
 
1639
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1474
1640
         && png_ptr->read_user_chunk_fn == NULL
1475
1641
#endif
1476
1642
         )
1477
1643
#endif
1478
1644
         png_chunk_error(png_ptr, "unknown critical chunk");
1479
1645
 
1480
 
      info_ptr = info_ptr; /* to quiet some compiler warnings */
 
1646
      info_ptr = info_ptr; /* To quiet some compiler warnings */
1481
1647
   }
1482
1648
 
1483
 
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
 
1649
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1484
1650
   if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
1485
1651
   {
1486
1652
#ifdef PNG_MAX_MALLOC_64K
1498
1664
        = '\0';
1499
1665
 
1500
1666
      png_ptr->unknown_chunk.size = (png_size_t)length;
 
1667
 
1501
1668
      if (length == 0)
1502
1669
         png_ptr->unknown_chunk.data = NULL;
 
1670
 
1503
1671
      else
1504
1672
      {
1505
1673
         png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
1506
 
       (png_uint_32)length);
 
1674
            (png_uint_32)length);
1507
1675
         png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
1508
1676
      }
1509
 
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
 
1677
 
 
1678
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1510
1679
      if (png_ptr->read_user_chunk_fn != NULL)
1511
1680
      {
1512
 
         /* callback to user unknown chunk handler */
 
1681
         /* Callback to user unknown chunk handler */
1513
1682
         int ret;
1514
1683
         ret = (*(png_ptr->read_user_chunk_fn))
1515
1684
           (png_ptr, &png_ptr->unknown_chunk);
 
1685
 
1516
1686
         if (ret < 0)
1517
1687
            png_chunk_error(png_ptr, "error in user chunk");
 
1688
 
1518
1689
         if (ret == 0)
1519
1690
         {
1520
1691
            if (!(png_ptr->chunk_name[0] & 0x20))
1525
1696
               &png_ptr->unknown_chunk, 1);
1526
1697
         }
1527
1698
      }
 
1699
 
1528
1700
      else
1529
1701
#endif
1530
1702
        png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
1531
1703
      png_free(png_ptr, png_ptr->unknown_chunk.data);
1532
1704
      png_ptr->unknown_chunk.data = NULL;
1533
1705
   }
 
1706
 
1534
1707
   else
1535
1708
#endif
1536
1709
      skip=length;
1567
1740
   PNG_CONST int FARDATA png_pass_dsp_mask[7] =
1568
1741
      {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
1569
1742
#endif
1570
 
   if (png_ptr == NULL) return;
 
1743
 
 
1744
   if (png_ptr == NULL)
 
1745
      return;
 
1746
 
1571
1747
   if (new_row != NULL)    /* new_row must == png_ptr->row_buf here. */
1572
1748
      png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
1573
1749
}
1577
1753
   png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
1578
1754
   png_progressive_end_ptr end_fn)
1579
1755
{
1580
 
   if (png_ptr == NULL) return;
 
1756
   if (png_ptr == NULL)
 
1757
      return;
 
1758
 
1581
1759
   png_ptr->info_fn = info_fn;
1582
1760
   png_ptr->row_fn = row_fn;
1583
1761
   png_ptr->end_fn = end_fn;
1588
1766
png_voidp PNGAPI
1589
1767
png_get_progressive_ptr(png_structp png_ptr)
1590
1768
{
1591
 
   if (png_ptr == NULL) return (NULL);
 
1769
   if (png_ptr == NULL)
 
1770
      return (NULL);
 
1771
 
1592
1772
   return png_ptr->io_ptr;
1593
1773
}
1594
1774
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */