~rafalcieslak256/ubuntu/quantal/libpng/build_test

« back to all changes in this revision

Viewing changes to example.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2009-02-21 15:50:52 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090221155052-x0s21xidln6rlvzl
Tags: 1.2.35-1
* New upstream release
  - http://secunia.com/advisories/33970/
    Fix a vulnerability reported by Tavis Ormandy in which
    some arrays of pointers are not initialized prior to using
    "malloc" to define the pointers.
    Closes: #516256
  - http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5907
    The png_check_keyword function in pngwutil.c in libpng, might
    allow context-dependent attackers to set the value of an
    arbitrary memory location to zero via vectors involving
    creation of crafted PNG files with keywords, related to an
    implicit cast of the '\0' character constant to a NULL pointer.
* Don't build libpng3 when binary-indep target is not called.
  Closes: #486415

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#if 0 /* in case someone actually tries to compile this */
3
3
 
4
4
/* example.c - an example of using libpng
5
 
 * Last changed in libpng 1.2.1 December 7, 2001.
 
5
 * Last changed in libpng 1.2.35 [February 14, 2009]
6
6
 * This file has been placed in the public domain by the authors.
7
 
 * Maintained 1998-2007 Glenn Randers-Pehrson
 
7
 * Maintained 1998-2009 Glenn Randers-Pehrson
8
8
 * Maintained 1996, 1997 Andreas Dilger)
9
9
 * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
10
10
 */
204
204
 
205
205
   /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
206
206
   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
207
 
      png_set_gray_1_2_4_to_8(png_ptr);
 
207
      png_set_expand_gray_1_2_4_to_8(png_ptr);
208
208
 
209
209
   /* Expand paletted or RGB images with transparency to full alpha channels
210
210
    * so the data will be available as RGBA quartets.
342
342
   /* The easiest way to read the image: */
343
343
   png_bytep row_pointers[height];
344
344
 
345
 
   for (row = 0; row < height; row++)
346
 
   {
 
345
   /* Clear the pointer array */
 
346
   for (row = 0; row < height; row++)
 
347
      row_pointers[row] = NULL;
 
348
 
 
349
   for (row = 0; row < height; row++)
347
350
      row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,
348
351
         info_ptr));
349
 
   }
350
352
 
351
353
   /* Now it's time to read the image.  One of these methods is REQUIRED */
352
354
#ifdef entire /* Read the entire image in one go */
505
507
 * shown below:
506
508
 */
507
509
   /* Check if row_num is in bounds. */
508
 
   if((row_num >= 0) && (row_num < height))
 
510
   if ((row_num >= 0) && (row_num < height))
509
511
   {
510
512
     /* Get pointer to corresponding row in our
511
513
      * PNG read buffer.
515
517
     /* If both rows are allocated then copy the new row
516
518
      * data to the corresponding row data.
517
519
      */
518
 
     if((old_row != NULL) && (new_row != NULL))
 
520
     if ((old_row != NULL) && (new_row != NULL))
519
521
     png_progressive_combine_row(png_ptr, old_row, new_row);
520
522
   }
521
523
/*
608
610
   /* set up the output control if you are using standard C streams */
609
611
   png_init_io(png_ptr, fp);
610
612
#else no_streams /* I/O initialization method 2 */
611
 
   /* If you are using replacement read functions, instead of calling
 
613
   /* If you are using replacement write functions, instead of calling
612
614
    * png_init_io() here you would call */
613
615
   png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
614
616
      user_IO_flush_function);
637
639
 
638
640
   /* set the palette if there is one.  REQUIRED for indexed-color images */
639
641
   palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
640
 
             * png_sizeof (png_color));
 
642
             * png_sizeof(png_color));
641
643
   /* ... set palette colors ... */
642
644
   png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
643
645
   /* You must not free palette here, because png_set_PLTE only makes a link to
771
773
 
772
774
      /* If you are only writing one row at a time, this works */
773
775
      for (y = 0; y < height; y++)
774
 
      {
775
776
         png_write_rows(png_ptr, &row_pointers[y], 1);
776
 
      }
777
777
   }
778
778
#endif no_entire /* use only one output method */
779
779
 
793
793
      allocated it with malloc() instead of png_malloc(), use free() instead
794
794
      of png_free(). */
795
795
   png_free(png_ptr, palette);
796
 
   palette=NULL;
 
796
   palette = NULL;
797
797
 
798
798
   /* Similarly, if you png_malloced any data that you passed in with
799
799
      png_set_something(), such as a hist or trans array, free it here,
800
800
      when you can be sure that libpng is through with it. */
801
801
   png_free(png_ptr, trans);
802
 
   trans=NULL;
 
802
   trans = NULL;
803
803
 
804
804
   /* clean up after the write, and free any memory allocated */
805
805
   png_destroy_write_struct(&png_ptr, &info_ptr);