Skip to content

Instantly share code, notes, and snippets.

@1mxml
Last active December 17, 2025 06:49
Show Gist options
  • Select an option

  • Save 1mxml/cabd6d972557d9d992fe5f4f6ca1dd87 to your computer and use it in GitHub Desktop.

Select an option

Save 1mxml/cabd6d972557d9d992fe5f4f6ca1dd87 to your computer and use it in GitHub Desktop.
@1mxml

1mxml commented Dec 11, 2025

Copy link
Copy Markdown
Author

Heap Buffer Overflow DoS Vulnerability in FreeImage (psdParser::ReadImageData)

CVE-ID: CVE-2025-65803
Affected Component: psdParser::ReadImageData
Affected Product: FreeImage ≤ 3.18.0
Impact: Denial of Service (DoS), potential memory corruption


Overview

A crafted PSD file can trigger a heap-buffer-overflow in FreeImage during image parsing.
The issue exists in psdParser::ReadImageData, where the parser computes the number of bytes per row (lineSize) directly from PSD header values without verifying whether the depth field is valid.

When an attacker provides an abnormally large depth, the computed lineSize becomes extremely large. This value is subsequently used in a memcpy() operation, overflowing the destination bitmap row buffer and causing a crash.


Technical Description

PSD header fields such as depth, width, and channels are used to calculate:
bytes = depth / 8
lineSize = width * bytes

FreeImage allocates a normal-sized bitmap row buffer based on expected bit-depth (e.g., ~80 bytes).
However, with a malicious PSD header, lineSize can reach tens of kilobytes.

The parser then performs:

memcpy(dst_line_start, src, lineSize)


Trigger Conditions

  • A PSD file contains an abnormally large or malformed depth field
  • nCompression = NONE, causing the parser to copy raw pixel data using the inflated lineSize
  • The application attempts to load the PSD using FreeImage_Load()

Any application using FreeImage to open PSD files is impacted.


Mitigation Recommendations

  • Validate PSD depth values (allow only expected values such as 1, 8, 16)
  • Verify that lineSize does not exceed the size of the destination row buffer
  • Reject PSD files with inconsistent or malformed header fields
  • Apply sandboxing when processing untrusted images

@iamleot

iamleot commented Dec 12, 2025

Copy link
Copy Markdown

Hello @1mxml!
Have you reported that to upstream?

@carnil

carnil commented Dec 12, 2025

Copy link
Copy Markdown

FWIW, there was as well in past (and yet unfixed): https://sourceforge.net/p/freeimage/bugs/366/ (CVE-2024-28565).

@carnil

carnil commented Dec 12, 2025

Copy link
Copy Markdown

@iamleot

iamleot commented Dec 12, 2025

Copy link
Copy Markdown

Thanks @carnil!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment