~ubuntu-branches/ubuntu/maverick/libpng/maverick-security

« back to all changes in this revision

Viewing changes to pngset.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2009-12-04 11:23:50 UTC
  • mfrom: (1.1.10 upstream) (15.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091204112350-ln22xyakgn9bh39k
Tags: 1.2.41-1
* New upstream release
* Debian source format is 3.0 (quilt)
* Update debian/watch
* Add 02-export-png_set_strip_error_numbers.patch
  Define PNG_ERROR_NUMBERS_SUPPORTED
  Upstream doesn't define PNG_ERROR_NUMBERS_SUPPORTED since 1.2.41. As
  a consecuence, the symbol png_set_strip_error_numbe@@PNG12_0 wasn't
  exported.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/* pngset.c - storage of image information into info struct
3
3
 *
4
 
 * Last changed in libpng 1.2.40 [September 10, 2009]
 
4
 * Last changed in libpng 1.2.41 [December 3, 2009]
5
5
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
6
6
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7
7
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
17
17
 */
18
18
 
19
19
#define PNG_INTERNAL
 
20
#define PNG_NO_PEDANTIC_WARNINGS
20
21
#include "png.h"
21
22
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22
23
 
23
 
#if defined(PNG_bKGD_SUPPORTED)
 
24
#ifdef PNG_bKGD_SUPPORTED
24
25
void PNGAPI
25
26
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
26
27
{
34
35
}
35
36
#endif
36
37
 
37
 
#if defined(PNG_cHRM_SUPPORTED)
 
38
#ifdef PNG_cHRM_SUPPORTED
38
39
#ifdef PNG_FLOATING_POINT_SUPPORTED
39
40
void PNGAPI
40
41
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
80
81
   if (png_ptr == NULL || info_ptr == NULL)
81
82
      return;
82
83
 
83
 
#if !defined(PNG_NO_CHECK_cHRM)
 
84
#ifdef PNG_CHECK_cHRM_SUPPORTED
84
85
   if (png_check_cHRM_fixed(png_ptr,
85
86
      white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
86
87
#endif
109
110
#endif /* PNG_FIXED_POINT_SUPPORTED */
110
111
#endif /* PNG_cHRM_SUPPORTED */
111
112
 
112
 
#if defined(PNG_gAMA_SUPPORTED)
 
113
#ifdef PNG_gAMA_SUPPORTED
113
114
#ifdef PNG_FLOATING_POINT_SUPPORTED
114
115
void PNGAPI
115
116
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
176
177
}
177
178
#endif
178
179
 
179
 
#if defined(PNG_hIST_SUPPORTED)
 
180
#ifdef PNG_hIST_SUPPORTED
180
181
void PNGAPI
181
182
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
182
183
{
233
234
   if (png_ptr == NULL || info_ptr == NULL)
234
235
      return;
235
236
 
236
 
   /* Check for width and height valid values */
237
 
   if (width == 0 || height == 0)
238
 
      png_error(png_ptr, "Image width or height is zero in IHDR");
239
 
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
240
 
   if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
241
 
      png_error(png_ptr, "image size exceeds user limits in IHDR");
242
 
#else
243
 
   if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
244
 
      png_error(png_ptr, "image size exceeds user limits in IHDR");
245
 
#endif
246
 
   if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
247
 
      png_error(png_ptr, "Invalid image size in IHDR");
248
 
   if ( width > (PNG_UINT_32_MAX
249
 
                 >> 3)      /* 8-byte RGBA pixels */
250
 
                 - 64       /* bigrowbuf hack */
251
 
                 - 1        /* filter byte */
252
 
                 - 7*8      /* rounding of width to multiple of 8 pixels */
253
 
                 - 8)       /* extra max_pixel_depth pad */
254
 
      png_warning(png_ptr, "Width is too large for libpng to process pixels");
255
 
 
256
 
   /* Check other values */
257
 
   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
258
 
       bit_depth != 8 && bit_depth != 16)
259
 
      png_error(png_ptr, "Invalid bit depth in IHDR");
260
 
 
261
 
   if (color_type < 0 || color_type == 1 ||
262
 
       color_type == 5 || color_type > 6)
263
 
      png_error(png_ptr, "Invalid color type in IHDR");
264
 
 
265
 
   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
266
 
       ((color_type == PNG_COLOR_TYPE_RGB ||
267
 
         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
268
 
         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
269
 
      png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
270
 
 
271
 
   if (interlace_type >= PNG_INTERLACE_LAST)
272
 
      png_error(png_ptr, "Unknown interlace method in IHDR");
273
 
 
274
 
   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
275
 
      png_error(png_ptr, "Unknown compression method in IHDR");
276
 
 
277
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
278
 
   /* Accept filter_method 64 (intrapixel differencing) only if
279
 
    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
280
 
    * 2. Libpng did not read a PNG signature (this filter_method is only
281
 
    *    used in PNG datastreams that are embedded in MNG datastreams) and
282
 
    * 3. The application called png_permit_mng_features with a mask that
283
 
    *    included PNG_FLAG_MNG_FILTER_64 and
284
 
    * 4. The filter_method is 64 and
285
 
    * 5. The color_type is RGB or RGBA
286
 
    */
287
 
   if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
288
 
      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
289
 
   if (filter_type != PNG_FILTER_TYPE_BASE)
290
 
   {
291
 
     if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
292
 
         (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
293
 
         ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
294
 
         (color_type == PNG_COLOR_TYPE_RGB ||
295
 
         color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
296
 
        png_error(png_ptr, "Unknown filter method in IHDR");
297
 
     if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
298
 
        png_warning(png_ptr, "Invalid filter method in IHDR");
299
 
   }
300
 
#else
301
 
   if (filter_type != PNG_FILTER_TYPE_BASE)
302
 
      png_error(png_ptr, "Unknown filter method in IHDR");
303
 
#endif
304
 
 
305
237
   info_ptr->width = width;
306
238
   info_ptr->height = height;
307
239
   info_ptr->bit_depth = (png_byte)bit_depth;
308
 
   info_ptr->color_type =(png_byte) color_type;
 
240
   info_ptr->color_type = (png_byte)color_type;
309
241
   info_ptr->compression_type = (png_byte)compression_type;
310
242
   info_ptr->filter_type = (png_byte)filter_type;
311
243
   info_ptr->interlace_type = (png_byte)interlace_type;
 
244
 
 
245
   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
 
246
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
 
247
       info_ptr->compression_type, info_ptr->filter_type);
 
248
 
312
249
   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
313
250
      info_ptr->channels = 1;
314
251
   else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
331
268
      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
332
269
}
333
270
 
334
 
#if defined(PNG_oFFs_SUPPORTED)
 
271
#ifdef PNG_oFFs_SUPPORTED
335
272
void PNGAPI
336
273
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
337
274
   png_int_32 offset_x, png_int_32 offset_y, int unit_type)
348
285
}
349
286
#endif
350
287
 
351
 
#if defined(PNG_pCAL_SUPPORTED)
 
288
#ifdef PNG_pCAL_SUPPORTED
352
289
void PNGAPI
353
290
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
354
291
   png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
487
424
#endif
488
425
#endif
489
426
 
490
 
#if defined(PNG_pHYs_SUPPORTED)
 
427
#ifdef PNG_pHYs_SUPPORTED
491
428
void PNGAPI
492
429
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
493
430
   png_uint_32 res_x, png_uint_32 res_y, int unit_type)
538
475
    * of num_palette entries, in case of an invalid PNG file that has
539
476
    * too-large sample values.
540
477
    */
541
 
   png_ptr->palette = (png_colorp)png_malloc(png_ptr,
 
478
   png_ptr->palette = (png_colorp)png_calloc(png_ptr,
542
479
      PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
543
 
   png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
544
 
      png_sizeof(png_color));
545
480
   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
546
481
   info_ptr->palette = png_ptr->palette;
547
482
   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
555
490
   info_ptr->valid |= PNG_INFO_PLTE;
556
491
}
557
492
 
558
 
#if defined(PNG_sBIT_SUPPORTED)
 
493
#ifdef PNG_sBIT_SUPPORTED
559
494
void PNGAPI
560
495
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
561
496
   png_color_8p sig_bit)
