Skip to content

Fix heap buffer overflow in _tiffWriteProc when saving TIFF to BytesIO - #10224

Merged
hugovk merged 1 commit into
python-pillow:mainfrom
hugovk:ghsa-332p-7hrc-92wf
Oct 16, 2026
Merged

hugovk merged 1 commit into
python-pillow:mainfrom
hugovk:ghsa-332p-7hrc-92wf

Conversation

@hugovk

@hugovk hugovk commented Oct 16, 2026

Copy link
Copy Markdown
Member

libtiff seeks past the current end of data when writing the directory and writes tag values there. _tiffWriteProc sized its realloc() from state->size + size instead of the write position state->loc + size, so the first out-of-line tag value written after such a seek could overrun the allocation by up to the size of the directory. The bytes skipped by the seek were also never zeroed, leaking stale heap contents into the saved file.

Size the buffer from the write position and zero the space added by realloc, matching the semantics of writing to a real file. Reject writes where the position is still beyond the buffer for the non-reallocating case.

libtiff seeks past the current end of data when writing the directory
and writes tag values there. _tiffWriteProc sized its realloc() from
state->size + size instead of the write position state->loc + size,
so the first out-of-line tag value written after such a seek could
overrun the allocation by up to the size of the directory. The bytes
skipped by the seek were also never zeroed, leaking stale heap
contents into the saved file.

Size the buffer from the write position and zero the space added by
realloc, matching the semantics of writing to a real file. Reject
writes where the position is still beyond the buffer for the
non-reallocating case.

Reported-by: carlini
Reported-by: Tomer-PL
Fixes: GHSA-332p-7hrc-92wf

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hugovk
hugovk force-pushed the ghsa-332p-7hrc-92wf branch from efc7b60 to 78c08bd Compare October 16, 2026 16:12
@hugovk
hugovk merged commit 11582e5 into python-pillow:main Oct 16, 2026
59 of 60 checks passed
@hugovk
hugovk deleted the ghsa-332p-7hrc-92wf branch October 16, 2026 17:37
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