1
0
mirror of https://github.com/glennrp/libpng.git synced 2026-10-24 08:39:18 +03:00

752 Commits

Author SHA1 Message Date
Cosmin Truta
0eb0c29eca Merge tag 'v1.6.59' into branch 'libpng18' into develop 2026-09-30 11:59:55 +03:00
Chris Lilley
d1d0abeffe Merge pull request #759 from aYukiSekiguchi/fix_hIST_chunk_position
Fix hIST chunk position to match W3C specification
2026-06-26 18:37:31 +03:00
Cosmin Truta
d2e19e86a0 Merge tag 'v1.6.58' into branch 'libpng18' into develop 2026-04-15 22:01:50 +03:00
Cosmin Truta
614ab644f8 Merge tag 'v1.6.58' into libpng18 2026-04-15 22:01:50 +03:00
Cosmin Truta
571a895143 test: Ensure the palette sync follows the gamma correction
This tests commit d4c4e49eb5.
2026-04-15 19:43:01 +03:00
Cosmin Truta
4543ed7c00 Merge tag 'v1.6.57' into branch 'libpng18' into develop 2026-04-13 11:45:26 +03:00
Cosmin Truta
306b1a1517 Merge tag 'v1.6.57' into libpng18 2026-04-13 11:45:26 +03:00
Cosmin Truta
55d20aaa32 fix: Handle getter-to-setter aliasing in append-style chunk setters
Apply the same class of robustness fix from the previous commit to
`png_set_text`, `png_set_sPLT` and `png_set_unknown_chunks`. These
append-style setters used `png_realloc_array` to grow the internal
array, then freed the old array before copying from the caller's
input. If the caller's pointer was obtained from the corresponding
getter, it aliased the freed array.

The fix defers the freeing of the old array until after the copy loop.

Also extend the pnggetset regression test to cover all three setters.
2026-03-30 17:43:05 +03:00
Cosmin Truta
398cbe3df0 fix: Handle self-referencing pointers in getter-to-setter aliasing
Apply a robustness fix for a caller-side API usage pattern involving
the getters and the setters for PLTE, tRNS, and hIST.

Passing a pointer returned by the PLTE, tRNS, or hIST getters back
into the corresponding setters used to cause the setters to read from
a stale pointer. The fix consists in snapshotting the caller's data
into a stack-local buffer before freeing the old internal storage.

Fixes pnggroup/libpng#836

Reported-by: Iv4n <Iv4n550@noreply.github.com>
2026-03-30 17:35:30 +03:00
Cosmin Truta
eb1662b428 Merge tag 'v1.6.56' into branch 'libpng18' into develop 2026-03-27 13:44:48 +02:00
Cosmin Truta
ef37879423 Merge tag 'v1.6.56' into libpng18 2026-03-27 13:44:48 +02:00
Philippe Antoine
dc1732e37a oss-fuzz: Restrict transformations_fuzzer to transformations
And let the other targets focus on the other parts.
2026-03-25 17:22:24 +02:00
Cosmin Truta
0126d4293e refactor(test): Avoid undefined pointer arithmetic in pngstest.c
Guard the pointer advance with `y+1 < height` inside the function
`compare_two_images` to skip this advance on the last iteration.

With a negative stride, the unconditional `row += stride` in the
for-statement produced a pointer before the allocated object on
the final iteration. Standard C permits one-after-end but not
one-before-beginning; this is undefined behavior regardless of
whether the pointer is dereferenced or not.
2026-03-23 22:45:09 +02:00
Cosmin Truta
98019f6e70 test: Add negative-stride test coverage to pngstest
Add the option --negative-stride to pngstest. When set, the row stride
is negated after buffer allocation but before calling the library, so
that `png_image_finish_read` and `png_image_write_to_file` exercise the
bottom-up (negative stride) code paths.

Add CI targets for the CMake build and for the configure build:

 - pngstest-negative-stride:
   Bottom-up layout with images covering colormapped, truecolor, alpha,
   8-bit, 16-bit, and short-height paths.
 - pngstest-negative-stride-extra:
   Same with --stride-extra 7 for non-aligned padding with bottom-up
   layout.

Note: the interlaced pngsuite images (`ibasn*.png`) are incompatible
with pngstest's format conversion comparison framework, so the
`png_image_read_direct_scaled` path (interlaced 16-to-8 conversion) is
not exercised by this test. A dedicated test for that path will require
interlaced images generated with the correct gamma properties for
pngstest's comparison logic, which is TODO.
2026-03-23 20:41:12 +02:00
Cosmin Truta
0c37b8fbff oss-fuzz: Fix indentation and rephrase comments in the build script
Co-authored-by: Bob Friesenhahn <bobjfriesenhahn@gmail.com>
2026-03-09 17:55:16 +02:00
Philippe Antoine
753fc9980a oss-fuzz: Build the nalloc variants only for the fuzzers that use nalloc 2026-03-09 17:24:17 +02:00
Philippe Antoine
e1fa87e72e oss-fuzz: Rename _nalloc to @nalloc to match the fuzztests naming 2026-03-09 17:24:17 +02:00
Philippe Antoine
c0822817b8 oss-fuzz: Use bash in the nalloc wrapper script 2026-03-09 17:24:17 +02:00
OwenSanzas
905e1f85ba oss-fuzz: Fix API misuse in the readapi fuzzer
Replace the calls to `png_set_scale_16`, `png_set_packing` and
`png_set_expand`, which were incorrectly combined with
`png_read_png(..., PNG_TRANSFORM_IDENTITY, ...)`, with the equivalent
`PNG_TRANSFORM_*` flags passed directly to `png_read_png`.

The libpng manual states that applications must use transforms, and not
call any `png_set_*` transform functions when they use `png_read_png`.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-03-09 11:56:10 +02:00
OwenSanzas
2d899901da oss-fuzz: Fix memory leaks and API misuse in the transformations fuzzer
- Fix row buffer leak: the row buffer, allocated after `setjmp`, was
  not freed when `png_read_row` triggered `longjmp`. Declare `row` as
  volatile before `setjmp` and free it in the error handler. This fixes
  a LeakSanitizer false positive that prevents the fuzzer from starting.
- Fix palette buffer leak (same pattern as the row buffer leak):
  declare `palette` as volatile before `setjmp` and free it in the
  error handler.
- Fix API misuse: replace `png_set_*` calls before `png_read_png` with
  `PNG_TRANSFORM_*` flags.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-03-09 11:32:06 +02:00
Philippe Antoine
62f9a9069f oss-fuzz: Fix build.sh for/if
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-02-13 20:17:41 +02:00
THE-Spellchecker
8d245089d1 Fix typographical errors
This is a cherry-pick of commit 0094fdbf37
from branch 'libpng18'.

Co-authored-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-02-13 18:48:22 +02:00
THE-Spellchecker
0094fdbf37 Fix typographical errors
Co-authored-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-02-13 18:30:34 +02:00
Cosmin Truta
d54127e3db refactor: Clean up pointer variable declarations
Split compound declarations of pointer variables for improved clarity.

Rename local loop boundary variables, remove their sterile const
qualifiers, and reorder their declarations to improve local cohesion.

This is a cherry-pick of commit 1ebf432e85
from branch 'libpng18'.
2026-02-11 21:17:47 +02:00
Cosmin Truta
e0dbfd4b56 refactor: Clean up the redundant top-level const qualifiers
Remove the top-level const qualifiers from local variables and from
function parameters passed by value. These qualifiers only constrain
the local object within the function body: they neither affect function
signatures, nor constrain callers, nor protect any shared state.

Throughout the libpng codebase we apply const only where it
meaningfully constrains objects beyond the immediate scope, such as
true constants and pointed-to objects.

