CVE-2026-27809: psd-tools Compression Module Has Unguarded Zlib Vulnerability

MODERATE
Advisory Identifier: GHSA-24p2-j2jr-386w
Advisory Summary

CVE-2026-27809 is a MODERATE compression module has unguarded zlib vulnerability (CWE-190: Integer Overflow or Wraparound) affecting psd-tools libraries in the PyPI ecosystem. The issue involves compression module has unguarded zlib decompression, missing dimension validation, and hardening gaps. Remediation is available by upgrading affected packages to version 1.12.2.

CVE-2026-27809 at a Glance

CVE Identifier CVE-2026-27809
GHSA Identifier GHSA-24p2-j2jr-386w
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-190: Integer Overflow or Wraparound
Affected Product psd-tools
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2026-27809

To remediate this vulnerability, upgrade all affected psd-tools dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

psd-tools fixed: 1.12.2
pip install psd-tools>=1.12.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show psd-tools

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-27809, inspect your installed packages using pip:

pip show psd-tools

Analyze the terminal output to locate any version of psd-tools in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.12.2), your application is affected.

Note: The pip show psd-tools command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-190: Integer Overflow or Wraparound, where the product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. this occurs when an integer value is incremented to a value that is too large to store in the associated representation. when this occurs, the value may become a very small or negative number. In psd-tools, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary A security review of the `psd_tools.compression` module (conducted against the `fix/invalid-rle-compression` branch, commits `7490ffa`–`2a006f5`) identified the following pre-existing issues. The two findings introduced and **fixed** by those commits (Cython buffer overflow, `IndexError` on lone repeat header) are excluded from this report. --- ## Findings ### 1. Unguarded `zlib.decompress` — ZIP bomb / memory exhaustion (Medium) **Location**: `src/psd_tools/compression/__init__.py`, lines 159 and 162 ```python result = zlib.decompress(data) # Compression.ZIP decompressed = zlib.decompress(data) # Compression.ZIP_WITH_PREDICTION ``` `zlib.decompress` is called without a `max_length` cap. A crafted PSD file containing a ZIP-compressed channel whose compressed payload expands to gigabytes would exhaust process memory before any limit is enforced. The RLE path is not vulnerable to this because the decoder pre-allocates exactly `row_size × height` bytes; the ZIP path has no equivalent ceiling. **Impact**: Denial-of-service / OOM crash when processing untrusted PSD files. **Suggested mitigation**: Pass a reasonable `max_length` to `zlib.decompress`, derived from the expected `width * height * depth // 8` byte count already computed in `decompress()`. --- ### 2. No upper-bound validation on image dimensions before allocation (Low) **Location**: `src/psd_tools/compression/__init__.py`, lines 138 and 193 ```python length = width * height * max(1, depth // 8) # decompress() row_size = max(width * depth // 8, 1) # decode_rle() ``` Neither `width`, `height`, nor `depth` are range-checked before these values drive memory allocation. The PSD format (version 2 / PSB) permits dimensions up to 300,000 × 300,000 pixels; a 4-channel 32-bit image at that size would require ~144 TB to hold. While the OS/Python allocator will reject such a request, there is no early, explicit guard that produces a clean, user-facing error. **Impact**: Uncontrolled allocation attempt from a malformed or adversarially crafted PSB file; hard crash rather than a recoverable error. **Suggested mitigation**: Validate `width`, `height`, and `depth` against known PSD/PSB limits before entering decompression, and raise a descriptive `ValueError` early. --- ### 3. `assert` used as a runtime integrity check (Low) **Location**: `src/psd_tools/compression/__init__.py`, line 170 ```python assert len(result) == length, "len=%d, expected=%d" % (len(result), length) ``` This assertion can be silently disabled by running the interpreter with `-O` (or `-OO`), which strips all `assert` statements. If the assertion ever becomes relevant (e.g., after future refactoring), disabling it would allow a length mismatch to propagate silently into downstream image compositing. **Impact**: Loss of an integrity guard in optimised deployments. **Suggested mitigation**: Replace with an explicit `if` + `raise ValueError(...)`. --- ### 4. `cdef int` indices vs. `Py_ssize_t size` type mismatch in Cython decoder (Low) **Location**: `src/psd_tools/compression/_rle.pyx`, lines 18–20 ```cython cdef int i = 0 cdef int j = 0 cdef int length = data.shape[0] ``` All loop indices are C `signed int` (32-bit). The `size` parameter is `Py_ssize_t` (64-bit on modern platforms). The comparison `j < size` promotes `j` to `Py_ssize_t`, but if `j` wraps due to a row size exceeding `INT_MAX` (~2.1 GB), the resulting comparison is undefined behaviour in C. In practice, row sizes are bounded by PSD/PSB dimension limits and are unreachable at this scale; however, the mismatch is a latent defect if the function is ever called directly with large synthetic inputs. **Impact**: Theoretical infinite loop or UB at >2 GB row sizes; not reachable from standard PSD/PSB parsing. **Suggested mitigation**: Change `cdef int i`, `j`, `length` to `cdef Py_ssize_t`. --- ### 5. Silent data degradation not surfaced to callers (Informational) **Location**: `src/psd_tools/compression/__init__.py`, lines 144–157 The tolerant RLE decoder (introduced in `2a006f5`) replaces malformed channel data with zero-padded (black) pixels and emits a `logger.warning`. This is the correct trade-off over crashing, but the warning is only observable if the caller has configured a log handler. The public `PSDImage` API does not surface channel-level decode failures to the user in any other way. **Impact**: A user parsing a silently corrupt file gets a visually wrong image with no programmatic signal to check. **Suggested mitigation**: Consider exposing a per-channel decode-error flag or raising a distinct warning category that users can filter or escalate via the `warnings` module. --- ### 6. `encode()` zero-length return type inconsistency in Cython (Informational) **Location**: `src/psd_tools/compression/_rle.pyx`, lines 66–67 ```cython if length == 0: return data # returns a memoryview, not an explicit std::string ``` All other return paths return an explicit `cdef string result`. This path returns `data` (a `const unsigned char[:]` memoryview) and relies on Cython's implicit coercion to `bytes`. It is functionally equivalent today but is semantically inconsistent and fragile if Cython's coercion rules change in a future version. **Impact**: Potential silent breakage in future Cython versions; not a current security issue. **Suggested mitigation**: Replace `return data` with `return result` (the already-declared empty `string`). --- ## Environment - Branch: `fix/invalid-rle-compression` - Reviewed commits: `7490ffa`, `2a006f5` - Python: 3.x (Cython extension compiled for CPython)