570
505
}
571
506
#endif
572
507
 
573
 
#if defined(PNG_sRGB_SUPPORTED)
 
508
#ifdef PNG_sRGB_SUPPORTED
574
509
void PNGAPI
575
510
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
576
511
{
587
522
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
588
523
   int intent)
589
524
{
590
 
#if defined(PNG_gAMA_SUPPORTED)
 
525
#ifdef PNG_gAMA_SUPPORTED
591
526
#ifdef PNG_FLOATING_POINT_SUPPORTED
592
527
   float file_gamma;
593
528
#endif
595
530
   png_fixed_point int_file_gamma;
596
531
#endif
597
532
#endif
598
 
#if defined(PNG_cHRM_SUPPORTED)
 
533
#ifdef PNG_cHRM_SUPPORTED
599
534
#ifdef PNG_FLOATING_POINT_SUPPORTED
600
535
   float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
601
536
#endif
609
544
 
610
545
   png_set_sRGB(png_ptr, info_ptr, intent);
611
546
 
612
 
#if defined(PNG_gAMA_SUPPORTED)
 
547
#ifdef PNG_gAMA_SUPPORTED
613
548
#ifdef PNG_FLOATING_POINT_SUPPORTED
614
549
   file_gamma = (float).45455;
615
550
   png_set_gAMA(png_ptr, info_ptr, file_gamma);
620
555
#endif
621
556
#endif
622
557
 
623
 
#if defined(PNG_cHRM_SUPPORTED)
 
558
#ifdef PNG_cHRM_SUPPORTED
624
559
   int_white_x = 31270L;
625
560
   int_white_y = 32900L;
626
561
   int_red_x   = 64000L;
641
576
   blue_y  = (float).06;
642
577
#endif
643
578
 
644
 
#if !defined(PNG_NO_CHECK_cHRM)
645
 
   if (png_check_cHRM_fixed(png_ptr,
 
579
#ifdef PNG_FIXED_POINT_SUPPORTED
 
580
   png_set_cHRM_fixed(png_ptr, info_ptr,
646
581
       int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
647
 
       int_green_y, int_blue_x, int_blue_y))
648
 
#endif
649
 
   {
650
 
#ifdef PNG_FIXED_POINT_SUPPORTED
651
 
      png_set_cHRM_fixed(png_ptr, info_ptr,
652
 
          int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
653
 
          int_green_y, int_blue_x, int_blue_y);
 
582
       int_green_y, int_blue_x, int_blue_y);
654
583
#endif
655
584
#ifdef PNG_FLOATING_POINT_SUPPORTED
656
 
      png_set_cHRM(png_ptr, info_ptr,
657
 
          white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
 
585
   png_set_cHRM(png_ptr, info_ptr,
 
586
       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
658
587
#endif
659
 
   }
660
588
#endif /* cHRM */
661
589
}
662
590
#endif /* sRGB */
663
591
 
664
592
 
665
 
#if defined(PNG_iCCP_SUPPORTED)
 
593
#ifdef PNG_iCCP_SUPPORTED
666
594
void PNGAPI
667
595
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
668
596
             png_charp name, int compression_type,
710
638
}
711
639
#endif
712
640
 
713
 
#if defined(PNG_TEXT_SUPPORTED)
 
641
#ifdef PNG_TEXT_SUPPORTED
714
642
void PNGAPI
715
643
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
716
644
             int num_text)