This is a cherry-pick of commit e973362b8b
from branch 'libpng18'.
2026-02-11 21:08:00 +02:00
Philippe Antoine
b72e38c08b oss-fuzz: Restrict the nalloc build to libfuzzer
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-02-09 20:48:12 +02:00
Cosmin Truta
09cf01d91e Merge tag 'v1.6.54' into branch 'libpng18' into develop 2026-02-06 21:19:42 +02:00
Cosmin Truta
96c78de6d5 Merge tag 'v1.6.54' into libpng18 2026-02-06 21:19:42 +02:00
Cosmin Truta
f88784b357 chore(oss-fuzz): Fix the lint errors 2026-01-12 22:18:46 +02:00
Philippe Antoine
25ec74f928 oss-fuzz: Add three targets
From https://github.com/pnggroup/libpng/issues/764

Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-01-12 11:41:09 +02:00
Philippe Antoine
7a77762e6d oss-fuzz: Replace unicode space with ascii space
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-01-12 11:41:09 +02:00
Philippe Antoine
296965f0e0 oss-fuzz: Disable nalloc with memory sanitizer
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-01-12 11:41:09 +02:00
Cosmin Truta
cf155de014 fix: Remove incorrect truncation casts from png_write_image_*
The type of the row stride (`display->row_bytes`) is ptrdiff_t. Casting
to png_uint_16 before division will truncate large strides, causing
incorrect pointer arithmetic for images exceeding 65535 bytes per row.
For bottom-up images (negative stride), the truncation also corrupts
the sign, advancing the row pointer forward instead of backward.

Remove the erroneous casts and let the compiler handle the pointer
arithmetic correctly. Also replace `sizeof (png_uint_16)` with 2.

Add regression test via `pngstest --stride-extra N` where N > 32767
triggers the affected code paths.

A NOTE ABOUT HISTORY:
The original code in libpng 1.5.6 (2011) had no such casts. They were
introduced in libpng 1.6.26 (2016), likely to silence compiler warnings
on 16-bit systems where the cast would be a no-op. On 32/64-bit systems
the cast truncates the strides above 65535 and corrupts the negative
strides.
2026-01-10 15:20:18 +02:00
Cosmin Truta
54c127584f chore: Tidy up whitespace in declarations and definitions
This is a cherry-pick of commit caa0c733f3
from branch 'libpng18'.
2025-12-08 17:57:47 +02:00
Philippe Antoine
c225b7d32b oss-fuzz: Use the nalloc fuzz target
Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2025-12-05 20:33:02 +02:00
Cosmin Truta
c2680c9090 Merge tag 'v1.6.52' into branch 'libpng18' into develop 2025-12-05 11:01:35 +02:00
Philippe Antoine
5c7d02d73b oss-fuzz: Add allocation failure fuzzing via nalloc
Integrate nalloc fuzzing to systematically test error handling paths
when memory allocations fail. This technique previously found a memory
leak in pCAL chunk handling and is already in production use via
OSS-Fuzz on libwebp and libssh.

This is enabled via the `_nalloc` target suffix or the `NALLOC_FREQ`
environment variable.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2025-12-03 20:49:47 +02:00
Chris Lilley
0441becac5 Merge pull request #745 from hmaarrfk/require_zlib_1260
Require zlib 1.2.8 -- shed maintenance
2025-12-03 09:26:30 -05:00
Cosmin Truta
a532f48615 Merge tag 'v1.6.51' into branch 'libpng18' into develop 2025-11-24 20:58:17 +02:00
Cosmin Truta
a199c21e9c refactor: Clean up remaining uses of deprecated pointer typedefs 2025-11-24 15:30:14 +02:00
Yuki Sekiguchi
c2831cb0e6 Add test cases for hIST chunk 2025-11-20 17:06:23 +09:00
Cosmin Truta
1ebf432e85 refactor: Clean up pointer variable declarations
Split compound declarations of pointer variables for improved clarity.

Rename local loop boundary variables, remove their sterile const
qualifiers, and reorder their declarations to improve local cohesion.
2025-11-07 11:53:04 +02:00
Mark Harfouche
c7ca4d432a Require zlib 1.2.8 -- shed maintenance
There are some proposals to move to a new zlib backend.

My first step in writing a patch for this was to shed some of the
compatibility if statements.

Zlib 1.2.8 was release in 2013 according to the archive history
https://zlib.net/fossils/

I think that 12 years is pretty generous and should help shed some mental
load
2025-11-03 17:53:38 -05:00
Cosmin Truta
e973362b8b refactor: Clean up the redundant top-level const qualifiers
Remove the top-level const qualifiers from local variables and from
function parameters passed by value. These qualifiers only constrain
the local object within the function body: they neither affect function
signatures, nor constrain callers, nor protect any shared state.

Throughout the libpng codebase we apply const only where it
meaningfully constrains objects beyond the immediate scope, such as
true constants and pointed-to objects.
2025-11-03 17:44:30 +02:00
Cosmin Truta
f395f18553 Fix the placement of top-level volatile qualifiers
In the previous commits

- "refactor: Replace deprecated pointer typedefs (part 1)"
- "refactor: Replace deprecated pointer typedefs (part 2)"

the volatile qualifiers in the rewritten declarations were mistakenly
placed on the left side of declaration types, effectively making them
bottom-level. (Oopsie!)

Move these qualifiers to the right side, restoring their intended
top-level status.
2025-11-03 11:01:39 +02:00
Cosmin Truta
d9e9c6d3a0 refactor: Replace deprecated pointer typedefs (part 2)
Following up on commit 7c67f70da1:

Replace 22 deprecated pointer typedefs with their underlying types.
The typedefs replaced are:

1. Core structure types:
   - png_structp, png_structrp, png_structpp and const variants
   - png_infop, png_inforp, png_infopp and const variants

2. Utility structure types:
   - png_row_infop, png_row_infopp
   - png_imagep, png_imagepp
   - png_controlp

3. Color structure types:
   - png_colorp, png_colorpp and const variants
   - png_color_8p, png_color_8pp and const variants
   - png_color_16p, png_color_16pp and const variants

4. Text and time structure types:
   - png_textp, png_textpp and const variants
   - png_timep, png_timepp and const variants

5. Chunk structure types:
   - png_unknown_chunkp, png_unknown_chunkpp and const variants
   - png_sPLT_tp, png_sPLT_tpp and const variants
   - png_sPLT_entryp, png_sPLT_entrypp and const variants

6. Internal types:
   - png_compression_bufferp
   - png_dsortp, png_dsortpp

Remove all remaining uses of spurious PNG_RESTRICT qualifiers.
Non-aliasing has already been guaranteed by the type-based aliasing
rules combined with the libpng usage pattern of a single pointer per
type.

Update the user manual accordingly.

This completes the systematic replacement of deprecated pointer
typedefs across the entire libpng codebase. The typedef declarations
remain in png.h for backward compatibility, marked as deprecated.

Reviewed-by: Chris Blume <ProgramMax@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2025-11-03 10:30:49 +02:00
Cosmin Truta
7c67f70da1 refactor: Replace deprecated pointer typedefs (part 1)
Following up on commit ddce3ff853:

1. Replace 28 deprecated pointer typedefs with their underlying types.
   The typedefs replaced are:
   - Basic: png_voidp, png_charp and const variants
   - Byte: png_bytep, png_const_bytep, png_bytepp
   - Numeric:
     - Integer: 16/32-bit integer pointer variants
     - Fixed-point: png_fixed_point_p and variants
     - Floating-point: png_doublep and variants

2. Remove a spurious PNG_RESTRICT qualifier. Non-aliasing has already
   been guaranteed by the type-based aliasing rules.

3. Update the user manual accordingly.

Reviewed-by: Chris Blume <ProgramMax@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2025-10-29 09:20:20 +02:00
Cosmin Truta
caa0c733f3 chore: Tidy up whitespace in declarations and definitions
Prepare a clean and consistent baseline for the upcoming refactoring.
2025-10-24 22:21:39 +03:00
Cosmin Truta
99230a0368 refactor: Delete conditional compilation for libpng 1.6.0 or earlier
This is a cherry-pick of commit 5ff29c03bb
from branch 'libpng18'
2025-09-03 21:18:33 +03:00
Cosmin Truta
5ff29c03bb refactor: Delete conditional compilation for libpng 1.6.0 or earlier 2025-09-03 21:18:33 +03:00