A heap-buffer overflow occurs during the image saving process within the DumpScreen2RGB function in gif2rgb.c, specifically between lines 321 and 323. This vulnerability manifests when a specially crafted GIF is processed for output. It is important to note that this issue is distinct from CVE-2022-28506. While the [5b74cd] commit effectively addresses CVE-2022-28506, it does not provide a resolution for this particular heap-buffer overflow problem. Consequently, even after applying the patch associated with CVE-2022-28506, the heap buffer overflow in question remains unmitigated.
The provided proof of concept (POC) successfully replicates the crash even if the 5b74cd commit (CVE-2022-28506) is applied.
POC crash on line 321 using the following -o output command
./giflib-5.2.1/gif2rgb -o out poc_crash
The POC_crash file is included.

Assigned CVE number : CVE-2023-48161
POC crash:
Last edit: Norbert 2023-11-20
This crah has been fixed. The tool now complains:
gif2rgb: Image is defective, decoding aborted
Hello Eric ! Unfortunately, I still have this error even after I've applied this patch and some others. The fix for me was to free "Buffers". Please find attached the patch.
THis patch is created based on the latest version ...
@esr I just tried with vanilla giflib 5.2.2 (plus ASan plus UBSan a la
make {O,LD}FLAGS='-fsanitize=address,undefined' CC=clang) and thePOC_crashfile attached by @tihanyin makes command./gif2rgb -o out POC_crashcrash with the same output as reported. This is not fixed, please fix. Thank you!CC @ctulhu
Last edit: Sebastian Pipping 2025-04-08
@bcodres the patched you attached — both the initial and the rebased one — only add three calls to
freewhich I would expect to be able to fix a memory leak but not a buffer overflow. Am I missing something? Could you verify the patch files contains what you intended to share for a fix? Thank you!CC @ctulhu
Hello @esr @hartwork
Yes, I've doubled check the issue and indeed my initial patch solve some memory leaks. I've attached a new patch that should solve the issue. It's actually a similar patch as CVE-2022-28506
After applying the patch I do not have the issue anymore:
Can you provide me feedback ?
Bogdan.
@bcodres I confirm that the patch fixes the crash for the attached
POC_crashfile. As a consequence, this seems to mean that CVE-2023-48161 and CVE-2025-31344 are the very same thing, see https://github.com/OpenMandrivaAssociation/giflib/blob/master/giflib-5.2.2-cve-2025-31344.patch and https://seclists.org/oss-sec/2025/q2/25 . Can you confirm?CC @ctulhu
Hello !
Yes, I can confirm that those 2 CVE's are the same. CVE-2025-31344 seems to be a duplicate of CVE-2023-48161.
@hartwork @esr
I've found another duplicate of this bug. Is CVE-2024-45993
https://gitlab.com/mthandazo/project-pov
I've tested without the patch with the sample from the link above
and the error is the same. With the patch the issue is not reproducible anymore.
Bogdan
@bcodres I agree — CVE-2024-45993 is the same! I just confirmed with a debugger that @mmuzila's file
crashes/samplehits the same code path. What only now I realize is that the issue (likely) appeared fixed to some (or some of the time), because whether the user passes argument-1or not — for single-file mode, in contrast to three-file mode — decides whether they run vulnerable code or not: they either run (a) the code with the fix from 368f28c0034ecfb6dd4b3412af4cc589a56e0611 for single-file mode or (b) the code that still needs patching (starting line 330) for three-files mode. I feel relieved to finally have clarity on that.@bcodres @mmuzila since related commit 368f28c0034ecfb6dd4b3412af4cc589a56e0611 says CVE-2022-28506 rather than CVE-2024-45993 I assume that CVE-2022-28506 is the same also?
Hello @hartwork. I can confirm that with the POC for CVE-2022-28506 I have the issue in the same spot from DumpScreen2RGB as in CVE-2023-48161.
With the same patch applied I do not have it anymore:
Bogdan
@bcodres thanks! At https://nvd.nist.gov/vuln/detail/CVE-2022-28506 I found…
…now and I confirm your results. I think that means that we have four CVEs all being about the same thing…
…, that the previous fix was incomplete, and that giflib-5.2.2-cve-2025-31344.patch completes it.
Thanks for your help!
Best, Sebastian