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

« back to all changes in this revision

Viewing changes to libpng.txt

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2005-10-03 20:18:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051003201843-cv2i5v7no1ff08tx
Tags: 1.2.8rel-5
* drop_pass_width.patch: don't export png_pass_width, it's absolutely 
  unnecessary.
* libpng12-0.shlibs: downgrade the shlibs accordingly
  (closes: #331383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
libpng.txt - A description on how to use and modify libpng
2
2
 
3
 
 libpng version 1.0.18 - December 3, 2004
 
3
 libpng version 1.2.8 - December 3, 2004
4
4
 Updated and distributed by Glenn Randers-Pehrson
5
5
 <glennrp at users.sourceforge.net>
6
6
 Copyright (c) 1998-2004 Glenn Randers-Pehrson
303
303
 
304
304
    png_set_read_status_fn(png_ptr, read_row_callback);
305
305
 
 
306
Width and height limits
 
307
 
 
308
The PNG specification allows the width and height of an image to be as
 
309
large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
 
310
Since very few applications really need to process such large images,
 
311
we have imposed an arbitrary 1-million limit on rows and columns.
 
312
Larger images will be rejected immediately with a png_error() call. If
 
313
you wish to override this limit, you can use
 
314
 
 
315
   png_set_user_limits(png_ptr, width_max, height_max);
 
316
 
 
317
to set your own limits, or use width_max = height_max = 0x7fffffffL
 
318
to allow all valid dimensions (libpng may reject some very large images
 
319
anyway because of potential buffer overflow conditions).
 
320
 
 
321
You should put this statement after you create the PNG structure and
 
322
before calling png_read_info(), png_read_png(), or png_process_data().
 
323
If you need to retrieve the limits that are being applied, use
 
324
 
 
325
   width_max = png_get_user_width_max(png_ptr);
 
326
   height_max = png_get_user_height_max(png_ptr);
 
327
 
306
328
Unknown-chunk handling
307
329
 
308
330
Now you get to set the way the library processes unknown chunks in the
745
767
For example, 4 bit/pixel paletted or grayscale data will be returned
746
768
2 pixels/byte with the leftmost pixel in the high-order bits of the
747
769
byte, unless png_set_packing() is called.  8-bit RGB data will be stored
748
 
in RGB RGB RGB format unless png_set_filler()
 
770
in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
749
771
is called to insert filler bytes, either before or after each RGB triplet.
750
772
16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
751
773
byte of the color value first, unless png_set_strip_16() is called to
753
775
png_set_add alpha() is called to insert filler bytes, either before or
754
776
after each RRGGBB triplet.  Similarly, 8-bit or 16-bit grayscale data can
755
777
be modified with
756
 
png_set_filler() or png_set_strip_16().
 
778
png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
757
779
 
758
780
The following code transforms grayscale images of less than 8 to 8 bits,
759
781
changes paletted images to RGB, and adds a full alpha channel if there is
838
860
opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
839
861
will generate RGBA pixels.
840
862
 
 
863
Note that png_set_filler() does not change the color type.  If you want
 
864
to do that, you can add a true alpha channel with
 
865
 
 
866
    if (color_type == PNG_COLOR_TYPE_RGB ||
841
867
           color_type == PNG_COLOR_TYPE_GRAY)
 
868
    png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
 
869
 
 
870
where "filler" contains the alpha value to assign to each pixel.
 
871
This function was added in libpng-1.2.7.
 
872
 
842
873
If you are reading an image with an alpha channel, and you need the
843
874
data as ARGB instead of the normal PNG format RGBA:
844
875
 
2678
2709
having level = 0 will be printed.  There aren't any such statements in
2679
2710
this version of libpng, but if you insert some they will be printed.
2680
2711
 
2681
 
VI.  MNG support
 
2712
VI.  Runtime optimization
 
2713
 
 
2714
A new feature in libpng 1.2.0 is the ability to dynamically switch between
 
2715
standard and optimized versions of some routines.  Currently these are
 
2716
limited to three computationally intensive tasks when reading PNG files:
 
2717
decoding row filters, expanding interlacing, and combining interlaced or
 
2718
transparent row data with previous row data.  Currently the optimized
 
2719
versions are available only for x86 (Intel, AMD, etc.) platforms with
 
2720
MMX support, though this may change in future versions.  (For example,
 
2721
the non-MMX assembler optimizations for zlib might become similarly
 
2722
runtime-selectable in future releases, in which case libpng could be
 
2723
extended to support them.  Alternatively, the compile-time choice of
 
2724
floating-point versus integer routines for gamma correction might become
 
2725
runtime-selectable.)
 
2726
 
 
2727
Because such optimizations tend to be very platform- and compiler-dependent,
 
2728
both in how they are written and in how they perform, the new runtime code
 
2729
in libpng has been written to allow programs to query, enable, and disable
 
2730
either specific optimizations or all such optimizations.  For example, to
 
2731
enable all possible optimizations (bearing in mind that some "optimizations"
 
2732
may actually run more slowly in rare cases):
 
2733
 
 
2734
    #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
 
2735
       png_uint_32 mask, flags;
 
2736
 
 
2737
       flags = png_get_asm_flags(png_ptr);
 
2738
       mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
 
2739
       png_set_asm_flags(png_ptr, flags | mask);
 
2740
    #endif
 
2741
 
 
2742
To enable only optimizations relevant to reading PNGs, use PNG_SELECT_READ
 
2743
by itself when calling png_get_asm_flagmask(); similarly for optimizing
 
2744
only writing.  To disable all optimizations:
 
2745
 
 
2746
    #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
 
2747
       flags = png_get_asm_flags(png_ptr);
 
2748
       mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
 
2749
       png_set_asm_flags(png_ptr, flags & ~mask);
 
2750
    #endif
 
2751
 
 
2752
To enable or disable only MMX-related features, use png_get_mmx_flagmask()
 
2753
in place of png_get_asm_flagmask().  The mmx version takes one additional
 
2754
parameter:
 
2755
 
 
2756
    #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
 
2757
       int selection = PNG_SELECT_READ | PNG_SELECT_WRITE;
 
2758
       int compilerID;
 
2759
 
 
2760
       mask = png_get_mmx_flagmask(selection, &compilerID);
 
2761
    #endif
 
2762
 
 
2763
On return, compilerID will indicate which version of the MMX assembler
 
2764
optimizations was compiled.  Currently two flavors exist:  Microsoft
 
2765
Visual C++ (compilerID == 1) and GNU C (a.k.a. gcc/gas, compilerID == 2).
 
2766
On non-x86 platforms or on systems compiled without MMX optimizations, a
 
2767
value of -1 is used.
 
2768
 
 
2769
Note that both png_get_asm_flagmask() and png_get_mmx_flagmask() return
 
2770
all valid, settable optimization bits for the version of the library that's
 
2771
currently in use.  In the case of shared (dynamically linked) libraries,
 
2772
this may include optimizations that did not exist at the time the code was
 
2773
written and compiled.  It is also possible, of course, to enable only known,
 
2774
specific optimizations; for example:
 
2775
 
 
2776
    #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
 
2777
       flags = PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  \
 
2778
             | PNG_ASM_FLAG_MMX_READ_INTERLACE    \
 
2779
             | PNG_ASM_FLAG_MMX_READ_FILTER_SUB   \
 
2780
             | PNG_ASM_FLAG_MMX_READ_FILTER_UP    \
 
2781
             | PNG_ASM_FLAG_MMX_READ_FILTER_AVG   \
 
2782
             | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
 
2783
       png_set_asm_flags(png_ptr, flags);
 
2784
    #endif
 
2785
 
 
2786
This method would enable only the MMX read-optimizations available at the
 
2787
time of libpng 1.2.0's release, regardless of whether a later version of
 
2788
the DLL were actually being used.  (Also note that these functions did not
 
2789
exist in versions older than 1.2.0, so any attempt to run a dynamically
 
2790
linked app on such an older version would fail.)
 
2791
 
 
2792
To determine whether the processor supports MMX instructions at all, use
 
2793
the png_mmx_support() function:
 
2794
 
 
2795
    #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
 
2796
       mmxsupport = png_mmx_support();
 
2797
    #endif
 
2798
 
 
2799
It returns -1 if MMX support is not compiled into libpng, 0 if MMX code
 
2800
is compiled but MMX is not supported by the processor, or 1 if MMX support
 
2801
is fully available.  Note that png_mmx_support(), png_get_mmx_flagmask(),
 
2802
and png_get_asm_flagmask() all may be called without allocating and ini-
 
2803
tializing any PNG structures (for example, as part of a usage screen or
 
2804
"about" box).
 
2805
 
 
2806
The following code can be used to prevent an application from using the
 
2807
thread_unsafe features, even if libpng was built with PNG_THREAD_UNSAFE_OK
 
2808
defined:
 
2809
 
 
2810
#if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) \
 
2811
  && defined(PNG_THREAD_UNSAFE_OK)
 
2812
    /* Disable thread-unsafe features of pnggccrd */
 
2813
    if (png_access_version() >= 10200)
 
2814
    {
 
2815
      png_uint_32 mmx_disable_mask = 0;
 
2816
      png_uint_32 asm_flags;
 
2817
 
 
2818
      mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  \
 
2819
                          | PNG_ASM_FLAG_MMX_READ_FILTER_SUB   \
 
2820
                          | PNG_ASM_FLAG_MMX_READ_FILTER_AVG   \
 
2821
                          | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
 
2822
      asm_flags = png_get_asm_flags(png_ptr);
 
2823
      png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);
 
2824
    }
 
2825
#endif
 
2826
 
 
2827
For more extensive examples of runtime querying, enabling and disabling
 
2828
of optimized features, see contrib/gregbook/readpng2.c in the libpng
 
2829
source-code distribution.
 
2830
 
 
2831
VII.  MNG support
2682
2832
 
2683
2833
The MNG specification (available at http://www.libpng.org/pub/mng) allows
2684
2834
certain extensions to PNG for PNG images that are embedded in MNG datastreams.
2703
2853
them.  You may wish to consider using libmng (available at
2704
2854
http://www.libmng.com) instead.
2705
2855
 
2706
 
VII.  Changes to Libpng from version 0.88
 
2856
VIII.  Changes to Libpng from version 0.88
2707
2857
 
2708
2858
It should be noted that versions of libpng later than 0.96 are not
2709
2859
distributed by the original libpng author, Guy Schalnat, nor by
2752
2902
 
2753
2903
   png_uint_32 application_vn = PNG_LIBPNG_VER;
2754
2904
 
2755
 
VIII. Y2K Compliance in libpng
 
2905
IX. Y2K Compliance in libpng
2756
2906
 
2757
2907
December 3, 2004
2758
2908
 
2760
2910
an official declaration.
2761
2911
 
2762
2912
This is your unofficial assurance that libpng from version 0.71 and
2763
 
upward through 1.0.18 are Y2K compliant.  It is my belief that earlier
 
2913
upward through 1.2.8 are Y2K compliant.  It is my belief that earlier
2764
2914
versions were also Y2K compliant.
2765
2915
 
2766
2916
Libpng only has three year fields.  One is a 2-byte unsigned integer that