Skip to content

fix(raw): apply LibRaw memory cap before unpack to prevent OOM#5275

Open
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-rawmemcap
Open

fix(raw): apply LibRaw memory cap before unpack to prevent OOM#5275
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-rawmemcap

Conversation

@lgritz

@lgritz lgritz commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

open_raw set imgdata.rawparams.max_raw_memory_mb after calling m_processor->unpack(), so LibRaw's allocation cap never protected the unpack step -- which is exactly where LibRaw allocates the raw image buffer. A corrupt raw file claiming huge dimensions could therefore allocate unbounded and OOM (showing up on the fuzzer as a 0-length crash artifact from an out-of-memory trip rather than a normal reproducer).

Move the max_raw_memory_mb assignment to immediately after open_file succeeds, before unpack(), so the cap (default 2048 MB) actually bounds the allocation. LibRaw then fails the file cleanly instead of OOMing.

Assisted-by: Claude Code / Claude Opus 4.8

open_raw set imgdata.rawparams.max_raw_memory_mb *after* calling
m_processor->unpack(), so LibRaw's allocation cap never protected the
unpack step -- which is exactly where LibRaw allocates the raw image
buffer. A corrupt raw file claiming huge dimensions could therefore
allocate unbounded and OOM (showing up on the fuzzer as a 0-length crash
artifact from an out-of-memory trip rather than a normal reproducer).

Move the max_raw_memory_mb assignment to immediately after open_file
succeeds, before unpack(), so the cap (default 2048 MB) actually bounds
the allocation. LibRaw then fails the file cleanly instead of OOMing.

Assisted-by: Claude Code / Claude Opus 4.8

Signed-off-by: Larry Gritz <lg@larrygritz.com>
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.

1 participant