Reject TGA images whose declared size cannot fit the input stream (PR #26761)

11 views
Skip to first unread message

MarkLee131

unread,
Jul 31, 2026, 4:28:15 AM (4 days ago) Jul 31
to wx-...@googlegroups.com, Subscribed

Closes #26760.

Two changes to src/common/imagtga.cpp:

  1. Reject a header whose declared image size cannot fit the stream, before either allocation. Uncompressed types have to fit exactly. The RLE types are allowed 128:1, since a packet costs 1 + pixelSize input bytes and yields at most 128 * pixelSize output bytes. The check is skipped when GetLength() returns no usable value, so non-seekable streams are unaffected.

  2. Check LastRead() after the header read and after the three uncompressed bulk reads, so a truncated file fails instead of loading. imagpcx.cpp has done this since #26624. DecodeRLE() already validated its own reads, which is why the RLE paths were already rejecting these files.

wxTGAHandler::DoCanRead() gets the same header check, since it was reading an unfilled hdr for streams shorter than 18 bytes.

Two regression tests in tests/image/image.cpp: Both fail on d5aacc4712 and pass with this commit. Also verified against the 3.3.3 release, where src/common/imagtga.cpp is byte-identical to master.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/26761

Commit Summary

  • 9576af5 Reject TGA images whose declared size cannot fit the input stream

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26761@github.com>

VZ

unread,
Aug 1, 2026, 8:01:34 AM (3 days ago) Aug 1
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26761)

Thanks for fixing this, will merge soon and backport to 3.2.

FWIW I think it would be better/simpler to use ReadAll() instead of Read() followed by LastRead() check, but this is hardly critical.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26761/c5151328536@github.com>

VZ

unread,
Aug 1, 2026, 8:05:39 AM (3 days ago) Aug 1
to wx-...@googlegroups.com, Subscribed

Closed #26761 via a546a7c.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26761/issue_event/28817552128@github.com>

Reply all
Reply to author
Forward
0 new messages