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

98 Commits

Author SHA1 Message Date
mohammadmseet-hue
c0ba09ecb4 fix: Prevent integer overflow in rowbytes computation
Cast `row_width` to `size_t` before multiplication when computing
`row_info->rowbytes`, to avoid 32-bit truncation on LP64 systems.

Fix the cast order in `png_do_expand_palette` where the widening
cast was applied after the multiply rather than before it.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-04-06 19:02:41 +03:00
Cosmin Truta
ef37879423 Merge tag 'v1.6.56' into libpng18 2026-03-27 13:44:48 +02:00
Cosmin Truta
1632f041e4 refactor(arm): Replace bit shifts and sizeof with plain expressions
Replace hand-strength-reduced idioms to make the source code easier to
read and to audit:

- Replace `i << 2` with `i * 4`;
- Replace `(i << 1) + i` with `i * 3`;
- Replace `sizeof(png_color)` with 3;
- Replace `sizeof(png_uint_32)` with 4;
- Use `index * CONSTANT` consistently in all stride expressions.

The optimizing compiler will emit identical machine code.

In particular, the expression `sizeof(png_uint_32)` used in this context
was a semantic misnomer: its value should represent bytes per pixel in
the RGBA format, not the size of the underlying integer type.
2026-03-23 17:04:38 +02:00
Cosmin Truta
aba9f18eba fix(arm): Resolve out-of-bounds read/write in NEON palette expansion
Both `png_do_expand_palette_rgba8_neon` and
`png_do_expand_palette_rgb8_neon` advanced in fixed-size chunks without
guarding the final iteration, allowing out-of-bounds reads and writes
when the row width is not a multiple of the chunk size.

Restrict the NEON loop to full chunks only, remove the now-unnecessary
post-loop adjustment, and undo the `*ddp` pre-adjustment before the
pointer handoff to the scalar fallback.

Reported-by: Amemoyoi <Amemoyoi@users.noreply.github.com>
Co-authored-by: Amemoyoi <Amemoyoi@users.noreply.github.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2026-03-21 23:48:49 +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
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
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
69a3e5bfd1 chore: Clean up the error directives
Make the error directives uniformly consistent with one another.
Remove surrounding quotes and trailing punctuation, and rephrase
some of the error messages and some of their associated comments
for either brevity or clarity.
2025-04-25 16:19:30 +03:00
John Bowler
d7d950e8bd [libpng16] chore: Clean up the leading blank lines from all source files
The leading blank lines are apparently an artefact of an older source
control system.  They are not required and they look like accidents,
because starting a source file with a blank line is not a regular habit
of software developers nowadays.

This is a cherry-pick of commit 37cc20add8
from branch 'libpng18'.

Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2024-10-11 11:51:04 +03:00
John Bowler
37cc20add8 chore: Clean up the leading blank lines from all source files
The leading blank lines are apparently an artefact of an older source
control system.  They are not required and they look like accidents,
because starting a source file with a blank line is not a regular habit
of software developers nowadays.

Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2024-10-11 11:24:56 +03:00
John Bowler
ed689982c2 Update the support for target-specific code
The change removes the need for build configuration of target specific
code such as SIMD enhancements.

The extensible framework is based on checks in the new file named
pngtarget.h and allows per target description of requirements and
capabilities using macros with the prefix PNG_TARGET_.  These macros are
interpreted by the core libpng code in a target independent way.

The PNG_TARGET_ prefixed macros describe the target specific
implementation and document how to include it.  The actual inclusion of
the code is done, at present, by a single target independent core file
named pngsimd.c.

This approach ensures that no special configuration in the build system
is required on any system.  It is not required on a system which is
compiling for the build host where we can reasonably assume that the
compiler is correctly set up.  Neither is it required for cross builds
so long as the toolchain is correctly set up.  In this case the
toolchain means the cross build system and any ancilliary programs it
requires.

More details of the implementation are included in the source files
named pngtarget.h and pngsimd.c.  These files document in C comments how
additional target specific code might be added.

The changes consist primarily of movement of target specific code from
the core libpng source files to the existing target specific
subdirectories such as the ones named intel and arm.  This isolates the
code into the corresponding subdirectory and eliminates the requirement
for changes across the libpng structure.

As part of this the ARM processor NEON instruction set specific palette
to RGB code has been generalised to allow implementation in other
architectures.  The resultant updated version of the original (ARM Ltd)
implementation has been moved to the subdirectory named arm.

In addition some selected changes have been included to allow testing
with higher warning levels than the typical compiler defaults.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2024-10-10 21:28:34 +03:00
John Bowler
d3cf9b6e22 [libpng16] arm: Use png_aligncastconst for an upcast in Neon intrinsics
This changes the arm/palette_neon_intrinsics.c code from using a bare
cast to using the portable macro `png_aligncastconst`.  This removes
the `-Wcast-align` warning.

The cast is safe because the pointer was allocated by `malloc(1024)`,
and `malloc` is required to return a pointer with sufficient alignment
for anything the allocation can accomodate.

Nevertheless, this is a quick and dirty fix; the use of `png_bytep` in
the `png_struct` declaration of the pointer is machine-specific.  Other
architectures may need different types and, consequently, the only type
which is portable to other companies' CPUs is `(void*)`.

This is a cherry-pick of commit a604b12c11
from branch 'libpng18'.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2024-09-27 16:54:09 +03:00
John Bowler
a604b12c11 arm: Use png_aligncastconst for an upcast in Neon intrinsics
This changes the arm/palette_neon_intrinsics.c code from using a bare
cast to using the portable macro `png_aligncastconst`.  This removes
the `-Wcast-align` warning.

The cast is safe because the pointer was allocated by `malloc(1024)`,
and `malloc` is required to return a pointer with sufficient alignment
for anything the allocation can accomodate.

Nevertheless, this is a quick and dirty fix; the use of `png_bytep` in
the `png_struct` declaration of the pointer is machine-specific.  Other
architectures may need different types and, consequently, the only type
which is portable to other companies' CPUs is `(void*)`.

Reviewed-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2024-09-27 13:16:28 +03:00
Cosmin Truta
e4a31f024b arm: Add a placeholder file in lieu of the former filter_neon.S
In the previous commit 9e538750d9
we removed the obsolete assembler implementation `filter_neon.S`.

In this commit we add a stand-in for the original file, restoring
the original source tree structure, for the benefit of continuing
hassle-free libpng source upgrades in the 1.6.x line.
2024-06-17 15:28:38 +03:00
Ross Burton
9e538750d9 arm: Remove obsolete assembler implementation filter_neon.S
This file contains hand-coded assembler implementations of the filter
functions for 32-bit Arm platforms.  These are only used when the
compiler doesn't support neon intrinsics (added to GCC 4.3 in 2008) or
is exactly GCC 4.5.4 (released 2012), both of which are sufficiently
unlikely to be true that it's fair to say the assembler is no longer
used.

This commit deletes filter_neon.S and removes the now obsolete
preprocessor logic in pngpriv.h.

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2024-06-15 23:09:34 +03:00
Cosmin Truta
b8ca9108ac arm: Add a compile-time assertion about PNG_ARM_NEON_CHECK_SUPPORTED
Following up on the previous commit by Martin Storsjö:

If the availability of ARM Neon is not only known at compile time,
but also expected by the compiler's target architecture, there should
be no further need for a run-time check. In fact, such a check would
be counter-productive.
2022-10-12 12:42:09 +03:00
Cosmin Truta
8c542ad9df arm: Do not allow PNG_ARM_NEON_CHECK_SUPPORTED on ARM64
ARM Neon is expected to be unconditionally available on ARM64.
Issue an #error if PNG_ARM_NEON_CHECK_SUPPORTED is defined on an
ARM64-based platform.

For the plain ARM platforms where ARM Neon checking is not yet
implemented, issue a slightly more descriptive #error, including
a suggested course of action.
2022-09-14 00:42:48 +03:00
Cosmin Truta
2abaf81e0f arm: Avoid compiler warnings in palette_neon_intrinsics.c
Use correct int types; wrap PNG_UNUSED around unused arguments.
2022-09-14 00:12:11 +03:00
Dan Field
403422674d Remove obsolete/incorrect __LLVM,__asm section
Contributed-by: Dan Field <dnfield@google.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2022-09-05 13:46:00 +03:00
Dan Field
a6fc80300f Add an __LLVM,__asm section for clang builds on ARM 2020-05-17 20:00:46 -04:00
Ryan VanderMeulen
386707c6d1 arm: Use <arm_neon.h> when compiling aarch64 intrinsics with clang-cl
MSVC's <arm64_neon.h> header contains cl.exe intrinsics that are not
recognized by clang-cl.

Contributed-by: Ryan VanderMeulen <rvandermeulen@mozilla.com>
Contributed-by: Mike Klein <mtklein@google.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2019-04-24 23:57:14 -04:00
Cosmin Truta
216387f6f7 arm: Move a png_debug statement to its correct place
It should be placed immediately after all variable declarations.
2019-04-22 23:56:57 -04:00
Cosmin Truta
82ae623ec9 arm: Rename all functions to the pattern png_*_neon; add debug traces 2019-03-31 09:44:45 -04:00
Cosmin Truta
70d122aac4 Fix a memory leak in the riffled palette optimization on ARM; refactor
Move deallocation of riffled_palette from png_write_destroy to
png_read_destroy. The reader (not the writer) is the owner of
riffled_palette.