CVE-2026-27809 Affected psd-tools Versions

1 component(s)
Fixed Versions:
1.12.2
Product / Package Ecosystem Affected Versions Fixed Version
psd-tools
PyPI
< 1.12.2
1.12.2

References

Frequently Asked Questions

What is CVE-2026-27809?
CVE-2026-27809 is a security vulnerability in psd-tools involving Compression module has unguarded zlib decompression, missing dimension validation, and hardening gaps under CWE-190: Integer Overflow or Wraparound.
Which psd-tools versions are affected?
Affected versions include releases prior to 1.12.2 across affected packages: psd-tools.
What version fixes CVE-2026-27809?
Upgrading to 1.12.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is psd-tools affected?
Yes, psd-tools is affected in releases prior to 1.12.2. Upgrade your dependency to 1.12.2 or later.
What CWE is associated with CVE-2026-27809?
CVE-2026-27809 is classified under CWE-190: Integer Overflow or Wraparound (The product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. This occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may become a very small or negative number.).
How can I check PyPI dependencies for CVE-2026-27809?
Run the dependency tree command: 'pip show psd-tools'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-24p2-j2jr-386w",
  "modified" : "2026-02-26T15:20:51Z",
  "published" : "2026-02-26T15:20:51Z",
  "aliases" : [ "CVE-2026-27809" ],
  "summary" : "psd-tools: Compression module has unguarded zlib decompression, missing dimension validation, and hardening gaps",
  "details" : "## Summary\n\nA security review of the `psd_tools.compression` module (conducted against the `fix/invalid-rle-compression` branch, commits `7490ffa`–`2a006f5`) identified the following pre-existing issues. The two findings introduced and **fixed** by those commits (Cython buffer overflow, `IndexError` on lone repeat header) are excluded from this report.\n\n---\n\n## Findings\n\n### 1. Unguarded `zlib.decompress` — ZIP bomb / memory exhaustion (Medium)\n\n**Location**: `src/psd_tools/compression/__init__.py`, lines 159 and 162\n\n```python\nresult = zlib.decompress(data)          # Compression.ZIP\ndecompressed = zlib.decompress(data)    # Compression.ZIP_WITH_PREDICTION\n```\n\n`zlib.decompress` is called without a `max_length` cap. A crafted PSD file containing a ZIP-compressed channel whose compressed payload expands to gigabytes would exhaust process memory before any limit is enforced. The RLE path is not vulnerable to this because the decoder pre-allocates exactly `row_size × height` bytes; the ZIP path has no equivalent ceiling.\n\n**Impact**: Denial-of-service / OOM crash when processing untrusted PSD files.\n\n**Suggested mitigation**: Pass a reasonable `max_length` to `zlib.decompress`, derived from the expected `width * height * depth // 8` byte count already computed in `decompress()`.\n\n---\n\n### 2. No upper-bound validation on image dimensions before allocation (Low)\n\n**Location**: `src/psd_tools/compression/__init__.py`, lines 138 and 193\n\n```python\nlength = width * height * max(1, depth // 8)   # decompress()\nrow_size = max(width * depth // 8, 1)           # decode_rle()\n```\n\nNeither `width`, `height`, nor `depth` are range-checked before these values drive memory allocation. The PSD format (version 2 / PSB) permits dimensions up to 300,000 × 300,000 pixels; a 4-channel 32-bit image at that size would require ~144 TB to hold. While the OS/Python allocator will reject such a request, there is no early, explicit guard that produces a clean, user-facing error.\n\n**Impact**: Uncontrolled allocation attempt from a malformed or adversarially crafted PSB file; hard crash rather than a recoverable error.\n\n**Suggested mitigation**: Validate `width`, `height`, and `depth` against known PSD/PSB limits before entering decompression, and raise a descriptive `ValueError` early.\n\n---\n\n### 3. `assert` used as a runtime integrity check (Low)\n\n**Location**: `src/psd_tools/compression/__init__.py`, line 170\n\n```python\nassert len(result) == length, \"len=%d, expected=%d\" % (len(result), length)\n```\n\nThis assertion can be silently disabled by running the interpreter with `-O` (or `-OO`), which strips all `assert` statements. If the assertion ever becomes relevant (e.g., after future refactoring), disabling it would allow a length mismatch to propagate silently into downstream image compositing.\n\n**Impact**: Loss of an integrity guard in optimised deployments.\n\n**Suggested mitigation**: Replace with an explicit `if` + `raise ValueError(...)`.\n\n---\n\n### 4. `cdef int` indices vs. `Py_ssize_t size` type mismatch in Cython decoder (Low)\n\n**Location**: `src/psd_tools/compression/_rle.pyx`, lines 18–20\n\n```cython\ncdef int i = 0\ncdef int j = 0\ncdef int length = data.shape[0]\n```\n\nAll loop indices are C `signed int` (32-bit). The `size` parameter is `Py_ssize_t` (64-bit on modern platforms). The comparison `j < size` promotes `j` to `Py_ssize_t`, but if `j` wraps due to a row size exceeding `INT_MAX` (~2.1 GB), the resulting comparison is undefined behaviour in C. In practice, row sizes are bounded by PSD/PSB dimension limits and are unreachable at this scale; however, the mismatch is a latent defect if the function is ever called directly with large synthetic inputs.\n\n**Impact**: Theoretical infinite loop or UB at >2 GB row sizes; not reachable from standard PSD/PSB parsing.\n\n**Suggested mitigation**: Change `cdef int i`, `j`, `length` to `cdef Py_ssize_t`.\n\n---\n\n### 5. Silent data degradation not surfaced to callers (Informational)\n\n**Location**: `src/psd_tools/compression/__init__.py`, lines 144–157\n\nThe tolerant RLE decoder (introduced in `2a006f5`) replaces malformed channel data with zero-padded (black) pixels and emits a `logger.warning`. This is the correct trade-off over crashing, but the warning is only observable if the caller has configured a log handler. The public `PSDImage` API does not surface channel-level decode failures to the user in any other way.\n\n**Impact**: A user parsing a silently corrupt file gets a visually wrong image with no programmatic signal to check.\n\n**Suggested mitigation**: Consider exposing a per-channel decode-error flag or raising a distinct warning category that users can filter or escalate via the `warnings` module.\n\n---\n\n### 6. `encode()` zero-length return type inconsistency in Cython (Informational)\n\n**Location**: `src/psd_tools/compression/_rle.pyx`, lines 66–67\n\n```cython\nif length == 0:\n    return data   # returns a memoryview, not an explicit std::string\n```\n\nAll other return paths return an explicit `cdef string result`. This path returns `data` (a `const unsigned char[:]` memoryview) and relies on Cython's implicit coercion to `bytes`. It is functionally equivalent today but is semantically inconsistent and fragile if Cython's coercion rules change in a future version.\n\n**Impact**: Potential silent breakage in future Cython versions; not a current security issue.\n\n**Suggested mitigation**: Replace `return data` with `return result` (the already-declared empty `string`).\n\n---\n\n## Environment\n\n- Branch: `fix/invalid-rle-compression`\n- Reviewed commits: `7490ffa`, `2a006f5`\n- Python: 3.x (Cython extension compiled for CPython)",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N/E:U"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "psd-tools"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.12.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/psd-tools/psd-tools/security/advisories/GHSA-24p2-j2jr-386w"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-27809"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/psd-tools/psd-tools/commit/6c0a78f195b5942757886a1863793fd5946c1fb1"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/psd-tools/psd-tools"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/psd-tools/psd-tools/releases/tag/v1.12.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-190", "CWE-409", "CWE-617", "CWE-704", "CWE-755", "CWE-789" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-02-26T15:20:51Z",
    "nvd_published_at" : "2026-02-26T00:16:26Z"
  }
}