789
717
         lang_len = 0;
790
718
         lang_key_len = 0;
791
719
      }
 
720
 
792
721
      else
793
722
#ifdef PNG_iTXt_SUPPORTED
794
723
      {
795
724
         /* Set iTXt data */
 
725
 
796
726
         if (text_ptr[i].lang != NULL)
797
727
            lang_len = png_strlen(text_ptr[i].lang);
798
728
         else
802
732
         else
803
733
            lang_key_len = 0;
804
734
      }
805
 
#else
 
735
#else /* PNG_iTXt_SUPPORTED */
806
736
      {
807
737
         png_warning(png_ptr, "iTXt chunk not supported.");
808
738
         continue;
819
749
#endif
820
750
            textp->compression = PNG_TEXT_COMPRESSION_NONE;
821
751
      }
 
752
 
822
753
      else
823
754
      {
824
755
         text_length = png_strlen(text_ptr[i].text);
870
801
      }
871
802
      else
872
803
#endif
 
804
 
873
805
      {
874
806
         textp->text_length = text_length;
875
807
#ifdef PNG_iTXt_SUPPORTED
883
815
}
884
816
#endif
885
817
 
886
 
#if defined(PNG_tIME_SUPPORTED)
 
818
#ifdef PNG_tIME_SUPPORTED
887
819
void PNGAPI
888
820
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
889
821
{
898
830
}
899
831
#endif
900
832
 
901
 
#if defined(PNG_tRNS_SUPPORTED)
 
833
#ifdef PNG_tRNS_SUPPORTED
902
834
void PNGAPI
903
835
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
904
836
   png_bytep trans, int num_trans, png_color_16p trans_values)
910
842
 
911
843
   if (trans != NULL)
912
844
   {
913
 
       /*
914
 
        * It may not actually be necessary to set png_ptr->trans here;
 
845
       /* It may not actually be necessary to set png_ptr->trans here;
915
846
        * we do it for backward compatibility with the way the png_handle_tRNS
916
847
        * function used to do the allocation.
917
848
        */
957
888
}
958
889
#endif
959
890
 
960
 
#if defined(PNG_sPLT_SUPPORTED)
 
891
#ifdef PNG_sPLT_SUPPORTED
961
892
void PNGAPI
962
893
png_set_sPLT(png_structp png_ptr,
963
894
             png_infop info_ptr, png_sPLT_tp entries, int nentries)
1121
1052
#endif
1122
1053
#endif
1123
1054
 
1124
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
1055
#ifdef PNG_MNG_FEATURES_SUPPORTED
1125
1056
png_uint_32 PNGAPI
1126
1057
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1127
1058
{
1135
1066
}
1136
1067
#endif
1137
1068
 
1138
 
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 
1069
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
1139
1070
void PNGAPI
1140
1071
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1141
1072
   chunk_list, int num_chunks)
1182
1113
}
1183
1114
#endif
1184
1115
 
1185
 
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
 
1116
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1186
1117
void PNGAPI
1187
1118
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1188
1119
   png_user_chunk_ptr read_user_chunk_fn)
1197
1128
}
1198
1129
#endif
1199
1130
 
1200
 
#if defined(PNG_INFO_IMAGE_SUPPORTED)
 
1131
#ifdef PNG_INFO_IMAGE_SUPPORTED
1201
1132
void PNGAPI
1202
1133
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1203
1134
{
1281
1212
}
1282
1213
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1283
1214
 
 
1215
 
 
1216
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
 
1217
void PNGAPI
 
1218
png_set_benign_errors(png_structp png_ptr, int allowed)
 
1219
{
 
1220
   png_debug(1, "in png_set_benign_errors");
 
1221
 
 
1222
   if (allowed)
 
1223
      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
 
1224
   else
 
1225
      png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
 
1226
}
 
1227
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
1284
1228
#endif /* ?PNG_1_0_X */
1285
1229
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */