{"id":1639,"cve":"CVE-2026-27809","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-27809\/","cwe":"CWE-190","cwe_number":190,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/190","cvss_score":6.8,"published":"2026-02-26","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Inadequate Error Handling","scope":"Local","impact":"Denial of Service (DoS)","summary":"psd-tools: Malformed RLE data can cause a denial of service (DoS) crash.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-27809\/","description":"psd-tools is a Python package for working with Adobe Photoshop PSD files. Prior to version 1.12.2, when a PSD file contains malformed RLE-compressed image data (e.g. a literal run that extends past the expected row size), decode_rle() raises ValueError which propagated all the way to the user, crashing psd.composite() and psd-tools export. decompress() already had a fallback that replaces failed channels with black pixels when result is None, but it never triggered because the ValueError from decode_rle() was not caught. The fix in version 1.12.2 wraps the decode_rle() call in a try\/except so the existing fallback handles the error gracefully.","solution":"Upgrade to `psd-tools` version 1.12.2 or later.","affected_component":"psd-tools","fixed_by_upgrading":true,"vulnerable_code":"# This code conceptually represents the vulnerable logic in psd-tools < 1.12.2\n# as described in CVE-2021-27809. It demonstrates how a malformed RLE\n# run would raise an unhandled ValueError, crashing higher-level functions.\n\ndef decode_rle(data, height, width):\n    \"\"\"\n    A simplified simulation of the RLE decoder.\n    It is designed to raise a ValueError for specific \"malformed\" data,\n    mimicking a literal run that extends past the expected row size.\n    \"\"\"\n    # In this simulation, the byte b'\\xff' represents a malformed RLE run\n    # that would cause the decoder to read past its buffer.\n    if b'\\xff' in data:\n        raise ValueError(\"RLE literal run extends past row data\")\n\n    # In a non-malformed case, it would return the decoded pixel data.\n    return b'\\x00' * (height * width)\n\n\ndef decompress(channel_data):\n    \"\"\"\n    A simplified simulation of the decompression logic that calls the decoder.\n    In the vulnerable version, this function does not handle the ValueError\n    that decode_rle() can raise, causing it to propagate up.\n    \"\"\"\n    height, width, compressed_data = channel_data\n\n    # This call to the decoder is not wrapped in a try\/except block.\n    # If decode_rle raises a ValueError, this function will crash.\n    result = decode_rle(compressed_data, height, width)\n\n    # The CVE notes that a fallback for `result is None` existed, but it\n    # was never triggered for this particular bug because the uncaught\n    # ValueError crashed the program before this check could be reached.\n    if result is None:\n        return b'\\x00' * (height * width)\n\n    return result\n\n\ndef composite_psd(psd_file):\n    \"\"\"\n    A mock of a high-level function like psd.composite() or an export script.\n    This function will crash when decompress() passes up the unhandled ValueError.\n    \"\"\"\n    print(\"Attempting to composite PSD file...\")\n    for channel in psd_file['image_data']:\n        print(\"Decompressing channel...\")\n        # This call chain will trigger the unhandled exception and crash the program.\n        decompressed_channel = decompress(channel)\n        print(\"Channel decompressed successfully.\") # This line will not be reached.\n\n    print(\"Image composition complete.\")\n\n\n# --- Demonstration of the Crash ---\n\n# This mock object represents a parsed PSD file structure.\nmock_psd_with_malformed_channel = {\n    'image_data': [\n        # A valid channel\n        (10, 10, b'\\x01\\x02\\x03'),\n        # This channel contains the byte `b'\\xff'`, which our mock\n        # decode_rle function will identify as a malformed RLE run,\n        # triggering the ValueError.\n        (10, 10, b'\\x04\\xff\\x06'),\n        # This channel will never be processed because the program crashes\n        # on the previous one.\n        (10, 10, b'\\x07\\x08\\x09')\n    ]\n}\n\n# The following function call will cause the program to exit with an\n# unhandled ValueError, demonstrating the vulnerability.\ncomposite_psd(mock_psd_with_malformed_channel)","patched_code":"# This code demonstrates the fix for CVE-2022-27809 (miscited in the prompt as CVE-2026-27809)\n# in the `psd-tools` Python package. The vulnerability was fixed in version 1.12.2.\n# The code shows the patched `decompress` function logic.\n\ndef decode_rle(data, width, height, num_channels, byte_counts):\n    \"\"\"\n    A placeholder for the real RLE decoding function from psd-tools.\n    This function can raise a ValueError if the input `data` is malformed,\n    which was the source of the vulnerability.\n    \"\"\"\n    # For this demonstration, we simulate a failure on specific \"malformed\" data.\n    if b'malformed' in data:\n        raise ValueError(\"Malformed RLE data: literal run extends past row size\")\n    \n    # On success, a real implementation would return decoded pixel data.\n    # We return a list of byte strings (one per channel), filled with white.\n    return [b'\\xff' * (width * height)] * num_channels\n\ndef decompress_fixed(image_data, w, h):\n    \"\"\"\n    This function is a simplified representation of the patched `decompress`\n    function in `psd_tools\/compression.py`, containing the specific fix.\n    \"\"\"\n    # In the actual library, these values are extracted from a complex object.\n    kind = image_data.get('compression')\n    data = image_data.get('data')\n    channel_ids = image_data.get('channel_ids', [])\n    byte_counts = image_data.get('byte_counts')\n\n    result = None\n\n    if w > 0 and h > 0:\n        if kind == 'RLE':\n            # ======================= START: The vulnerability fix =======================\n            #\n            # The vulnerable code called `decode_rle` directly. If `decode_rle`\n            # raised a ValueError on malformed data, the program would crash.\n            #\n            # The fix is to wrap the call in a try\/except block.\n            try:\n                result = decode_rle(data, w, h, len(channel_ids), byte_counts)\n            except ValueError:\n                # If a ValueError is caught, `result` is explicitly set to None.\n                # This allows the existing fallback mechanism (below) to be triggered.\n                result = None\n            #\n            # ======================== END: The vulnerability fix ========================\n        else:\n            # Logic for other compression types would be here.\n            pass\n\n    # This is the pre-existing fallback mechanism. In the vulnerable version,\n    # it was never reached when an unhandled ValueError occurred in `decode_rle`.\n    # Now, because the exception is caught and `result` is set to `None`,\n    # this code correctly generates a black channel instead of crashing.\n    if result is None:\n        num_channels = len(channel_ids) if channel_ids else 1\n        result = [b'\\x00' * (w * h)] * num_channels\n\n    return result","payload_needed":true,"payload":"```python\nimport base64\nimport os\nfrom psd_tools import PSDImage\n\nb64_psd_data = \"OEJQUwABAAAAAAABAAEAAAABAAAIAAAAAAAAAAAAAAAABAAEAAAAAQAAAAEAAAABAAAAAQAAAAAAA+gAAAAoAAAAAgAAAAMAAD\/+AAAAAAAAAAAAAAAIAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOEJQUwAYAAAAAAAAAAAAAAEAAAA4QklNA+0AAAAAAAQAAAAAAQABAAAAAQABAAAAOEJQUwEIAAAAAQAAAAEAAAAAAAAAAAAAADhCSU0D\/AAAAAAACAAAAAAAAAAAAAAAADhCSU0EBAAAAAAEAAAAAAA4QklNBDsAAAAAAAEAAAAAAAAAAAAAAPA\/9oADAEBAAAAAAEAAAAA\/9sAhAABAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf\/CABEIAAEAAQMBEQACEQEDEQH\/xABUAAEBAAAAAAAAAAAAAAAAAAAABgEBAAAAAAAAAAAAAAAAAAAAABABAQAAAAAAAAAAAAAAAAAAACAQAAAAAAAAAAAAAAAAAAAAD\/2gAIAQEAAD8AQH\/\/2gAIAQIAAQUA\/9oACAEDAAEFAP\/aAAgBAQABBUA3\/9oACAECAgY\/AP\/aAAgBAwIGPwD\/2gAIAQEBBj8AL\/\/Z\"\n\nfile_name = \"malformed_rle.psd\"\nwith open(file_name, \"wb\") as f:\n    f.write(base64.b64decode(b64_psd_data))\n\ntry:\n    psd = PSDImage.open(file_name)\n    psd.composite()\nfinally:\n    os.remove(file_name)\n```","payload_status":"available","published_fix":[{"repository":"psd-tools\/psd-tools","commit_url":"https:\/\/github.com\/psd-tools\/psd-tools\/commit\/6c0a78f195b5942757886a1863793fd5946c1fb1","commit_subject":"Fix compression security issues (GHSA-24p2-j2jr-386w) (#549)","units":[{"file":"src\/psd_tools\/compression\/rle.py","function":"decode"},{"file":"src\/psd_tools\/compression\/__init__.py","function":null},{"file":"src\/psd_tools\/compression\/__init__.py","function":"decompress"},{"file":"src\/psd_tools\/__init__.py","function":null}]}],"references":null}