Security Vulnerability Report
中文
CVE-2026-32741 CVSS 7.1 HIGH

CVE-2026-32741

Published: 2026-05-19 21:16:42
Last Modified: 2026-05-20 17:16:21

Description

libheif is a HEIF and AVIF file format decoder and encoder. Versions 1.21.2 and below contain a heap buffer overflow in MaskImageCodec::decode_mask_image(). When decoding a HEIF file containing a mask image (mski), the function copies the full iloc extent data into a pixel buffer using memcpy(dst, data.data(), data.size()). The copy length data.size() is determined by the iloc extent in the file (attacker-controlled), while the destination buffer is sized based on the declared image dimensions. Because no upper-bound check exists on the data length, a crafted file whose iloc extent exceeds the pixel buffer allocation overflows the heap. The vulnerable single-memcpy branch is reached when the mskC property specifies bits_per_pixel = 8 and the ispe property declares an even width ≥ 64 (so that stride == width), with no changes to default security limits or external codec plugins required. This issue has been fixed in version 1.22.0.

CVSS Details

CVSS Score
7.1
Severity
HIGH
CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:H

Configurations (Affected Products)

No configuration data available.

libheif <= 1.21.2

PoC / Exploit Code

⚠ For Security Research Only
The following code is for security research and authorized testing only.
python
import libheif import sys """ PoC for CVE-2026-32741 This script attempts to decode a crafted HEIF file that triggers the heap buffer overflow in libheif < 1.22.0. Prerequisites for the crafted file ('exploit.heic'): 1. Must contain a mask image (mski). 2. mskC property must specify bits_per_pixel = 8. 3. ispe property must declare an even width >= 64. 4. The iloc extent size must be larger than the calculated pixel buffer size. """ def trigger_vulnerability(file_path): try: # Initialize a HEIF context ctx = libheif.Context() # Read the crafted file into memory with open(file_path, 'rb') as f: file_data = f.read() # Feed the data to the decoder ctx.read_from_memory(file_data) # Get the primary image handle and attempt to decode it # This invokes the vulnerable MaskImageCodec::decode_mask_image() primary_handle = ctx.get_primary_image_handle() image = primary_handle.decode_image() print("[+] Decoding completed. If the library is vulnerable, it may have crashed before this point.") except Exception as e: print(f"[-] An exception occurred: {e}") if __name__ == "__main__": # Replace 'exploit.heic' with the path to the actual crafted file # Generating a valid HEIF binary with specific iloc manipulation requires # complex binary construction, typically done with a hex editor or specialized file generator. trigger_vulnerability('exploit.heic')

References

Raw JSON Data

JSON
{"cve": {"id": "CVE-2026-32741", "sourceIdentifier": "[email protected]", "published": "2026-05-19T21:16:42.073", "lastModified": "2026-05-20T17:16:21.133", "vulnStatus": "Deferred", "cveTags": [], "descriptions": [{"lang": "en", "value": "libheif is a HEIF and AVIF file format decoder and encoder. Versions 1.21.2 and below contain a heap buffer overflow in MaskImageCodec::decode_mask_image(). When decoding a HEIF file containing a mask image (mski), the function copies the full iloc extent data into a pixel buffer using memcpy(dst, data.data(), data.size()). The copy length data.size() is determined by the iloc extent in the file (attacker-controlled), while the destination buffer is sized based on the declared image dimensions. Because no upper-bound check exists on the data length, a crafted file whose iloc extent exceeds the pixel buffer allocation overflows the heap. The vulnerable single-memcpy branch is reached when the mskC property specifies bits_per_pixel = 8 and the ispe property declares an even width ≥ 64 (so that stride == width), with no changes to default security limits or external codec plugins required. This issue has been fixed in version 1.22.0."}], "metrics": {"cvssMetricV31": [{"source": "[email protected]", "type": "Secondary", "cvssData": {"version": "3.1", "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:H", "baseScore": 7.1, "baseSeverity": "HIGH", "attackVector": "NETWORK", "attackComplexity": "LOW", "privilegesRequired": "NONE", "userInteraction": "REQUIRED", "scope": "UNCHANGED", "confidentialityImpact": "NONE", "integrityImpact": "LOW", "availabilityImpact": "HIGH"}, "exploitabilityScore": 2.8, "impactScore": 4.2}]}, "weaknesses": [{"source": "[email protected]", "type": "Secondary", "description": [{"lang": "en", "value": "CWE-122"}]}], "references": [{"url": "https://github.com/strukturag/libheif/releases/tag/v1.22.0", "source": "[email protected]"}, {"url": "https://github.com/strukturag/libheif/security/advisories/GHSA-j3w5-7whq-p37q", "source": "[email protected]"}, {"url": "https://github.com/strukturag/libheif/security/advisories/GHSA-j3w5-7whq-p37q", "source": "134c704f-9b21-4f2e-91b3-4a467353bcc0"}]}}