Move allocation and initialization of riffled_palette from
png_do_read_transformations to png_init_palette_transformations.

Allow riffled_palette inside png_struct only if the ARM Neon
optimizations are enabled.

Rename png_riffle_palette_rgba to png_riffle_palette_rgba8, etc.,
to better indicate the strict applicability of these routines.

Fix an unused parameter warning in the build configurations where
riffled palette optimization is not enabled.

Fix indentation.
2019-02-03 19:51:18 -05:00
Cosmin Truta
94429a335b Remove the "last changed" version information from source comments 2018-09-04 00:58:55 -04:00
Cosmin Truta
1ceaa83a84 Fix the build with MSVC ARM64 2018-09-04 00:53:38 -04:00
Cosmin Truta
b66ed71131 Restore the ANSI C compliance after adding the ARM optimization
Also apply style and formatting fixes
2018-09-04 00:15:30 -04:00
Richard Townsend
7734cda20c Optimize png_do_expand_palette for ARM
ARM-specific optimization processes 8 or 4 pixels at once.
Improves performance by around 10-22% on a recent ARM Chromebook.
2018-09-04 00:04:58 -04:00
Cosmin Truta
2fc5ddff18 Restore the ANSI C compliance after applying the MSVC ARM64 fix 2018-09-03 22:27:45 -04:00
zzzzRuby
8033c96f32 Fix build errors with MSVC ARM64
(Contributed by Zhijie Liang)
2018-09-03 22:26:06 -04:00
Glenn Randers-Pehrson
df7e9dae0c [libpng16] Imported from libpng-1.6.32.tar 2017-08-24 16:39:02 -05:00
Glenn Randers-Pehrson
b73c891891 [libpng16] Bump version to 1.6.32beta01 2017-07-27 14:18:21 -05:00
Glenn Randers-Pehrson
9fcb846402 [libpng16] Imported from libpng-1.6.31.tar 2017-07-27 05:27:17 -05:00
Glenn Randers-Pehrson
77417b8ea0 [libpng16] Imported from libpng-1.6.31beta01.tar 2017-07-05 06:45:46 -05:00
Glenn Randers-Pehrson
eed9efec4e [libpng16] Added special case for FreeBSD in arm/filter_neon.S (Maya Rashish). 2017-07-05 05:36:59 -05:00
Glenn Randers-Pehrson
428f5ddabd [libpng16] Bump version to 1.6.24beta01 2016-06-11 14:10:03 -05:00
Glenn Randers-Pehrson
ed6db9d86b [libpng16] Imported from libpng-1.6.23.tar 2016-06-09 06:49:42 -05:00
Glenn Randers-Pehrson
4e34fd3b8a [libpng16] Bump version to 1.6.23beta01 2016-05-27 19:48:24 -05:00
Glenn Randers-Pehrson
ac43a87820 [libpng16] Imported from libpng-1.6.22.tar 2016-05-26 07:25:14 -05:00
Glenn Randers-Pehrson
da9d1d7aa6 [libpng16] Added pngdebug() statements to the new intel code and the arm code. 2016-02-19 14:58:59 -06:00
Glenn Randers-Pehrson
018b4fccb9 [libpng16] Happy New Year! Update copyright year. 2014-12-31 18:45:23 -06:00
Glenn Randers-Pehrson
ecd074945c [libpng16] Bump version to 1.6.17beta01 2014-12-21 22:56:42 -06:00
Glenn Randers-Pehrson
88dd30b232 [libpng16] Imported from libpng-1.6.16.tar 2014-12-21 21:53:00 -06:00
Glenn Randers-Pehrson
7c5d037032 [libpng16] Update arm/*.c to libpng coding style. 2014-11-29 17:04:35 -06:00
Glenn Randers-Pehrson
ee16fc4a6f [libpng16] Added ".align 2" to arm/filter_neon.S to support old GAS assemblers
that don't do alignment correctly.
2014-11-29 16:27:27 -06:00
Glenn Randers-Pehrson
26a94ab06f [libpng16] Imported from libpng-1.6.13rc01.tar 2014-08-13 22:08:01 -05:00
Glenn Randers-Pehrson
212fd5745d [libpng16] Bump version to 1.6.13beta01 2014-06-11 21:13:33 -05:00
Glenn Randers-Pehrson
e429c66cea [libpng16] Imported from libpng-1.6.12.tar 2014-06-11 20:41:51 -05:00