{"id":"CVE-2026-54058","aliases":["CVE-2026-54058","GHSA-62p4-gmf7-7g93","BIT-PILLOW-2026-54058","PYSEC-2026-3493"],"related":[],"kind":"vulnerability","state":"published","title":"Pillow: Out-of-bounds read via attacker-controlled row stride on Pillow's mmap path (McIdas AREA files)","summary":"Pillow is a Python imaging library. Prior to 12.3.0, when Pillow loads an uncompressed McIdas AREA image from a filename through the mmap raw codec path, attacker-controlled header words can set a row stride smaller than the natural row width, causing pixel access such as Image.tobytes(), getpixel, convert, or save to read beyond the mapped region and disclose adjacent process memory or fault. This issue is fixed in version 12.3.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Pillow is a Python imaging library. Prior to 12.3.0, when Pillow loads an uncompressed McIdas AREA image from a filename through the mmap raw codec path, attacker-controlled header words can set a row stride smaller than the natural row width, causing pixel access such as Image.tobytes(), getpixel, convert, or save to read beyond the mapped region and disclose adjacent process memory or fault. This issue is fixed in version 12.3.0.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nWhen Pillow loads an uncompressed image whose tile uses the `raw` codec and a mode in `Image._MAPMODES`, and the image was opened **from a filename**, it memory-maps the file and builds the image's row pointers directly into the mapping via `PyImaging_MapBuffer` (`src/map.c`). The per-row spacing (`stride`) is taken from the tile arguments. `map.c` validates `offset + ysize*stride <= buffer_len` but **never checks that `stride` is at least the natural row width `xsize * pixelsize`**.\n\nThe **McIdas** AREA plugin (`McIdasImagePlugin.py`) derives `stride`, `offset`, `xsize`, and `ysize` directly from attacker-controlled 32-bit header words with no validation. By supplying a `stride` far smaller than the row width, an attacker makes each row pointer read `xsize*pixelsize` bytes that run past the mapped region. Accessing the pixels (e.g. `Image.tobytes()`,\n`getpixel`, `convert`, `save`) then reads adjacent process memory (information disclosure) or faults (SIGBUS, denial of service).\n\n\n## Complete Code Trace\n\n**Step 1: `McIdasImageFile._open`** - turns attacker header words into image size, file offset, and row stride with no validation.\n\n```python\n# src/PIL/McIdasImagePlugin.py:41-70\ns = self.fp.read(256)\nif not _accept(s) or len(s) != 256:        # _accept: prefix == b\"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x04\"\n    raise SyntaxError(...)\nself.area_descriptor = w = [0, *struct.unpack(\"!64i\", s)]   # w[1..64] = signed BE int32, ALL attacker-controlled\n\nif w[11] == 1:\n    mode = rawmode = \"L\"                    # pixelsize 1, in _MAPMODES\nelif w[11] == 2:\n    mode = rawmode = \"I;16B\"                # pixelsize 2, in _MAPMODES\n...\nself._mode = mode\nself._size = w[10], w[9]                    # (xsize, ysize)  <-- attacker\noffset = w[34] + w[15]                       # <-- attacker\nstride = w[15] + w[10] * w[11] * w[14]       # <-- attacker (set w[14]=0, w[15]=1 => stride=1)\nself.tile = [\n    ImageFile._Tile(\"raw\", (0, 0) + self.size, offset, (rawmode, stride, 1))\n]\n```\n\n**Step 2: `ImageFile.load` (mmap branch)** - selects mmap and delegates to `map_buffer`.\n\n```python\n# src/PIL/ImageFile.py:322-348\nif use_mmap:                                 # use_mmap = self.filename and len(self.tile) == 1\n    decoder_name, extents, offset, args = self.tile[0]\n    if (decoder_name == \"raw\" and isinstance(args, tuple) and len(args) >= 3\n            and args[0] == self.mode and args[0] in Image._MAPMODES):\n        if offset < 0:                       # only lower-bound guard on offset\n            raise ValueError(\"Tile offset cannot be negative\")\n        with open(self.filename) as fp:\n            self.map = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)\n        if offset + self.size[1] * args[1] > self.map.size():   # == offset + ysize*stride; NO stride>=linesize check\n            raise OSError(\"buffer is not large enough\")\n        self.im = Image.core.map_buffer(\n            self.map, self.size, decoder_name, offset, args      # args = (\"L\", stride, 1)\n        )\n```\n\n**Step 3: `PyImaging_MapBuffer`** - builds row pointers at `stride` spacing into the mmap; validates everything except `stride >= row width`.\n\n```c\n/* src/map.c:65-140 */\nif (!PyArg_ParseTuple(args, \"O(ii)sn(sii)\",\n        &target, &xsize, &ysize, &codec, &offset, &mode_name, &stride, &ystep))\n    return NULL;\n...\nconst ModeID mode = findModeID(mode_name);          /* \"L\" */\n\nif (stride <= 0) {                                  /* attacker sets stride=1 (>0) -> NOT recomputed */\n    if (mode == IMAGING_MODE_L || mode == IMAGING_MODE_P) stride = xsize;\n    else if (isModeI16(mode)) stride = xsize * 2;\n    else stride = xsize * 4;\n}\n\nif (stride > 0 && ysize > PY_SSIZE_T_MAX / stride) {/* overflow guard only */\n    PyErr_SetString(PyExc_MemoryError, \"Integer overflow in ysize\"); return NULL;\n}\nsize = (Py_ssize_t)ysize * stride;                  /* = 1*1 = 1 */\n\nif (offset > PY_SSIZE_T_MAX - size) { ... }\n...\nif (offset + size > view.len) {                     /* 1 + 1 = 2 <= 256 -> PASSES */\n    PyErr_SetString(PyExc_ValueError, \"buffer is not large enough\");\n    PyBuffer_Release(&view); return NULL;\n}\n\nim = ImagingNewPrologueSubtype(mode, xsize, ysize, sizeof(ImagingBufferInstance));\n/* im->linesize = xsize * pixelsize = 200000  (the REAL per-row read width) */\n\n/* setup file pointers -- NO check that stride >= im->linesize */\nif (ystep > 0) {\n    for (y = 0; y < ysize; y++) {\n        im->image[y] = (char *)view.buf + offset + y * stride;   /* row points into mmap, spacing=1 */\n    }\n} else { ... }\n```\n\n`im->linesize` (the number of bytes any consumer reads per row) is `xsize * pixelsize = 200000`, but the row pointers are only `stride = 1` byte apart and the buffer is only `offset + ysize*stride = 2` bytes \"claimed\". Nothing reconciles the two.\n\n**Step 4: pixel access (`Image.tobytes()` → raw encoder `copy1`)** - reads `linesize` bytes from `im->image[0]`, i.e. `xsize` bytes starting at `view.buf + offset`, running far past the mmap.\n\n```c\n/* the raw \"L\" packer copies linesize (=xsize) bytes per row from im->image[y];\n   for row 0 that is view.buf+1 .. view.buf+1+200000, vs a 256-byte file. */\n```\n\n## Chain Summary\n\n```\nSOURCE: McIdas AREA header words w[9],w[10],w[11],w[14],w[15],w[34]  (Image.open on a path)\n  ↓ McIdasImagePlugin._open: stride = w[15]+w[10]*w[11]*w[14]  -> attacker sets stride=1   [McIdasImagePlugin.py:66]\n  ↓ tile = (\"raw\", (0,0,xsize,1), offset, (\"L\", 1, 1))                                     [McIdasImagePlugin.py:68]\nGADGET: ImageFile.load mmap branch -- only checks offset+ysize*stride<=len  <- BUG: no stride>=linesize check  [ImageFile.py:343]\n  ↓ core.map_buffer(map, (xsize,1), \"raw\", offset, (\"L\",1,1))                              [ImageFile.py:346]\nSINK: PyImaging_MapBuffer: im->image[0] = view.buf + offset + 0*stride; linesize=xsize   [map.c:134]\n  ↓ Image.tobytes() raw \"L\" encoder reads linesize (=xsize) bytes from im->image[0]\nIMPACT: reads xsize bytes from a tiny mmap -> OOB read of adjacent process memory (leak) or SIGBUS (DoS)\n```\n## Proof of Concept\n\nSee attached [poc.zip](https://github.com/user-attachments/files/28460498/poc.zip)\n\n\n## Impact on a Parent Application\n\nAny application that opens image files supplied by users **from a path on disk** (the common pattern: save upload to a temp file, then `Image.open(path)`), has the default plugin set (McIdas is registered by default), and subsequently reads/returns/re-encodes the decoded pixels (thumbnailing, format conversion, serving a preview), is exposed:\n\n- **Information disclosure (High):** the decoded \"image\" contains bytes of the   worker process's adjacent heap/mapped memory, which the app then serves or stores - potentially leaking secrets, credentials, or other users' data.\n- **Denial of service (High):** a larger `xsize` reliably crashes the worker with SIGBUS.\n\n## Suggested fix\nCore fix in `src/map.c` (`PyImaging_MapBuffer`): reject `offset < 0` and `stride < im->linesize`. Defense-in-depth in `McIdasImagePlugin._open`: reject `offset < 0` or `stride < xsize*pixelsize` .","format":"markdown","source":"ghsa"},{"lang":"es","text":"Pillow es una biblioteca de imágenes de Python. Antes de la versión 12.3.0, cuando Pillow carga una imagen McIdas AREA sin comprimir desde un nombre de archivo a través de la ruta del códec mmap raw, palabras de encabezado controladas por el atacante pueden establecer un paso de fila menor que el ancho de fila natural, causando que el acceso a píxeles, como Image.tobytes(), getpixel, convert o save, lea más allá de la región mapeada y divulgue memoria de proceso adyacente o cause un fallo. Este problema está solucionado en la versión 12.3.0.","source":"nvd"}],"published":"2026-07-14T16:27:38.050Z","modified":"2026-10-24T21:10:00.130Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N","score":8.3,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N","score":8.3,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:H","score":9.1,"rating":"CRITICAL"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"CRITICAL"}],"cwes":["CWE-125"],"affected":[{"ranges":[{"version":"< 12.3.0","status":"affected"}],"vendor":"python-pillow","product":"Pillow","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"12.3.0"}],"ecosystem":"PyPI","package":"pillow","purl":"pkg:pypi/pillow","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"12.3.0"}],"vendor":"python","product":"pillow","cpe":"cpe:2.3:a:python:pillow:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"12.3.0"}],"ecosystem":"PyPI","package":"pillow","purl":"pkg:pypi/pillow","source":"pysec"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"12.3.0"}],"ecosystem":"Bitnami","package":"pillow","purl":"pkg:bitnami/pillow","source":"bitnami"}],"references":[{"url":"https://github.com/python-pillow/Pillow/security/advisories/GHSA-62p4-gmf7-7g93","tags":["advisory","exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/python-pillow/Pillow/pull/9719","tags":["fix","issue-tracking","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/python-pillow/Pillow/commit/6a8de891fb00968e5ea79bfa84368ed90b3cfc1d","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/python-pillow/Pillow/releases/tag/12.3.0","tags":["article","product","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54058","tags":["advisory","web"],"sources":["ghsa","pysec","bitnami"]},{"url":"https://github.com/python-pillow/Pillow","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/pillow","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-62p4-gmf7-7g93","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-14T17:53:55.907Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54058","url":"https://www.cve.org/CVERecord?id=CVE-2026-54058","licence":"CVE Terms of Use","modified":"2026-07-14T17:54:25.654Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-62p4-gmf7-7g93","url":"https://github.com/advisories/GHSA-62p4-gmf7-7g93","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:10.632Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54058","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54058","licence":"Public domain","modified":"2026-10-24T21:10:00.130Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-3493","url":"https://osv.dev/vulnerability/PYSEC-2026-3493","licence":"CC-BY-4.0","modified":"2026-07-23T15:11:42.568Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-PILLOW-2026-54058","url":"https://osv.dev/vulnerability/BIT-PILLOW-2026-54058","licence":"Apache-2.0","modified":"2026-09-10T16:01:45.908Z"}],"updatedAt":"2026-11-25T22:59:27.968Z","epss":{"score":0.00476,"percentile":0.33421,"date":"2026-11-30T12:00:22.000Z"}}