Skip to content

Fix heap-buffer-overflow write in PICT UnpackPictRow#41

Merged
danoli3 merged 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/pict-packbits-oob-write
Apr 22, 2026
Merged

Fix heap-buffer-overflow write in PICT UnpackPictRow#41
danoli3 merged 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/pict-packbits-oob-write

Conversation

@JorgeBarredo14
Copy link
Copy Markdown

Summary

The PackBits decompression loop in UnpackPictRow advances pCurPixel by the decoded run length without verifying that the destination remains within the allocated line buffer (pLineBuf, sized to rowBytes). A crafted PICT file with run lengths that exceed the scanline width causes memset (packed path) or read_proc (unpacked path) to write past the end of the buffer.

Root cause

PluginPICT.cpp lines 562 and 571: the decoded len is used directly in memset/read_proc without clamping to the remaining buffer space.

Fix

Clamp the decoded length to the remaining buffer space (pLineBuf + rowBytes - pCurPixel) before each write operation, in both the packed-data and unpacked-data code paths. Skip the write entirely if no space remains.

Metadata

  • CWE: CWE-787 (Out-of-bounds Write)
  • Severity: High
  • Reproducer: crafted PICT file (available on request)
  • Found during: academic security research

@JorgeBarredo14
Copy link
Copy Markdown
Author

CI failures on macOS/clang are pre-existing — the same 4 checks fail on master (e.g. run on commit a750f88). This PR builds cleanly on Linux and Windows.

@danoli3
Copy link
Copy Markdown
Owner

danoli3 commented Apr 16, 2026

Thanks yes I'll make a macOS fix and re-run

@danoli3
Copy link
Copy Markdown
Owner

danoli3 commented Apr 22, 2026

Master is fixed could you rebase these and lets test ci

The PackBits decompression loop in UnpackPictRow advances
pCurPixel by the decoded run length without verifying that the
destination remains within the allocated line buffer. A crafted
PICT file with run lengths that exceed the scanline width causes
memset or read_proc to write past the end of pLineBuf.

Clamp the decoded length to the remaining buffer space before
each write operation, in both the packed-data and unpacked-data
code paths.

CWE-787 (Out-of-bounds Write)
Found during academic security research.
@JorgeBarredo14 JorgeBarredo14 force-pushed the fix/pict-packbits-oob-write branch from 72dc3d3 to 1824832 Compare April 22, 2026 08:32
@danoli3
Copy link
Copy Markdown
Owner

danoli3 commented Apr 22, 2026

Thanks running ci now

@danoli3
Copy link
Copy Markdown
Owner

danoli3 commented Apr 22, 2026

Amazing merging now. could you update the other prs too

@danoli3 danoli3 merged commit fc05640 into danoli3:master Apr 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants