~ubuntu-branches/ubuntu/intrepid/libpng/intrepid-security

« back to all changes in this revision

Viewing changes to pngset.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2006-11-21 19:07:43 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20061121190743-wkt0yzs5uq2xoq10
Tags: 1.2.13-4
Removed drop_pass_width patch. Closes: #399499.

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
 
 * libpng 1.2.8 - December 3, 2004
 
4
 * Last changed in libpng 1.2.13 November 13, 2006
5
5
 * For conditions of distribution and use, see copyright notice in png.h
6
 
 * Copyright (c) 1998-2004 Glenn Randers-Pehrson
 
6
 * Copyright (c) 1998-2006 Glenn Randers-Pehrson
7
7
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
8
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9
9
 *
16
16
#define PNG_INTERNAL
17
17
#include "png.h"
18
18
 
 
19
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
 
20
 
19
21
#if defined(PNG_bKGD_SUPPORTED)
20
22
void PNGAPI
21
23
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
100
102
        "Ignoring attempt to set negative chromaticity value");
101
103
      return;
102
104
   }
 
105
#ifdef PNG_FLOATING_POINT_SUPPORTED
103
106
   if (white_x > (double) PNG_UINT_31_MAX ||
104
107
       white_y > (double) PNG_UINT_31_MAX ||
105
108
         red_x > (double) PNG_UINT_31_MAX ||
108
111
       green_y > (double) PNG_UINT_31_MAX ||
109
112
        blue_x > (double) PNG_UINT_31_MAX ||
110
113
        blue_y > (double) PNG_UINT_31_MAX)
 
114
#else
 
115
   if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
116
       white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
117
         red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
118
         red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
119
       green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
120
       green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
121
        blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 
122
        blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
 
123
#endif
111
124
   {
112
125
      png_warning(png_ptr,
113
126
        "Ignoring attempt to set chromaticity value exceeding 21474.83");
209
222
   png_debug1(1, "in %s storage function\n", "hIST");
210
223
   if (png_ptr == NULL || info_ptr == NULL)
211
224
      return;
212
 
   if (info_ptr->num_palette == 0)
 
225
   if (info_ptr->num_palette <= 0 || info_ptr->num_palette
 
226
       > PNG_MAX_PALETTE_LENGTH)
213
227
   {
214
228
       png_warning(png_ptr,
215
 
          "Palette size 0, hIST allocation skipped.");
 
229
          "Invalid palette size, hIST allocation skipped.");
216
230
       return;
217
231
   }
218
232
 
219
233
#ifdef PNG_FREE_ME_SUPPORTED
220
234
   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
221
235
#endif
222
 
   /* Changed from info->num_palette to 256 in version 1.2.1 */
 
236
   /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
 
237
      1.2.1 */
223
238
   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
224
 
      (png_uint_32)(256 * png_sizeof (png_uint_16)));
 
239
      (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
225
240
   if (png_ptr->hist == NULL)
226
241
     {
227
242
       png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
303
318
    * 5. The color_type is RGB or RGBA
304
319
    */
305
320
   if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
306
 
      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
 
321
      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
307
322
   if(filter_type != PNG_FILTER_TYPE_BASE)
308
323
   {
309
324
     if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
310
325
        (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
311
326
        ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
312
 
        (color_type == PNG_COLOR_TYPE_RGB || 
 
327
        (color_type == PNG_COLOR_TYPE_RGB ||
313
328
         color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
314
329
        png_error(png_ptr, "Unknown filter method in IHDR");
315
330
     if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
517
532
   if (png_ptr == NULL || info_ptr == NULL)
518
533
      return;
519
534
 
 
535
   if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
 
536
     {
 
537
       if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 
538
         png_error(png_ptr, "Invalid palette length");
 
539
       else
 
540
       {
 
541
         png_warning(png_ptr, "Invalid palette length");
 
542
         return;
 
543
       }
 
544
     }
 
545
 
520
546
   /*
521
547
    * It may not actually be necessary to set png_ptr->palette here;
522
548
    * we do it for backward compatibility with the way the png_handle_tRNS
526
552
   png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
527
553
#endif
528
554
 
529
 
   /* Changed in libpng-1.2.1 to allocate 256 instead of num_palette entries,
 
555
   /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
 
556
      of num_palette entries,
530
557
      in case of an invalid PNG file that has too-large sample values. */
531
558
   png_ptr->palette = (png_colorp)png_malloc(png_ptr,
532
 
      256 * png_sizeof(png_color));
533
 
   png_memset(png_ptr->palette, 0, 256 * png_sizeof(png_color));
 
559
      PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
 
560
   png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
 
561
      png_sizeof(png_color));
534
562
   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
535
563
   info_ptr->palette = png_ptr->palette;
536
564
   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
890
918
#ifdef PNG_FREE_ME_SUPPORTED
891
919
       png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
892
920
#endif
893
 
       /* Changed from num_trans to 256 in version 1.2.1 */
 
921
       /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
894
922
       png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
895
 
           (png_uint_32)256);
896
 
       png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
 
923
           (png_uint_32)PNG_MAX_PALETTE_LENGTH);
 
924
       if (num_trans <= PNG_MAX_PALETTE_LENGTH)
 
925
         png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
897
926
#ifdef PNG_FREE_ME_SUPPORTED
898
927
       info_ptr->free_me |= PNG_FREE_TRNS;
899
928
#else
921
950
    png_sPLT_tp np;
922
951
    int i;
923
952
 
 
953
    if (png_ptr == NULL || info_ptr == NULL)
 
954
       return;
 
955
 
924
956
    np = (png_sPLT_tp)png_malloc_warn(png_ptr,
925
957
        (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
926
958
    if (np == NULL)
944
976
        /* TODO: use png_malloc_warn */
945
977
        png_strcpy(to->name, from->name);
946
978
        to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
947
 
            from->nentries * png_sizeof(png_sPLT_t));
 
979
            from->nentries * png_sizeof(png_sPLT_entry));
948
980
        /* TODO: use png_malloc_warn */
949
981
        png_memcpy(to->entries, from->entries,
950
 
            from->nentries * png_sizeof(png_sPLT_t));
 
982
            from->nentries * png_sizeof(png_sPLT_entry));
951
983
        to->nentries = from->nentries;
952
984
        to->depth = from->depth;
953
985
    }
1023
1055
}
1024
1056
#endif
1025
1057
 
 
1058
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
1026
1059
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
1027
1060
    defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
1028
1061
void PNGAPI
1029
1062
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
1030
1063
{
1031
1064
   /* This function is deprecated in favor of png_permit_mng_features()
1032
 
      and will be removed from libpng-2.0.0 */
 
1065
      and will be removed from libpng-1.3.0 */
1033
1066
   png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
1034
1067
   if (png_ptr == NULL)
1035
1068
      return;
1038
1071
     ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
1039
1072
}
1040
1073
#endif
 
1074
#endif
1041
1075
 
1042
1076
#if defined(PNG_MNG_FEATURES_SUPPORTED)
1043
1077
png_uint_32 PNGAPI
1059
1093
{
1060
1094
    png_bytep new_list, p;
1061
1095
    int i, old_num_chunks;
 
1096
    if (png_ptr == NULL)
 
1097
       return;
1062
1098
    if (num_chunks == 0)
1063
1099
    {
1064
1100
      if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
1102
1138
   png_user_chunk_ptr read_user_chunk_fn)
1103
1139
{
1104
1140
   png_debug(1, "in png_set_read_user_chunk_fn\n");
 
1141
   if (png_ptr == NULL)
 
1142
      return;
1105
1143
   png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1106
1144
   png_ptr->user_chunk_ptr = user_chunk_ptr;
1107
1145
}
1128
1166
void PNGAPI
1129
1167
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
1130
1168
{
 
1169
    if (png_ptr == NULL)
 
1170
       return;
1131
1171
    if(png_ptr->zbuf)
1132
1172
       png_free(png_ptr, png_ptr->zbuf);
1133
1173
    png_ptr->zbuf_size = (png_size_t)size;
1154
1194
    png_uint_32 settable_asm_flags;
1155
1195
    png_uint_32 settable_mmx_flags;
1156
1196
 
 
1197
    if (png_ptr == NULL)
 
1198
       return;
 
1199
 
1157
1200
    settable_mmx_flags =
1158
1201
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
1159
1202
                         PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  |
1181
1224
    }
1182
1225
 
1183
1226
    /* we're replacing the settable bits with those passed in by the user,
1184
 
     * so first zero them out of the master copy, then logical-OR in the
 
1227
     * so first zero them out of the master copy, then bitwise-OR in the
1185
1228
     * allowed subset that was requested */
1186
1229
 
1187
1230
    png_ptr->asm_flags &= ~settable_asm_flags;               /* zero them */
1196
1239
                        png_byte mmx_bitdepth_threshold,
1197
1240
                        png_uint_32 mmx_rowbytes_threshold)
1198
1241
{
 
1242
    if (png_ptr == NULL)
 
1243
       return;
1199
1244
    png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
1200
1245
    png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
1201
1246
}
1211
1256
     * rejected by png_set_IHDR().  To accept any PNG datastream
1212
1257
     * regardless of dimensions, set both limits to 0x7ffffffL.
1213
1258
     */
 
1259
    if(png_ptr == NULL) return;
1214
1260
    png_ptr->user_width_max = user_width_max;
1215
1261
    png_ptr->user_height_max = user_height_max;
1216
1262
}
1217
1263
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1218
1264
 
1219
1265
#endif /* ?PNG_1_0_X */
 
1266
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */