COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
pngset.c File Reference
#include "pngpriv.h"
Include dependency graph for pngset.c:

Functions

void png_set_bKGD (png_const_structrp png_ptr, png_inforp info_ptr, png_const_color_16p background)
 
void png_set_cHRM_fixed (png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point blue_y)
 
void png_set_cHRM_XYZ_fixed (png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, png_fixed_point int_red_Z, png_fixed_point int_green_X, png_fixed_point int_green_Y, png_fixed_point int_green_Z, png_fixed_point int_blue_X, png_fixed_point int_blue_Y, png_fixed_point int_blue_Z)
 
void png_set_cHRM (png_const_structrp png_ptr, png_inforp info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, double green_y, double blue_x, double blue_y)
 
void png_set_cHRM_XYZ (png_const_structrp png_ptr, png_inforp info_ptr, double red_X, double red_Y, double red_Z, double green_X, double green_Y, double green_Z, double blue_X, double blue_Y, double blue_Z)
 
void png_set_gAMA_fixed (png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point file_gamma)
 
void png_set_gAMA (png_const_structrp png_ptr, png_inforp info_ptr, double file_gamma)
 
void png_set_hIST (png_const_structrp png_ptr, png_inforp info_ptr, png_const_uint_16p hist)
 
void png_set_IHDR (png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type)
 
void png_set_oFFs (png_const_structrp png_ptr, png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y, int unit_type)
 
void png_set_pCAL (png_const_structrp png_ptr, png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params)
 
void png_set_sCAL_s (png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_const_charp swidth, png_const_charp sheight)
 
void png_set_sCAL (png_const_structrp png_ptr, png_inforp info_ptr, int unit, double width, double height)
 
void png_set_sCAL_fixed (png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_fixed_point width, png_fixed_point height)
 
void png_set_pHYs (png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)
 
void png_set_PLTE (png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette)
 
void png_set_sBIT (png_const_structrp png_ptr, png_inforp info_ptr, png_const_color_8p sig_bit)
 
void png_set_sRGB (png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent)
 
void png_set_sRGB_gAMA_and_cHRM (png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent)
 
void png_set_iCCP (png_const_structrp png_ptr, png_inforp info_ptr, png_const_charp name, int compression_type, png_const_bytep profile, png_uint_32 proflen)
 
void png_set_text (png_const_structrp png_ptr, png_inforp info_ptr, png_const_textp text_ptr, int num_text)
 
int png_set_text_2 (png_const_structrp png_ptr, png_inforp info_ptr, png_const_textp text_ptr, int num_text)
 
void png_set_tIME (png_const_structrp png_ptr, png_inforp info_ptr, png_const_timep mod_time)
 
void png_set_tRNS (png_structrp png_ptr, png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
 
void png_set_sPLT (png_const_structrp png_ptr, png_inforp info_ptr, png_const_sPLT_tp entries, int nentries)
 
static png_byte check_location (png_const_structrp png_ptr, int location)
 
void png_set_unknown_chunks (png_const_structrp png_ptr, png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
 
void png_set_unknown_chunk_location (png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location)
 
png_uint_32 png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features)
 
static unsigned int add_one_chunk (png_bytep list, unsigned int count, png_const_bytep add, int keep)
 
void png_set_keep_unknown_chunks (png_structrp png_ptr, int keep, png_const_bytep chunk_list, int num_chunks_in)
 
void png_set_read_user_chunk_fn (png_structrp png_ptr, png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)
 
void png_set_rows (png_const_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers)
 
void png_set_compression_buffer_size (png_structrp png_ptr, png_size_t size)
 
void png_set_invalid (png_const_structrp png_ptr, png_inforp info_ptr, int mask)
 
void png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)
 
void png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max)
 
void png_set_chunk_malloc_max (png_structrp png_ptr, png_alloc_size_t user_chunk_malloc_max)
 
void png_set_benign_errors (png_structrp png_ptr, int allowed)
 
void png_set_check_for_invalid_index (png_structrp png_ptr, int allowed)
 

Function Documentation

void png_set_bKGD ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_color_16p  background 
)
27 {
28  png_debug1(1, "in %s storage function", "bKGD");
29 
30  if (png_ptr == NULL || info_ptr == NULL || background == NULL)
31  return;
32 
33  info_ptr->background = *background;
34  info_ptr->valid |= PNG_INFO_bKGD;
35 }
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_uint_32 valid
Definition: pnginfo.h:61
#define PNG_INFO_bKGD
Definition: png.h:878
void png_set_cHRM_fixed ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_fixed_point  white_x,
png_fixed_point  white_y,
png_fixed_point  red_x,
png_fixed_point  red_y,
png_fixed_point  green_x,
png_fixed_point  green_y,
png_fixed_point  blue_x,
png_fixed_point  blue_y 
)
44 {
45  png_xy xy;
46 
47  png_debug1(1, "in %s storage function", "cHRM fixed");
48 
49  if (png_ptr == NULL || info_ptr == NULL)
50  return;
51 
52  xy.redx = red_x;
53  xy.redy = red_y;
54  xy.greenx = green_x;
55  xy.greeny = green_y;
56  xy.bluex = blue_x;
57  xy.bluey = blue_y;
58  xy.whitex = white_x;
59  xy.whitey = white_y;
60 
61  if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy,
62  2/* override with app values*/) != 0)
63  info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
64 
65  png_colorspace_sync_info(png_ptr, info_ptr);
66 }
void png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
Definition: png.c:1129
int png_colorspace_set_chromaticities(png_const_structrp png_ptr, png_colorspacerp colorspace, const png_xy *xy, int preferred)
Definition: png.c:1679
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
void png_set_cHRM_XYZ_fixed ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_fixed_point  int_red_X,
png_fixed_point  int_red_Y,
png_fixed_point  int_red_Z,
png_fixed_point  int_green_X,
png_fixed_point  int_green_Y,
png_fixed_point  int_green_Z,
png_fixed_point  int_blue_X,
png_fixed_point  int_blue_Y,
png_fixed_point  int_blue_Z 
)
75 {
76  png_XYZ XYZ;
77 
78  png_debug1(1, "in %s storage function", "cHRM XYZ fixed");
79 
80  if (png_ptr == NULL || info_ptr == NULL)
81  return;
82 
83  XYZ.red_X = int_red_X;
84  XYZ.red_Y = int_red_Y;
85  XYZ.red_Z = int_red_Z;
86  XYZ.green_X = int_green_X;
87  XYZ.green_Y = int_green_Y;
88  XYZ.green_Z = int_green_Z;
89  XYZ.blue_X = int_blue_X;
90  XYZ.blue_Y = int_blue_Y;
91  XYZ.blue_Z = int_blue_Z;
92 
93  if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace,
94  &XYZ, 2) != 0)
95  info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
96 
97  png_colorspace_sync_info(png_ptr, info_ptr);
98 }
void png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
Definition: png.c:1129
int png_colorspace_set_endpoints(png_const_structrp png_ptr, png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred)
Definition: png.c:1717
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
void png_set_cHRM ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
double  white_x,
double  white_y,
double  red_x,
double  red_y,
double  green_x,
double  green_y,
double  blue_x,
double  blue_y 
)
105 {
106  png_set_cHRM_fixed(png_ptr, info_ptr,
107  png_fixed(png_ptr, white_x, "cHRM White X"),
108  png_fixed(png_ptr, white_y, "cHRM White Y"),
109  png_fixed(png_ptr, red_x, "cHRM Red X"),
110  png_fixed(png_ptr, red_y, "cHRM Red Y"),
111  png_fixed(png_ptr, green_x, "cHRM Green X"),
112  png_fixed(png_ptr, green_y, "cHRM Green Y"),
113  png_fixed(png_ptr, blue_x, "cHRM Blue X"),
114  png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
115 }
png_fixed_point png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
Definition: png.c:3219
void png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point blue_y)
Definition: pngset.c:40
void png_set_cHRM_XYZ ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
double  red_X,
double  red_Y,
double  red_Z,
double  green_X,
double  green_Y,
double  green_Z,
double  blue_X,
double  blue_Y,
double  blue_Z 
)
121 {
122  png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
123  png_fixed(png_ptr, red_X, "cHRM Red X"),
124  png_fixed(png_ptr, red_Y, "cHRM Red Y"),
125  png_fixed(png_ptr, red_Z, "cHRM Red Z"),
126  png_fixed(png_ptr, green_X, "cHRM Red X"),
127  png_fixed(png_ptr, green_Y, "cHRM Red Y"),
128  png_fixed(png_ptr, green_Z, "cHRM Red Z"),
129  png_fixed(png_ptr, blue_X, "cHRM Red X"),
130  png_fixed(png_ptr, blue_Y, "cHRM Red Y"),
131  png_fixed(png_ptr, blue_Z, "cHRM Red Z"));
132 }
png_fixed_point png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
Definition: png.c:3219
void png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, png_fixed_point int_red_Z, png_fixed_point int_green_X, png_fixed_point int_green_Y, png_fixed_point int_green_Z, png_fixed_point int_blue_X, png_fixed_point int_blue_Y, png_fixed_point int_blue_Z)
Definition: pngset.c:69
void png_set_gAMA_fixed ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_fixed_point  file_gamma 
)
141 {
142  png_debug1(1, "in %s storage function", "gAMA");
143 
144  if (png_ptr == NULL || info_ptr == NULL)
145  return;
146 
147  png_colorspace_set_gamma(png_ptr, &info_ptr->colorspace, file_gamma);
148  png_colorspace_sync_info(png_ptr, info_ptr);
149 }
void png_colorspace_set_gamma(png_const_structrp png_ptr, png_colorspacerp colorspace, png_fixed_point gAMA)
Definition: png.c:1074
void png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
Definition: png.c:1129
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
void png_set_gAMA ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
double  file_gamma 
)
154 {
155  png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma,
156  "png_set_gAMA"));
157 }
png_fixed_point png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
Definition: png.c:3219
void png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point file_gamma)
Definition: pngset.c:139
void png_set_hIST ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_uint_16p  hist 
)
165 {
166  int i;
167 
168  png_debug1(1, "in %s storage function", "hIST");
169 
170  if (png_ptr == NULL || info_ptr == NULL)
171  return;
172 
173  if (info_ptr->num_palette == 0 || info_ptr->num_palette
175  {
176  png_warning(png_ptr,
177  "Invalid palette size, hIST allocation skipped");
178 
179  return;
180  }
181 
182  png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
183 
184  /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
185  * version 1.2.1
186  */
187  info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr,
188  PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16))));
189 
190  if (info_ptr->hist == NULL)
191  {
192  png_warning(png_ptr, "Insufficient memory for hIST chunk data");
193  return;
194  }
195 
196  info_ptr->free_me |= PNG_FREE_HIST;
197 
198  for (i = 0; i < info_ptr->num_palette; i++)
199  info_ptr->hist[i] = hist[i];
200 
201  info_ptr->valid |= PNG_INFO_hIST;
202 }
#define PNG_FREE_HIST
Definition: png.h:1912
#define PNG_INFO_hIST
Definition: png.h:879
int i
Definition: rw_test.cpp:37
#define PNG_MAX_PALETTE_LENGTH
Definition: png.h:866
PNG_IMPEXP png_voidp() png_malloc_warn(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:210
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
#define png_voidcast(type, value)
Definition: pngpriv.h:408
void png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, int num)
Definition: png.c:442
png_uint_16 num_palette
Definition: pnginfo.h:64
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_uint_16 * png_uint_16p
Definition: pngconf.h:606
png_uint_32 valid
Definition: pnginfo.h:61
png_uint_32 free_me
Definition: pnginfo.h:221
void png_set_IHDR ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_uint_32  width,
png_uint_32  height,
int  bit_depth,
int  color_type,
int  interlace_type,
int  compression_type,
int  filter_type 
)
210 {
211  png_debug1(1, "in %s storage function", "IHDR");
212 
213  if (png_ptr == NULL || info_ptr == NULL)
214  return;
215 
216  info_ptr->width = width;
217  info_ptr->height = height;
218  info_ptr->bit_depth = (png_byte)bit_depth;
219  info_ptr->color_type = (png_byte)color_type;
220  info_ptr->compression_type = (png_byte)compression_type;
221  info_ptr->filter_type = (png_byte)filter_type;
222  info_ptr->interlace_type = (png_byte)interlace_type;
223 
224  png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
225  info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
226  info_ptr->compression_type, info_ptr->filter_type);
227 
228  if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
229  info_ptr->channels = 1;
230 
231  else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
232  info_ptr->channels = 3;
233 
234  else
235  info_ptr->channels = 1;
236 
237  if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
238  info_ptr->channels++;
239 
240  info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
241 
242  info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
243 }
png_byte filter_type
Definition: pnginfo.h:70
png_size_t rowbytes
Definition: pnginfo.h:62
png_byte interlace_type
Definition: pnginfo.h:71
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:810
png_byte compression_type
Definition: pnginfo.h:69
png_byte color_type
Definition: pnginfo.h:67
png_byte channels
Definition: pnginfo.h:76
#define PNG_COLOR_MASK_COLOR
Definition: png.h:805
png_uint_32 height
Definition: pnginfo.h:60
void png_check_IHDR(png_const_structrp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type)
Definition: png.c:2476
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_byte bit_depth
Definition: pnginfo.h:66
#define PNG_COLOR_MASK_ALPHA
Definition: png.h:806
png_byte pixel_depth
Definition: pnginfo.h:77
png_uint_32 width
Definition: pnginfo.h:59
#define PNG_ROWBYTES(pixel_bits, width)
Definition: pngpriv.h:660
void png_set_oFFs ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_int_32  offset_x,
png_int_32  offset_y,
int  unit_type 
)
249 {
250  png_debug1(1, "in %s storage function", "oFFs");
251 
252  if (png_ptr == NULL || info_ptr == NULL)
253  return;
254 
255  info_ptr->x_offset = offset_x;
256  info_ptr->y_offset = offset_y;
257  info_ptr->offset_unit_type = (png_byte)unit_type;
258  info_ptr->valid |= PNG_INFO_oFFs;
259 }
#define PNG_INFO_oFFs
Definition: png.h:881
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_uint_32 valid
Definition: pnginfo.h:61
void png_set_pCAL ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_charp  purpose,
png_int_32  X0,
png_int_32  X1,
int  type,
int  nparams,
png_const_charp  units,
png_charpp  params 
)
267 {
269  int i;
270 
271  png_debug1(1, "in %s storage function", "pCAL");
272 
273  if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL
274  || (nparams > 0 && params == NULL))
275  return;
276 
277  length = strlen(purpose) + 1;
278  png_debug1(3, "allocating purpose for info (%lu bytes)",
279  (unsigned long)length);
280 
281  /* TODO: validate format of calibration name and unit name */
282 
283  /* Check that the type matches the specification. */
284  if (type < 0 || type > 3)
285  png_error(png_ptr, "Invalid pCAL equation type");
286 
287  if (nparams < 0 || nparams > 255)
288  png_error(png_ptr, "Invalid pCAL parameter count");
289 
290  /* Validate params[nparams] */
291  for (i=0; i<nparams; ++i)
292  {
293  if (params[i] == NULL ||
294  !png_check_fp_string(params[i], strlen(params[i])))
295  png_error(png_ptr, "Invalid format for pCAL parameter");
296  }
297 
298  info_ptr->pcal_purpose = png_voidcast(png_charp,
299  png_malloc_warn(png_ptr, length));
300 
301  if (info_ptr->pcal_purpose == NULL)
302  {
303  png_warning(png_ptr, "Insufficient memory for pCAL purpose");
304  return;
305  }
306 
307  memcpy(info_ptr->pcal_purpose, purpose, length);
308 
309  png_debug(3, "storing X0, X1, type, and nparams in info");
310  info_ptr->pcal_X0 = X0;
311  info_ptr->pcal_X1 = X1;
312  info_ptr->pcal_type = (png_byte)type;
313  info_ptr->pcal_nparams = (png_byte)nparams;
314 
315  length = strlen(units) + 1;
316  png_debug1(3, "allocating units for info (%lu bytes)",
317  (unsigned long)length);
318 
319  info_ptr->pcal_units = png_voidcast(png_charp,
320  png_malloc_warn(png_ptr, length));
321 
322  if (info_ptr->pcal_units == NULL)
323  {
324  png_warning(png_ptr, "Insufficient memory for pCAL units");
325  return;
326  }
327 
328  memcpy(info_ptr->pcal_units, units, length);
329 
330  info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
331  (png_size_t)((nparams + 1) * (sizeof (png_charp)))));
332 
333  if (info_ptr->pcal_params == NULL)
334  {
335  png_warning(png_ptr, "Insufficient memory for pCAL params");
336  return;
337  }
338 
339  memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp)));
340 
341  for (i = 0; i < nparams; i++)
342  {
343  length = strlen(params[i]) + 1;
344  png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
345  (unsigned long)length);
346 
347  info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
348 
349  if (info_ptr->pcal_params[i] == NULL)
350  {
351  png_warning(png_ptr, "Insufficient memory for pCAL parameter");
352  return;
353  }
354 
355  memcpy(info_ptr->pcal_params[i], params[i], length);
356  }
357 
358  info_ptr->valid |= PNG_INFO_pCAL;
359  info_ptr->free_me |= PNG_FREE_PCAL;
360 }
int i
Definition: rw_test.cpp:37
PNG_IMPEXP png_voidp() png_malloc_warn(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:210
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
char * png_charp
Definition: pngconf.h:610
#define png_debug(l, m)
Definition: pngdebug.h:146
#define png_voidcast(type, value)
Definition: pngpriv.h:408
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
char ** png_charpp
Definition: pngconf.h:633
png_uint_32 length
Definition: png.c:2173
png_uint_32 valid
Definition: pnginfo.h:61
#define PNG_FREE_PCAL
Definition: png.h:1916
PNG_IMPEXP void() png_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:40
size_t png_size_t
Definition: pngconf.h:543
int png_check_fp_string(png_const_charp string, png_size_t size)
Definition: png.c:2770
png_uint_32 free_me
Definition: pnginfo.h:221
#define PNG_INFO_pCAL
Definition: png.h:883
#define png_debug2(l, m, p1, p2)
Definition: pngdebug.h:152
void png_set_sCAL_s ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  unit,
png_const_charp  swidth,
png_const_charp  sheight 
)
367 {
368  png_size_t lengthw = 0, lengthh = 0;
369 
370  png_debug1(1, "in %s storage function", "sCAL");
371 
372  if (png_ptr == NULL || info_ptr == NULL)
373  return;
374 
375  /* Double check the unit (should never get here with an invalid
376  * unit unless this is an API call.)
377  */
378  if (unit != 1 && unit != 2)
379  png_error(png_ptr, "Invalid sCAL unit");
380 
381  if (swidth == NULL || (lengthw = strlen(swidth)) == 0 ||
382  swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw))
383  png_error(png_ptr, "Invalid sCAL width");
384 
385  if (sheight == NULL || (lengthh = strlen(sheight)) == 0 ||
386  sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh))
387  png_error(png_ptr, "Invalid sCAL height");
388 
389  info_ptr->scal_unit = (png_byte)unit;
390 
391  ++lengthw;
392 
393  png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
394 
395  info_ptr->scal_s_width = png_voidcast(png_charp,
396  png_malloc_warn(png_ptr, lengthw));
397 
398  if (info_ptr->scal_s_width == NULL)
399  {
400  png_warning(png_ptr, "Memory allocation failed while processing sCAL");
401  return;
402  }
403 
404  memcpy(info_ptr->scal_s_width, swidth, lengthw);
405 
406  ++lengthh;
407 
408  png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
409 
410  info_ptr->scal_s_height = png_voidcast(png_charp,
411  png_malloc_warn(png_ptr, lengthh));
412 
413  if (info_ptr->scal_s_height == NULL)
414  {
415  png_free (png_ptr, info_ptr->scal_s_width);
416  info_ptr->scal_s_width = NULL;
417 
418  png_warning(png_ptr, "Memory allocation failed while processing sCAL");
419  return;
420  }
421 
422  memcpy(info_ptr->scal_s_height, sheight, lengthh);
423 
424  info_ptr->valid |= PNG_INFO_sCAL;
425  info_ptr->free_me |= PNG_FREE_SCAL;
426 }
PNG_IMPEXP png_voidp() png_malloc_warn(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:210
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
char * png_charp
Definition: pngconf.h:610
#define png_voidcast(type, value)
Definition: pngpriv.h:408
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_uint_32 valid
Definition: pnginfo.h:61
PNG_IMPEXP void() png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:229
PNG_IMPEXP void() png_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:40
size_t png_size_t
Definition: pngconf.h:543
int png_check_fp_string(png_const_charp string, png_size_t size)
Definition: png.c:2770
png_uint_32 free_me
Definition: pnginfo.h:221
#define PNG_FREE_SCAL
Definition: png.h:1917
#define PNG_INFO_sCAL
Definition: png.h:887
void png_set_sCAL ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  unit,
double  width,
double  height 
)
432 {
433  png_debug1(1, "in %s storage function", "sCAL");
434 
435  /* Check the arguments. */
436  if (width <= 0)
437  png_warning(png_ptr, "Invalid sCAL width ignored");
438 
439  else if (height <= 0)
440  png_warning(png_ptr, "Invalid sCAL height ignored");
441 
442  else
443  {
444  /* Convert 'width' and 'height' to ASCII. */
445  char swidth[PNG_sCAL_MAX_DIGITS+1];
446  char sheight[PNG_sCAL_MAX_DIGITS+1];
447 
448  png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,
450  png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,
452 
453  png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
454  }
455 }
#define PNG_sCAL_PRECISION
Definition: pnglibconf.h:207
void png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, double fp, unsigned int precision)
Definition: png.c:2826
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
void png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_const_charp swidth, png_const_charp sheight)
Definition: pngset.c:365
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
#define PNG_sCAL_MAX_DIGITS
Definition: pngpriv.h:1685
void png_set_sCAL_fixed ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  unit,
png_fixed_point  width,
png_fixed_point  height 
)
462 {
463  png_debug1(1, "in %s storage function", "sCAL");
464 
465  /* Check the arguments. */
466  if (width <= 0)
467  png_warning(png_ptr, "Invalid sCAL width ignored");
468 
469  else if (height <= 0)
470  png_warning(png_ptr, "Invalid sCAL height ignored");
471 
472  else
473  {
474  /* Convert 'width' and 'height' to ASCII. */
475  char swidth[PNG_sCAL_MAX_DIGITS+1];
476  char sheight[PNG_sCAL_MAX_DIGITS+1];
477 
478  png_ascii_from_fixed(png_ptr, swidth, (sizeof swidth), width);
479  png_ascii_from_fixed(png_ptr, sheight, (sizeof sheight), height);
480 
481  png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
482  }
483 }
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
void png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, int unit, png_const_charp swidth, png_const_charp sheight)
Definition: pngset.c:365
void png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, png_size_t size, png_fixed_point fp)
Definition: png.c:3141
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
#define PNG_sCAL_MAX_DIGITS
Definition: pngpriv.h:1685
void png_set_pHYs ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_uint_32  res_x,
png_uint_32  res_y,
int  unit_type 
)
491 {
492  png_debug1(1, "in %s storage function", "pHYs");
493 
494  if (png_ptr == NULL || info_ptr == NULL)
495  return;
496 
497  info_ptr->x_pixels_per_unit = res_x;
498  info_ptr->y_pixels_per_unit = res_y;
499  info_ptr->phys_unit_type = (png_byte)unit_type;
500  info_ptr->valid |= PNG_INFO_pHYs;
501 }
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_uint_32 valid
Definition: pnginfo.h:61
#define PNG_INFO_pHYs
Definition: png.h:880
void png_set_PLTE ( png_structrp  png_ptr,
png_inforp  info_ptr,
png_const_colorp  palette,
int  num_palette 
)
507 {
508 
509  png_debug1(1, "in %s storage function", "PLTE");
510 
511  if (png_ptr == NULL || info_ptr == NULL)
512  return;
513 
514  if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
515  {
516  if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
517  png_error(png_ptr, "Invalid palette length");
518 
519  else
520  {
521  png_warning(png_ptr, "Invalid palette length");
522  return;
523  }
524  }
525 
526  if ((num_palette > 0 && palette == NULL) ||
527  (num_palette == 0
529  && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0
530 # endif
531  ))
532  {
533  png_error(png_ptr, "Invalid palette");
534  return;
535  }
536 
537  /* It may not actually be necessary to set png_ptr->palette here;
538  * we do it for backward compatibility with the way the png_handle_tRNS
539  * function used to do the allocation.
540  *
541  * 1.6.0: the above statement appears to be incorrect; something has to set
542  * the palette inside png_struct on read.
543  */
544  png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
545 
546  /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
547  * of num_palette entries, in case of an invalid PNG file that has
548  * too-large sample values.
549  */
550  png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
551  PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
552 
553  if (num_palette > 0)
554  memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
555  info_ptr->palette = png_ptr->palette;
556  info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
557 
558  info_ptr->free_me |= PNG_FREE_PLTE;
559 
560  info_ptr->valid |= PNG_INFO_PLTE;
561 }
#define PNG_MAX_PALETTE_LENGTH
Definition: png.h:866
png_colorp palette
Definition: pnginfo.h:63
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:810
#define PNG_FREE_PLTE
Definition: png.h:1922
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
#define png_voidcast(type, value)
Definition: pngpriv.h:408
void png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, int num)
Definition: png.c:442
#define PNG_MNG_FEATURES_SUPPORTED
Definition: pnglibconf.h:45
png_byte color_type
Definition: pnginfo.h:67
png_colorp palette
Definition: pngstruct.h:238
png_uint_16 num_palette
Definition: pngstruct.h:239
png_uint_16 num_palette
Definition: pnginfo.h:64
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
Definition: png.h:619
#define PNG_INFO_PLTE
Definition: png.h:876
PNG_IMPEXP png_voidp() png_calloc(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:50
png_uint_32 valid
Definition: pnginfo.h:61
PNG_IMPEXP void() png_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:40
#define PNG_FLAG_MNG_EMPTY_PLTE
Definition: png.h:995
png_uint_32 free_me
Definition: pnginfo.h:221
void png_set_sBIT ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_color_8p  sig_bit 
)
567 {
568  png_debug1(1, "in %s storage function", "sBIT");
569 
570  if (png_ptr == NULL || info_ptr == NULL || sig_bit == NULL)
571  return;
572 
573  info_ptr->sig_bit = *sig_bit;
574  info_ptr->valid |= PNG_INFO_sBIT;
575 }
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
#define PNG_INFO_sBIT
Definition: png.h:874
png_uint_32 valid
Definition: pnginfo.h:61
void png_set_sRGB ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  srgb_intent 
)
581 {
582  png_debug1(1, "in %s storage function", "sRGB");
583 
584  if (png_ptr == NULL || info_ptr == NULL)
585  return;
586 
587  (void)png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent);
588  png_colorspace_sync_info(png_ptr, info_ptr);
589 }
void png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
Definition: png.c:1129
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
int png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, int intent)
Definition: png.c:1833
void png_set_sRGB_gAMA_and_cHRM ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  srgb_intent 
)
594 {
595  png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
596 
597  if (png_ptr == NULL || info_ptr == NULL)
598  return;
599 
600  if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace,
601  srgb_intent) != 0)
602  {
603  /* This causes the gAMA and cHRM to be written too */
604  info_ptr->colorspace.flags |=
605  PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
606  }
607 
608  png_colorspace_sync_info(png_ptr, info_ptr);
609 }
void png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
Definition: png.c:1129
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
int png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, int intent)
Definition: png.c:1833
void png_set_iCCP ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_charp  name,
int  compression_type,
png_const_bytep  profile,
png_uint_32  proflen 
)
618 {
619  png_charp new_iccp_name;
620  png_bytep new_iccp_profile;
622 
623  png_debug1(1, "in %s storage function", "iCCP");
624 
625  if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
626  return;
627 
628  if (compression_type != PNG_COMPRESSION_TYPE_BASE)
629  png_app_error(png_ptr, "Invalid iCCP compression method");
630 
631  /* Set the colorspace first because this validates the profile; do not
632  * override previously set app cHRM or gAMA here (because likely as not the
633  * application knows better than libpng what the correct values are.) Pass
634  * the info_ptr color_type field to png_colorspace_set_ICC because in the
635  * write case it has not yet been stored in png_ptr.
636  */
637  {
638  int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
639  proflen, profile, info_ptr->color_type);
640 
641  png_colorspace_sync_info(png_ptr, info_ptr);
642 
643  /* Don't do any of the copying if the profile was bad, or inconsistent. */
644  if (result == 0)
645  return;
646 
647  /* But do write the gAMA and cHRM chunks from the profile. */
648  info_ptr->colorspace.flags |=
649  PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
650  }
651 
652  length = strlen(name)+1;
653  new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));
654 
655  if (new_iccp_name == NULL)
656  {
657  png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk");
658  return;
659  }
660 
661  memcpy(new_iccp_name, name, length);
662  new_iccp_profile = png_voidcast(png_bytep,
663  png_malloc_warn(png_ptr, proflen));
664 
665  if (new_iccp_profile == NULL)
666  {
667  png_free(png_ptr, new_iccp_name);
668  new_iccp_name = NULL;
669  png_benign_error(png_ptr,
670  "Insufficient memory to process iCCP profile");
671  return;
672  }
673 
674  memcpy(new_iccp_profile, profile, proflen);
675 
676  png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
677 
678  info_ptr->iccp_proflen = proflen;
679  info_ptr->iccp_name = new_iccp_name;
680  info_ptr->iccp_profile = new_iccp_profile;
681  info_ptr->free_me |= PNG_FREE_ICCP;
682  info_ptr->valid |= PNG_INFO_iCCP;
683 }
int png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace, png_const_charp name, png_uint_32 profile_length, png_const_bytep profile, int color_type)
Definition: png.c:2371
png_byte * png_bytep
Definition: pngconf.h:600
PNG_IMPEXP png_voidp() png_malloc_warn(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:210
char * png_charp
Definition: pngconf.h:610
#define PNG_FREE_ICCP
Definition: png.h:1913
#define png_voidcast(type, value)
Definition: pngpriv.h:408
void png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)
Definition: png.c:1129
void png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, int num)
Definition: png.c:442
png_byte color_type
Definition: pnginfo.h:67
void png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:405
string name
Definition: cubesat2obj.cpp:6
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_uint_32 length
Definition: png.c:2173
#define PNG_COMPRESSION_TYPE_BASE
Definition: png.h:819
png_uint_32 valid
Definition: pnginfo.h:61
PNG_IMPEXP void() png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:229
size_t png_size_t
Definition: pngconf.h:543
png_uint_32 free_me
Definition: pnginfo.h:221
#define PNG_INFO_iCCP
Definition: png.h:885
PNG_IMPEXP void() png_benign_error(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:362
void png_set_text ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_textp  text_ptr,
int  num_text 
)
690 {
691  int ret;
692  ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
693 
694  if (ret != 0)
695  png_error(png_ptr, "Insufficient memory to store text");
696 }
int png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, png_const_textp text_ptr, int num_text)
Definition: pngset.c:699
PNG_IMPEXP void() png_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:40
int png_set_text_2 ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_textp  text_ptr,
int  num_text 
)
701 {
702  int i;
703 
704  png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" :
705  (unsigned long)png_ptr->chunk_name);
706 
707  if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)
708  return(0);
709 
710  /* Make sure we have enough space in the "text" array in info_struct
711  * to hold all of the incoming text_ptr objects. This compare can't overflow
712  * because max_text >= num_text (anyway, subtract of two positive integers
713  * can't overflow in any case.)
714  */
715  if (num_text > info_ptr->max_text - info_ptr->num_text)
716  {
717  int old_num_text = info_ptr->num_text;
718  int max_text;
719  png_textp new_text = NULL;
720 
721  /* Calculate an appropriate max_text, checking for overflow. */
722  max_text = old_num_text;
723  if (num_text <= INT_MAX - max_text)
724  {
725  max_text += num_text;
726 
727  /* Round up to a multiple of 8 */
728  if (max_text < INT_MAX-8)
729  max_text = (max_text + 8) & ~0x7;
730 
731  else
732  max_text = INT_MAX;
733 
734  /* Now allocate a new array and copy the old members in; this does all
735  * the overflow checks.
736  */
737  new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,
738  info_ptr->text, old_num_text, max_text-old_num_text,
739  sizeof *new_text));
740  }
741 
742  if (new_text == NULL)
743  {
744  png_chunk_report(png_ptr, "too many text chunks",
746  return 1;
747  }
748 
749  png_free(png_ptr, info_ptr->text);
750 
751  info_ptr->text = new_text;
752  info_ptr->free_me |= PNG_FREE_TEXT;
753  info_ptr->max_text = max_text;
754  /* num_text is adjusted below as the entries are copied in */
755 
756  png_debug1(3, "allocated %d entries for info_ptr->text", max_text);
757  }
758 
759  for (i = 0; i < num_text; i++)
760  {
761  size_t text_length, key_len;
762  size_t lang_len, lang_key_len;
763  png_textp textp = &(info_ptr->text[info_ptr->num_text]);
764 
765  if (text_ptr[i].key == NULL)
766  continue;
767 
768  if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||
769  text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
770  {
771  png_chunk_report(png_ptr, "text compression mode is out of range",
773  continue;
774  }
775 
776  key_len = strlen(text_ptr[i].key);
777 
778  if (text_ptr[i].compression <= 0)
779  {
780  lang_len = 0;
781  lang_key_len = 0;
782  }
783 
784  else
785 # ifdef PNG_iTXt_SUPPORTED
786  {
787  /* Set iTXt data */
788 
789  if (text_ptr[i].lang != NULL)
790  lang_len = strlen(text_ptr[i].lang);
791 
792  else
793  lang_len = 0;
794 
795  if (text_ptr[i].lang_key != NULL)
796  lang_key_len = strlen(text_ptr[i].lang_key);
797 
798  else
799  lang_key_len = 0;
800  }
801 # else /* PNG_iTXt_SUPPORTED */
802  {
803  png_chunk_report(png_ptr, "iTXt chunk not supported",
805  continue;
806  }
807 # endif
808 
809  if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
810  {
811  text_length = 0;
812 # ifdef PNG_iTXt_SUPPORTED
813  if (text_ptr[i].compression > 0)
815 
816  else
817 # endif
819  }
820 
821  else
822  {
823  text_length = strlen(text_ptr[i].text);
824  textp->compression = text_ptr[i].compression;
825  }
826 
827  textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr,
828  key_len + text_length + lang_len + lang_key_len + 4));
829 
830  if (textp->key == NULL)
831  {
832  png_chunk_report(png_ptr, "text chunk: out of memory",
834  return 1;
835  }
836 
837  png_debug2(2, "Allocated %lu bytes at %p in png_set_text",
838  (unsigned long)(png_uint_32)
839  (key_len + lang_len + lang_key_len + text_length + 4),
840  textp->key);
841 
842  memcpy(textp->key, text_ptr[i].key, key_len);
843  *(textp->key + key_len) = '\0';
844 
845  if (text_ptr[i].compression > 0)
846  {
847  textp->lang = textp->key + key_len + 1;
848  memcpy(textp->lang, text_ptr[i].lang, lang_len);
849  *(textp->lang + lang_len) = '\0';
850  textp->lang_key = textp->lang + lang_len + 1;
851  memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
852  *(textp->lang_key + lang_key_len) = '\0';
853  textp->text = textp->lang_key + lang_key_len + 1;
854  }
855 
856  else
857  {
858  textp->lang=NULL;
859  textp->lang_key=NULL;
860  textp->text = textp->key + key_len + 1;
861  }
862 
863  if (text_length != 0)
864  memcpy(textp->text, text_ptr[i].text, text_length);
865 
866  *(textp->text + text_length) = '\0';
867 
868 # ifdef PNG_iTXt_SUPPORTED
869  if (textp->compression > 0)
870  {
871  textp->text_length = 0;
872  textp->itxt_length = text_length;
873  }
874 
875  else
876 # endif
877  {
878  textp->text_length = text_length;
879  textp->itxt_length = 0;
880  }
881 
882  info_ptr->num_text++;
883  png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
884  }
885 
886  return(0);
887 }
#define PNG_TEXT_COMPRESSION_LAST
Definition: png.h:733
#define PNG_FREE_TEXT
Definition: png.h:1924
png_charp text
Definition: png.h:711
int compression
Definition: png.h:705
int i
Definition: rw_test.cpp:37
char * png_charp
Definition: pngconf.h:610
png_charp lang
Definition: png.h:715
png_voidp png_realloc_array(png_const_structrp png_ptr, png_const_voidp old_array, int old_elements, int add_elements, size_t element_size)
Definition: pngmem.c:130
#define png_voidcast(type, value)
Definition: pngpriv.h:408
png_voidp png_malloc_base(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:69
png_uint_32 chunk_name
Definition: pngstruct.h:221
png_charp key
Definition: png.h:710
#define PNG_TEXT_COMPRESSION_NONE
Definition: png.h:729
Definition: png.h:703
#define PNG_ITXT_COMPRESSION_NONE
Definition: png.h:731
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
#define PNG_CHUNK_WRITE_ERROR
Definition: pngpriv.h:1673
png_size_t itxt_length
Definition: png.h:714
PNG_IMPEXP void() png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:229
void png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
Definition: pngerror.c:531
png_charp lang_key
Definition: png.h:717
png_size_t text_length
Definition: png.h:713
png_uint_32 free_me
Definition: pnginfo.h:221
#define png_debug2(l, m, p1, p2)
Definition: pngdebug.h:152
void png_set_tIME ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_timep  mod_time 
)
894 {
895  png_debug1(1, "in %s storage function", "tIME");
896 
897  if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL ||
898  (png_ptr->mode & PNG_WROTE_tIME) != 0)
899  return;
900 
901  if (mod_time->month == 0 || mod_time->month > 12 ||
902  mod_time->day == 0 || mod_time->day > 31 ||
903  mod_time->hour > 23 || mod_time->minute > 59 ||
904  mod_time->second > 60)
905  {
906  png_warning(png_ptr, "Ignoring invalid time value");
907  return;
908  }
909 
910  info_ptr->mod_time = *mod_time;
911  info_ptr->valid |= PNG_INFO_tIME;
912 }
#define PNG_INFO_tIME
Definition: png.h:882
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
png_byte hour
Definition: png.h:746
png_byte second
Definition: png.h:748
png_byte minute
Definition: png.h:747
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
#define PNG_WROTE_tIME
Definition: pngpriv.h:551
png_byte day
Definition: png.h:745
png_uint_32 valid
Definition: pnginfo.h:61
png_uint_32 mode
Definition: pngstruct.h:179
png_byte month
Definition: png.h:744
void png_set_tRNS ( png_structrp  png_ptr,
png_inforp  info_ptr,
png_const_bytep  trans_alpha,
int  num_trans,
png_const_color_16p  trans_color 
)
919 {
920  png_debug1(1, "in %s storage function", "tRNS");
921 
922  if (png_ptr == NULL || info_ptr == NULL)
923  return;
924 
925  if (trans_alpha != NULL)
926  {
927  /* It may not actually be necessary to set png_ptr->trans_alpha here;
928  * we do it for backward compatibility with the way the png_handle_tRNS
929  * function used to do the allocation.
930  *
931  * 1.6.0: The above statement is incorrect; png_handle_tRNS effectively
932  * relies on png_set_tRNS storing the information in png_struct
933  * (otherwise it won't be there for the code in pngrtran.c).
934  */
935 
936  png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
937 
938  /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
939  png_ptr->trans_alpha = info_ptr->trans_alpha = png_voidcast(png_bytep,
941 
942  if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
943  memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
944  }
945 
946  if (trans_color != NULL)
947  {
948  int sample_max = (1 << info_ptr->bit_depth);
949 
950  if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
951  trans_color->gray > sample_max) ||
952  (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
953  (trans_color->red > sample_max ||
954  trans_color->green > sample_max ||
955  trans_color->blue > sample_max)))
956  png_warning(png_ptr,
957  "tRNS chunk has out-of-range samples for bit_depth");
958 
959  info_ptr->trans_color = *trans_color;
960 
961  if (num_trans == 0)
962  num_trans = 1;
963  }
964 
965  info_ptr->num_trans = (png_uint_16)num_trans;
966 
967  if (num_trans != 0)
968  {
969  info_ptr->valid |= PNG_INFO_tRNS;
970  info_ptr->free_me |= PNG_FREE_TRNS;
971  }
972 }
PNG_IMPEXP png_voidp() png_malloc(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:169
#define PNG_MAX_PALETTE_LENGTH
Definition: png.h:866
#define PNG_COLOR_TYPE_RGB
Definition: png.h:811
png_uint_16 blue
Definition: png.h:634
png_byte * png_bytep
Definition: pngconf.h:600
png_uint_16 gray
Definition: png.h:635
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
#define png_voidcast(type, value)
Definition: pngpriv.h:408
void png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, int num)
Definition: png.c:442
png_byte color_type
Definition: pnginfo.h:67
png_uint_16 green
Definition: png.h:633
#define PNG_COLOR_TYPE_GRAY
Definition: png.h:809
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
png_byte bit_depth
Definition: pnginfo.h:66
#define PNG_INFO_tRNS
Definition: png.h:877
png_uint_32 valid
Definition: pnginfo.h:61
size_t png_size_t
Definition: pngconf.h:543
png_uint_16 red
Definition: png.h:632
png_uint_32 free_me
Definition: pnginfo.h:221
png_uint_16 num_trans
Definition: pnginfo.h:65
#define PNG_FREE_TRNS
Definition: png.h:1923
void png_set_sPLT ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_sPLT_tp  entries,
int  nentries 
)
987 {
988  png_sPLT_tp np;
989 
990  if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL)
991  return;
992 
993  /* Use the internal realloc function, which checks for all the possible
994  * overflows. Notice that the parameters are (int) and (size_t)
995  */
997  info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
998  sizeof *np));
999 
1000  if (np == NULL)
1001  {
1002  /* Out of memory or too many chunks */
1003  png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR);
1004  return;
1005  }
1006 
1007  png_free(png_ptr, info_ptr->splt_palettes);
1008  info_ptr->splt_palettes = np;
1009  info_ptr->free_me |= PNG_FREE_SPLT;
1010 
1011  np += info_ptr->splt_palettes_num;
1012 
1013  do
1014  {
1016 
1017  /* Skip invalid input entries */
1018  if (entries->name == NULL || entries->entries == NULL)
1019  {
1020  /* png_handle_sPLT doesn't do this, so this is an app error */
1021  png_app_error(png_ptr, "png_set_sPLT: invalid sPLT");
1022  /* Just skip the invalid entry */
1023  continue;
1024  }
1025 
1026  np->depth = entries->depth;
1027 
1028  /* In the event of out-of-memory just return - there's no point keeping
1029  * on trying to add sPLT chunks.
1030  */
1031  length = strlen(entries->name) + 1;
1032  np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length));
1033 
1034  if (np->name == NULL)
1035  break;
1036 
1037  memcpy(np->name, entries->name, length);
1038 
1039  /* IMPORTANT: we have memory now that won't get freed if something else
1040  * goes wrong; this code must free it. png_malloc_array produces no
1041  * warnings; use a png_chunk_report (below) if there is an error.
1042  */
1044  entries->nentries, sizeof (png_sPLT_entry)));
1045 
1046  if (np->entries == NULL)
1047  {
1048  png_free(png_ptr, np->name);
1049  np->name = NULL;
1050  break;
1051  }
1052 
1053  np->nentries = entries->nentries;
1054  /* This multiply can't overflow because png_malloc_array has already
1055  * checked it when doing the allocation.
1056  */
1057  memcpy(np->entries, entries->entries,
1058  entries->nentries * sizeof (png_sPLT_entry));
1059 
1060  /* Note that 'continue' skips the advance of the out pointer and out
1061  * count, so an invalid entry is not added.
1062  */
1063  info_ptr->valid |= PNG_INFO_sPLT;
1064  ++(info_ptr->splt_palettes_num);
1065  ++np;
1066  }
1067  while (++entries, --nentries);
1068 
1069  if (nentries > 0)
1070  png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
1071 }
png_int_32 nentries
Definition: png.h:679
char * png_charp
Definition: pngconf.h:610
png_voidp png_realloc_array(png_const_structrp png_ptr, png_const_voidp old_array, int old_elements, int add_elements, size_t element_size)
Definition: pngmem.c:130
#define png_voidcast(type, value)
Definition: pngpriv.h:408
png_voidp png_malloc_base(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:69
void png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:405
png_byte depth
Definition: png.h:677
#define PNG_FREE_SPLT
Definition: png.h:1914
png_sPLT_entryp entries
Definition: png.h:678
Definition: png.h:657
#define PNG_CHUNK_WRITE_ERROR
Definition: pngpriv.h:1673
png_voidp png_malloc_array(png_const_structrp png_ptr, int nelements, size_t element_size)
Definition: pngmem.c:120
Definition: png.h:674
png_uint_32 length
Definition: png.c:2173
png_uint_32 valid
Definition: pnginfo.h:61
PNG_IMPEXP void() png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:229
void png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
Definition: pngerror.c:531
size_t png_size_t
Definition: pngconf.h:543
#define PNG_INFO_sPLT
Definition: png.h:886
png_uint_32 free_me
Definition: pnginfo.h:221
png_charp name
Definition: png.h:676
static png_byte check_location ( png_const_structrp  png_ptr,
int  location 
)
static
1077 {
1079 
1080  /* New in 1.6.0; copy the location and check it. This is an API
1081  * change; previously the app had to use the
1082  * png_set_unknown_chunk_location API below for each chunk.
1083  */
1084  if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
1085  {
1086  /* Write struct, so unknown chunks come from the app */
1087  png_app_warning(png_ptr,
1088  "png_set_unknown_chunks now expects a valid location");
1089  /* Use the old behavior */
1090  location = (png_byte)(png_ptr->mode &
1092  }
1093 
1094  /* This need not be an internal error - if the app calls
1095  * png_set_unknown_chunks on a read pointer it must get the location right.
1096  */
1097  if (location == 0)
1098  png_error(png_ptr, "invalid location in png_set_unknown_chunks");
1099 
1100  /* Now reduce the location to the top-most set bit by removing each least
1101  * significant bit in turn.
1102  */
1103  while (location != (location & -location))
1104  location &= ~(location & -location);
1105 
1106  /* The cast is safe because 'location' is a bit mask and only the low four
1107  * bits are significant.
1108  */
1109  return (png_byte)location;
1110 }
#define PNG_HAVE_PLTE
Definition: png.h:786
#define PNG_IS_READ_STRUCT
Definition: pngpriv.h:557
#define PNG_HAVE_IHDR
Definition: png.h:785
#define PNG_AFTER_IDAT
Definition: png.h:787
png_uint_32 mode
Definition: pngstruct.h:179
PNG_IMPEXP void() png_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:40
void png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:392
void png_set_unknown_chunks ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_const_unknown_chunkp  unknowns,
int  num_unknowns 
)
1115 {
1116  png_unknown_chunkp np;
1117 
1118  if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 ||
1119  unknowns == NULL)
1120  return;
1121 
1122  /* Check for the failure cases where support has been disabled at compile
1123  * time. This code is hardly ever compiled - it's here because
1124  * STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this
1125  * code) but may be meaningless if the read or write handling of unknown
1126  * chunks is not compiled in.
1127  */
1128 # if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
1129  defined(PNG_READ_SUPPORTED)
1130  if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1131  {
1132  png_app_error(png_ptr, "no unknown chunk support on read");
1133  return;
1134  }
1135 # endif
1136 # if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
1137  defined(PNG_WRITE_SUPPORTED)
1138  if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
1139  {
1140  png_app_error(png_ptr, "no unknown chunk support on write");
1141  return;
1142  }
1143 # endif
1144 
1145  /* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that
1146  * unknown critical chunks could be lost with just a warning resulting in
1147  * undefined behavior. Now png_chunk_report is used to provide behavior
1148  * appropriate to read or write.
1149  */
1151  info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
1152  sizeof *np));
1153 
1154  if (np == NULL)
1155  {
1156  png_chunk_report(png_ptr, "too many unknown chunks",
1158  return;
1159  }
1160 
1161  png_free(png_ptr, info_ptr->unknown_chunks);
1162  info_ptr->unknown_chunks = np; /* safe because it is initialized */
1163  info_ptr->free_me |= PNG_FREE_UNKN;
1164 
1165  np += info_ptr->unknown_chunks_num;
1166 
1167  /* Increment unknown_chunks_num each time round the loop to protect the
1168  * just-allocated chunk data.
1169  */
1170  for (; num_unknowns > 0; --num_unknowns, ++unknowns)
1171  {
1172  memcpy(np->name, unknowns->name, (sizeof np->name));
1173  np->name[(sizeof np->name)-1] = '\0';
1174  np->location = check_location(png_ptr, unknowns->location);
1175 
1176  if (unknowns->size == 0)
1177  {
1178  np->data = NULL;
1179  np->size = 0;
1180  }
1181 
1182  else
1183  {
1184  np->data = png_voidcast(png_bytep,
1185  png_malloc_base(png_ptr, unknowns->size));
1186 
1187  if (np->data == NULL)
1188  {
1189  png_chunk_report(png_ptr, "unknown chunk: out of memory",
1191  /* But just skip storing the unknown chunk */
1192  continue;
1193  }
1194 
1195  memcpy(np->data, unknowns->data, unknowns->size);
1196  np->size = unknowns->size;
1197  }
1198 
1199  /* These increments are skipped on out-of-memory for the data - the
1200  * unknown chunk entry gets overwritten if the png_chunk_report returns.
1201  * This is correct in the read case (the chunk is just dropped.)
1202  */
1203  ++np;
1204  ++(info_ptr->unknown_chunks_num);
1205  }
1206 }
png_byte * png_bytep
Definition: pngconf.h:600
png_voidp png_realloc_array(png_const_structrp png_ptr, png_const_voidp old_array, int old_elements, int add_elements, size_t element_size)
Definition: pngmem.c:130
#define png_voidcast(type, value)
Definition: pngpriv.h:408
#define PNG_IS_READ_STRUCT
Definition: pngpriv.h:557
png_voidp png_malloc_base(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:69
png_byte name[5]
Definition: png.h:765
Definition: png.h:763
void png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:405
#define PNG_FREE_UNKN
Definition: png.h:1919
png_byte location
Definition: png.h:775
#define PNG_CHUNK_WRITE_ERROR
Definition: pngpriv.h:1673
png_uint_32 mode
Definition: pngstruct.h:179
PNG_IMPEXP void() png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:229
void png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
Definition: pngerror.c:531
png_byte * data
Definition: png.h:766
png_uint_32 free_me
Definition: pnginfo.h:221
static png_byte check_location(png_const_structrp png_ptr, int location)
Definition: pngset.c:1076
png_size_t size
Definition: png.h:767
void png_set_unknown_chunk_location ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  chunk,
int  location 
)
1211 {
1212  /* This API is pretty pointless in 1.6.0 because the location can be set
1213  * before the call to png_set_unknown_chunks.
1214  *
1215  * TODO: add a png_app_warning in 1.7
1216  */
1217  if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 &&
1218  chunk < info_ptr->unknown_chunks_num)
1219  {
1220  if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0)
1221  {
1222  png_app_error(png_ptr, "invalid unknown chunk location");
1223  /* Fake out the pre 1.6.0 behavior: */
1224  if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */
1225  location = PNG_AFTER_IDAT;
1226 
1227  else
1228  location = PNG_HAVE_IHDR; /* also undocumented */
1229  }
1230 
1231  info_ptr->unknown_chunks[chunk].location =
1232  check_location(png_ptr, location);
1233  }
1234 }
#define PNG_HAVE_PLTE
Definition: png.h:786
#define PNG_HAVE_IDAT
Definition: pngpriv.h:544
#define PNG_HAVE_IHDR
Definition: png.h:785
void png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:405
#define PNG_AFTER_IDAT
Definition: png.h:787
static png_byte check_location(png_const_structrp png_ptr, int location)
Definition: pngset.c:1076
png_uint_32 png_permit_mng_features ( png_structrp  png_ptr,
png_uint_32  mng_features 
)
1241 {
1242  png_debug(1, "in png_permit_mng_features");
1243 
1244  if (png_ptr == NULL)
1245  return 0;
1246 
1247  png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES;
1248 
1249  return png_ptr->mng_features_permitted;
1250 }
#define PNG_ALL_MNG_FEATURES
Definition: png.h:997
#define png_debug(l, m)
Definition: pngdebug.h:146
static unsigned int add_one_chunk ( png_bytep  list,
unsigned int  count,
png_const_bytep  add,
int  keep 
)
static
1256 {
1257  unsigned int i;
1258 
1259  /* Utility function: update the 'keep' state of a chunk if it is already in
1260  * the list, otherwise add it to the list.
1261  */
1262  for (i=0; i<count; ++i, list += 5)
1263  {
1264  if (memcmp(list, add, 4) == 0)
1265  {
1266  list[4] = (png_byte)keep;
1267  return count;
1268  }
1269  }
1270 
1271  if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
1272  {
1273  ++count;
1274  memcpy(list, add, 4);
1275  list[4] = (png_byte)keep;
1276  }
1277 
1278  return count;
1279 }
int i
Definition: rw_test.cpp:37
int count
Definition: rw_test.cpp:36
#define PNG_HANDLE_CHUNK_AS_DEFAULT
Definition: png.h:2497
void png_set_keep_unknown_chunks ( png_structrp  png_ptr,
int  keep,
png_const_bytep  chunk_list,
int  num_chunks_in 
)
1284 {
1285  png_bytep new_list;
1286  unsigned int num_chunks, old_num_chunks;
1287 
1288  if (png_ptr == NULL)
1289  return;
1290 
1291  if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST)
1292  {
1293  png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep");
1294  return;
1295  }
1296 
1297  if (num_chunks_in <= 0)
1298  {
1299  png_ptr->unknown_default = keep;
1300 
1301  /* '0' means just set the flags, so stop here */
1302  if (num_chunks_in == 0)
1303  return;
1304  }
1305 
1306  if (num_chunks_in < 0)
1307  {
1308  /* Ignore all unknown chunks and all chunks recognized by
1309  * libpng except for IHDR, PLTE, tRNS, IDAT, and IEND
1310  */
1311  static PNG_CONST png_byte chunks_to_ignore[] = {
1312  98, 75, 71, 68, '\0', /* bKGD */
1313  99, 72, 82, 77, '\0', /* cHRM */
1314  103, 65, 77, 65, '\0', /* gAMA */
1315  104, 73, 83, 84, '\0', /* hIST */
1316  105, 67, 67, 80, '\0', /* iCCP */
1317  105, 84, 88, 116, '\0', /* iTXt */
1318  111, 70, 70, 115, '\0', /* oFFs */
1319  112, 67, 65, 76, '\0', /* pCAL */
1320  112, 72, 89, 115, '\0', /* pHYs */
1321  115, 66, 73, 84, '\0', /* sBIT */
1322  115, 67, 65, 76, '\0', /* sCAL */
1323  115, 80, 76, 84, '\0', /* sPLT */
1324  115, 84, 69, 82, '\0', /* sTER */
1325  115, 82, 71, 66, '\0', /* sRGB */
1326  116, 69, 88, 116, '\0', /* tEXt */
1327  116, 73, 77, 69, '\0', /* tIME */
1328  122, 84, 88, 116, '\0' /* zTXt */
1329  };
1330 
1331  chunk_list = chunks_to_ignore;
1332  num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U;
1333  }
1334 
1335  else /* num_chunks_in > 0 */
1336  {
1337  if (chunk_list == NULL)
1338  {
1339  /* Prior to 1.6.0 this was silently ignored, now it is an app_error
1340  * which can be switched off.
1341  */
1342  png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list");
1343  return;
1344  }
1345 
1346  num_chunks = num_chunks_in;
1347  }
1348 
1349  old_num_chunks = png_ptr->num_chunk_list;
1350  if (png_ptr->chunk_list == NULL)
1351  old_num_chunks = 0;
1352 
1353  /* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow.
1354  */
1355  if (num_chunks + old_num_chunks > UINT_MAX/5)
1356  {
1357  png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks");
1358  return;
1359  }
1360 
1361  /* If these chunks are being reset to the default then no more memory is
1362  * required because add_one_chunk above doesn't extend the list if the 'keep'
1363  * parameter is the default.
1364  */
1365  if (keep != 0)
1366  {
1367  new_list = png_voidcast(png_bytep, png_malloc(png_ptr,
1368  5 * (num_chunks + old_num_chunks)));
1369 
1370  if (old_num_chunks > 0)
1371  memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
1372  }
1373 
1374  else if (old_num_chunks > 0)
1375  new_list = png_ptr->chunk_list;
1376 
1377  else
1378  new_list = NULL;
1379 
1380  /* Add the new chunks together with each one's handling code. If the chunk
1381  * already exists the code is updated, otherwise the chunk is added to the
1382  * end. (In libpng 1.6.0 order no longer matters because this code enforces
1383  * the earlier convention that the last setting is the one that is used.)
1384  */
1385  if (new_list != NULL)
1386  {
1387  png_const_bytep inlist;
1388  png_bytep outlist;
1389  unsigned int i;
1390 
1391  for (i=0; i<num_chunks; ++i)
1392  {
1393  old_num_chunks = add_one_chunk(new_list, old_num_chunks,
1394  chunk_list+5*i, keep);
1395  }
1396 
1397  /* Now remove any spurious 'default' entries. */
1398  num_chunks = 0;
1399  for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5)
1400  {
1401  if (inlist[4])
1402  {
1403  if (outlist != inlist)
1404  memcpy(outlist, inlist, 5);
1405  outlist += 5;
1406  ++num_chunks;
1407  }
1408  }
1409 
1410  /* This means the application has removed all the specialized handling. */
1411  if (num_chunks == 0)
1412  {
1413  if (png_ptr->chunk_list != new_list)
1414  png_free(png_ptr, new_list);
1415 
1416  new_list = NULL;
1417  }
1418  }
1419 
1420  else
1421  num_chunks = 0;
1422 
1423  png_ptr->num_chunk_list = num_chunks;
1424 
1425  if (png_ptr->chunk_list != new_list)
1426  {
1427  if (png_ptr->chunk_list != NULL)
1428  png_free(png_ptr, png_ptr->chunk_list);
1429 
1430  png_ptr->chunk_list = new_list;
1431  }
1432 }
PNG_IMPEXP png_voidp() png_malloc(png_const_structrp png_ptr, png_alloc_size_t size)
Definition: pngmem.c:169
#define PNG_HANDLE_CHUNK_LAST
Definition: png.h:2501
int i
Definition: rw_test.cpp:37
png_byte * png_bytep
Definition: pngconf.h:600
#define png_voidcast(type, value)
Definition: pngpriv.h:408
void png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:405
#define PNG_CONST
Definition: pngconf.h:86
const png_byte * png_const_bytep
Definition: pngconf.h:601
PNG_IMPEXP void() png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:229
static unsigned int add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep)
Definition: pngset.c:1255
void png_set_read_user_chunk_fn ( png_structrp  png_ptr,
png_voidp  user_chunk_ptr,
png_user_chunk_ptr  read_user_chunk_fn 
)
1439 {
1440  png_debug(1, "in png_set_read_user_chunk_fn");
1441 
1442  if (png_ptr == NULL)
1443  return;
1444 
1445  png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1446  png_ptr->user_chunk_ptr = user_chunk_ptr;
1447 }
#define png_debug(l, m)
Definition: pngdebug.h:146
void png_set_rows ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
png_bytepp  row_pointers 
)
1454 {
1455  png_debug1(1, "in %s storage function", "rows");
1456 
1457  if (png_ptr == NULL || info_ptr == NULL)
1458  return;
1459 
1460  if (info_ptr->row_pointers != NULL &&
1461  (info_ptr->row_pointers != row_pointers))
1462  png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1463 
1464  info_ptr->row_pointers = row_pointers;
1465 
1466  if (row_pointers != NULL)
1467  info_ptr->valid |= PNG_INFO_IDAT;
1468 }
void png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, int num)
Definition: png.c:442
#define PNG_FREE_ROWS
Definition: png.h:1915
#define png_debug1(l, m, p1)
Definition: pngdebug.h:149
#define PNG_INFO_IDAT
Definition: png.h:888
png_uint_32 valid
Definition: pnginfo.h:61
void png_set_compression_buffer_size ( png_structrp  png_ptr,
png_size_t  size 
)
1473 {
1474  if (png_ptr == NULL)
1475  return;
1476 
1477  if (size == 0 || size > PNG_UINT_31_MAX)
1478  png_error(png_ptr, "invalid compression buffer size");
1479 
1480 # ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1481  if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
1482  {
1483  png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
1484  return;
1485  }
1486 # endif
1487 
1488 # ifdef PNG_WRITE_SUPPORTED
1489  if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
1490  {
1491  if (png_ptr->zowner != 0)
1492  {
1493  png_warning(png_ptr,
1494  "Compression buffer size cannot be changed because it is in use");
1495  return;
1496  }
1497 
1498  if (size > ZLIB_IO_MAX)
1499  {
1500  png_warning(png_ptr,
1501  "Compression buffer size limited to system maximum");
1502  size = ZLIB_IO_MAX; /* must fit */
1503  }
1504 
1505  else if (size < 6)
1506  {
1507  /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
1508  * if this is permitted.
1509  */
1510  png_warning(png_ptr,
1511  "Compression buffer size cannot be reduced below 6");
1512  return;
1513  }
1514 
1515  if (png_ptr->zbuffer_size != size)
1516  {
1517  png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
1518  png_ptr->zbuffer_size = (uInt)size;
1519  }
1520  }
1521 # endif
1522 }
#define PNG_UINT_31_MAX
Definition: png.h:790
PNG_IMPEXP void() png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
#define PNG_IS_READ_STRUCT
Definition: pngpriv.h:557
#define ZLIB_IO_MAX
Definition: pngstruct.h:57
png_uint_32 mode
Definition: pngstruct.h:179
void png_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *list)
Definition: pngwutil.c:440
PNG_IMPEXP void() png_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:40
png_uint_32 zowner
Definition: pngstruct.h:183
unsigned int uInt
Definition: zconf.h:370
void png_set_invalid ( png_const_structrp  png_ptr,
png_inforp  info_ptr,
int  mask 
)
1526 {
1527  if (png_ptr != NULL && info_ptr != NULL)
1528  info_ptr->valid &= ~mask;
1529 }
png_uint_32 valid
Definition: pnginfo.h:61
void png_set_user_limits ( png_structrp  png_ptr,
png_uint_32  user_width_max,
png_uint_32  user_height_max 
)
1537 {
1538  /* Images with dimensions larger than these limits will be
1539  * rejected by png_set_IHDR(). To accept any PNG datastream
1540  * regardless of dimensions, set both limits to 0x7ffffffL.
1541  */
1542  if (png_ptr == NULL)
1543  return;
1544 
1545  png_ptr->user_width_max = user_width_max;
1546  png_ptr->user_height_max = user_height_max;
1547 }
void png_set_chunk_cache_max ( png_structrp  png_ptr,
png_uint_32  user_chunk_cache_max 
)
1552 {
1553  if (png_ptr != NULL)
1554  png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1555 }
void png_set_chunk_malloc_max ( png_structrp  png_ptr,
png_alloc_size_t  user_chunk_malloc_max 
)
1561 {
1562  if (png_ptr != NULL)
1563  png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
1564 }
void png_set_benign_errors ( png_structrp  png_ptr,
int  allowed 
)
1571 {
1572  png_debug(1, "in png_set_benign_errors");
1573 
1574  /* If allowed is 1, png_benign_error() is treated as a warning.
1575  *
1576  * If allowed is 0, png_benign_error() is treated as an error (which
1577  * is the default behavior if png_set_benign_errors() is not called).
1578  */
1579 
1580  if (allowed != 0)
1581  png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN |
1583 
1584  else
1585  png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN |
1587 }
#define PNG_FLAG_APP_WARNINGS_WARN
Definition: pngpriv.h:622
#define png_debug(l, m)
Definition: pngdebug.h:146
png_uint_32 flags
Definition: pngstruct.h:180
#define PNG_FLAG_BENIGN_ERRORS_WARN
Definition: pngpriv.h:621
#define PNG_FLAG_APP_ERRORS_WARN
Definition: pngpriv.h:623
void png_set_check_for_invalid_index ( png_structrp  png_ptr,
int  allowed 
)
1601 {
1602  png_debug(1, "in png_set_check_for_invalid_index");
1603 
1604  if (allowed > 0)
1605  png_ptr->num_palette_max = 0;
1606 
1607  else
1608  png_ptr->num_palette_max = -1;
1609 }
#define png_debug(l, m)
Definition: pngdebug.h:146