Commit Graph
132 Commits
Author SHA1 Message Date
MarkLee131 a546a7c518 Reject TGA images whose declared size cannot fit the input stream
ReadTGA() sized both the image and its scratch buffer from the header's
width, height and bpp without comparing them against the input stream,
and never checked how much data the bulk reads actually returned. A
22 byte file declaring a 31232x16382 image at 24bpp therefore allocated
1.5 GB twice over, and, because a short read went undetected, LoadFile()
returned true and handed back an image of the declared size that the
file never contained.

Reject dimensions whose claimed image size cannot fit the stream before
allocating anything: uncompressed types must fit exactly, while the RLE
variants are allowed up to 128:1 expansion, since each packet costs
1 + pixelSize input bytes and yields at most 128 * pixelSize output
bytes. Also check LastRead() after the header read and after each of the
three uncompressed bulk reads, so that a truncated file is reported as a
failure instead of a success, as imagpcx.cpp has done since #26624;
DecodeRLE() already validated its own reads.

Fixes #26760.

Closes #26761.
2026-08-01 13:59:48 +02:00
Paul Cornett 32856caa7a Avoid -Wdouble-promotion warnings 2026-07-16 20:44:58 -07:00
dxbjavid c77b7ebd2a Fix potentially using uninitialised data in PCX image handler
Reject truncated reads to avoid uninitialised data.

Closes #26624.
2026-06-23 20:00:54 +02:00
dxbjavid 788b458112 Avoid uninitialised palette read in wxXPMDecoder::ReadData()
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK ASAN not compatible (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxQt (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxX11 (push) Has been cancelled
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Has been cancelled
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxDFB (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK UBSAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Has been cancelled
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Has been cancelled
CMake builds / macOS latest wxGTK 3 Unix Makefiles (push) Has been cancelled
CMake builds / MSW/MSVC wxMSW (push) Has been cancelled
CMake builds / MSW/Clang wxMSW (push) Has been cancelled
CMake builds / macOS latest wxOSX Ninja (push) Has been cancelled
CMake builds / macOS 14 wxOSX Xcode (push) Has been cancelled
CMake builds / macOS 14 wxIOS (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 5.15 (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 6.10 (push) Has been cancelled
Mac builds / wxMac ARM ASAN not compatible (push) Has been cancelled
Mac builds / wxMac Universal C++14 (push) Has been cancelled
Mac builds / wxiOS Simulator on Silicon Mac (push) Has been cancelled
Mac builds / wxiOS (push) Has been cancelled
Mac builds / wxMac Intel C++17 (push) Has been cancelled
Mac Xcode builds / iOS Simulator static (push) Has been cancelled
Mac Xcode builds / macOS dynamic Release (push) Has been cancelled
Mac Xcode builds / iOS static Debug (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Release x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 Debug Win32 (push) Has been cancelled
MSW builds / wxMSW vs2022 Release arm64 (push) Has been cancelled
MSW builds / wxMSW vs2026 DLL Release x64 (push) Has been cancelled
MSW cross-builds / wxMSW 64 bits not compatible (push) Has been cancelled
MSW cross-builds / wxMSW/Univ (push) Has been cancelled
MSW cross-builds / wxMSW 32 bits (push) Has been cancelled
Code Checks / Check Spelling (push) Has been cancelled
Code Checks / Check Whitespace (push) Has been cancelled
Code Checks / Check Mixed EOL (push) Has been cancelled
Code Checks / Check C++ Style (push) Has been cancelled
Code Checks / Check All Headers In allheaders.h (push) Has been cancelled
Update Documentation / Update Online Documentation (push) Has been cancelled
This function allocates the palette r/g/b arrays from the colour count
given in the XPM header but fills them by walking the colour map, so a
malformed file that reuses the same key on more than one colour line
collapses those lines into a single map entry and leaves the tail of the
arrays uninitialised. wxPalette() then copies that uninitialised memory
into the palette later returned by GetPalette(), and in debug builds the
wxASSERT(i == colors_cnt) at the end fires.

Use the actual number of distinct colours in the map as the size for
the arrays and the palette to fix this.

Also add a test loading an XPM triggering this issue.

Closes #26595.
2026-06-16 00:34:15 +02:00
dxbjavid 7ee01fa850 Validate background colour index in wxGIFDecoder::LoadGIF()
Don't set background colour to uninitialized memory contents, just
ignore the invalid index.

Closes #26582.
2026-06-13 20:42:07 +02:00
Maarten Bent a113ddc9e5 Add some guards against missing build options 2026-06-06 12:43:17 +02:00
dxbjavid e4a462d4bc Fix palette buffer overflow in wxGIFHandler::SaveFile()
The image palette can have more than the 256 entries a GIF supports, for
example when the image was loaded from an XPM that declares a larger
colour count. wxGIFHandler_GetPalette(), called when saving a GIF,
copied every entry into the caller's fixed wxRGB pal[256] buffer,
overflowing it.

Such an image can't be represented as a GIF, so reject the save with an
error message instead of overflowing the buffer or writing out a silently
truncated palette.

Closes #26532.
2026-05-31 15:45:18 +02:00
dxbjavid 830ec3c439 Avoid writing beyond the buffer end for GIFs with zero size
Reject GIF frames with zero width or height to avoid writing beyond the
(empty) buffer returned by malloc(0).

Closes #26524.
2026-05-31 15:33:05 +02:00
dxbjavid 86bc0762ef Validate decoded pixel indices in wxGIFDecoder::ConvertToImage()
Avoid reading uninitialized memory if any of the pixels in the input
data reference entries beyond the end of the palette.

Closes #26521.
2026-05-31 14:35:51 +02:00
Vadim Zeitlin ccff9fe0f3 Make recently added wxXPMDecoder test case really pass
We need to use memmove() and not strncpy() in wxXPMDecoder code as
nothing guarantees that the source and destination regions don't overlap
and they did overlap, in fact, for the test case added as part of
46f928d057 (Fix buffer overflow on invalid width in wxXPMDecoder,
2026-05-27).

Also make the test itself more explicit by hard-coding the test XPM
instead of constructing it dynamically.

See #26519.
2026-05-30 23:02:11 +02:00
dxbjavid 46f928d057 Fix buffer overflow on invalid width in wxXPMDecoder
Fix integer overflow in wxXPMDecoder::ReadData() when computing
width*chars_per_pixel: a header with a (very) large width could result
in wrapping around and result in reasonable but yet invalid value, which
could let the key-reading loop run off the end of the buffer.

Compute the product in 64-bits to avoid the overflow.

Closes #26519.
2026-05-30 17:12:17 +02:00
dxbjavid 83d55d0a90 Fix one-byte over-read in IFF decomprle replicate packet
The replicate-run branch reads the packet's data byte after only
checking that one source byte remains, but it consumes two (the control
byte plus the data byte). A BODY ending in a lone replicate control byte
then reads one byte past the input buffer. Require two bytes left,
matching the literal-run check above.

Closes #26518.
2026-05-30 17:00:44 +02:00
dxbjavid b47e2bb352 Validate 4-bit BMP palette index against number of colors
Fix out-of-bounds read when decoding 4bpp BMP with invalid palette
indices.

Closes #26511.
2026-05-26 23:51:04 +02:00
dxbjavid a676a0f1f5 Validate ANI frame indices against loaded icon count
The SEQ chunk of an ANI file gives a 32-bit image index per animation
step.  These values were stored into wxANIFrameInfo::m_imageIndex
verbatim, without any check against the number of icon chunks actually
loaded into m_images.  wxANIDecoder::ConvertToImage() and
GetTransparentColour() then used the value as an index into m_images
directly, so a malformed ANI file could trigger an out-of-bounds vector
access when the file is displayed.

Reject the file in Load() if any of the indices is negative or points
past the end of m_images, and also reject files that produced no icon
chunks at all so the subsequent m_images[0] reference is safe.

Closes #26492.
2026-05-25 19:08:07 +02:00
dxbjavid c8c1ca9bb8 Stop reading past data end in truncated IFF BODY decode
Fix iff body truncation over-read in wxIFFDecoder::ReadIFF:
wxIFFDecoder::ReadIFF() sets chunkLen = dataend - dataptr on the
truncated BODY path, which is 8 too large because bodyptr lives 8 bytes
after dataptr. The non-RLE decode loop below then reads up to 8 bytes
past the end of databuf; clamp chunkLen to dataend - bodyptr instead.

Closes #26505.
2026-05-25 14:28:41 +02:00
dxbjavid b2d7c29f29 Reject TGA files with non-zero colour map origin
ReadTGA() in src/common/imagtga.cpp allocates the palette buffer as
paletteLength * palEntrySize bytes (palette indices 0..paletteLength-1)
but the loop that fills it writes each entry at index paletteStart + i.
The paletteStart and paletteLength values come straight from the TGA
header (bytes 3-7 of the colour map specification) and aren't bounded
against each other. For any file with paletteStart > 0, the calls to
Palette_SetRGB()/Palette_SetRGBA() write past the end of the buffer:
e.g. paletteStart=100, paletteLength=10, palettebpp=24 allocates 30
bytes but writes at offsets 100..129. The subsequent
image->SetPalette(wxPalette((int) paletteLength, &palette[0], ...))
also reads from index 0 onward, so the rest of the loader was already
implicitly assuming paletteStart == 0.

Add an explicit early-return wxTGA_INVFORMAT in the colour-mapped
branch when paletteStart is non-zero, which is the assumption the
existing code makes anyway.

Closes #26493.
2026-05-23 20:55:04 +02:00
dxbjavid 71d58842eb Reject GIF files with LZW minimum code size > 11
The minimum code size byte that follows the local colour table in
wxGIFDecoder::LoadGIF() is only checked for <= 0. dgif() sizes
ab_prefix/ab_tail with allocSize = 4096 + 1, so a value of 12
starts ab_free at 4098 and the first alphabet update at
gifdecod.cpp:457 writes one entry past the end of both arrays. The
existing wxASSERT(ab_free < allocSize) already flagged this in debug
builds. The new wxImage::BadGIFLZWMinCodeSize test feeds a 37-byte
2x1 GIF with code size 12 to LoadFile and asserts it is rejected.

Closes #26501.
2026-05-23 16:48:22 +02:00
dxbjavid 49a4dbee56 Stop reading past wxCharBuffer end on unterminated XPM quote
The quote-stripping loop in wxXPMDecoder::ReadFile() sets p = q + 1
after strncpy(). If the closing " was missing, q stopped at the
buffer terminator, so p ended up one past it and the outer for-loop's
p++ then dereferenced two bytes off the end of the wxCharBuffer.
Mirror the already-existing /*-comment treatment and break out of the
loop when *q == '\0'.

Closes #26499.
2026-05-23 16:19:06 +02:00
jmestwa-coder d22a91e952 Validate IFF BMHD fields to prevent pixel-buffer overflow
wxIFFDecoder::ReadIFF() in src/common/imagiff.cpp parses the BMHD
chunk without bounding the width, height or bitplane count. The
subsequent pixel buffer is allocated with

    m_image->p = new byte[bmhd_width * bmhd_height * 3];

using signed-int multiplication. With bmhd_width = 21849 and
bmhd_height = 65535 (both legal 16-bit BMHD values) the product
4,295,622,645 overflows int and wraps down to 655,349, so only
~640 KiB is actually allocated. The BODY decode loop then writes
3 * bmhd_width bytes per row, so a BODY chunk supplying just 10
lineskips of zeros (lineskip = 2732 for this width, total 27,320
bytes) is enough to overrun the allocation. A bmhd_bitplanes or
bmhd_width of zero also makes lineskip * bmhd_bitplanes zero and
causes a divide-by-zero in the height computation a few lines
later.

Reject malformed BMHD chunks at parse time: require positive
width, height and bitplane count, cap the bitplane count at 32
(the largest format the decoder handles is 24-bit ILBM), and cap
bmhd_width * bmhd_height so that the product multiplied by 3
stays within INT_MAX. This makes the existing int-typed buffer
size computation safe and keeps the patch local to the BMHD
parsing branch.

A unit test in tests/image/image.cpp builds the malformed IFF
described above in memory, registers the IFF handler and asserts
that LoadFile() rejects it; without the fix the test triggers a
heap-buffer-overflow during BODY decoding.

Closes #26497.
2026-05-22 16:44:00 +02:00
dxbjavid d1d6605e93 Reject BMP RLE absolute runs that overrun the current scanline
In src/common/imagbmp.cpp::LoadBMPData() the absolute-mode branches of
both the BI_RLE4 (around line 763) and BI_RLE8 (around line 870) decode
loops increment 'column' for each pixel without checking it against
'width'. The image buffer is sized width * height * 3 and 'poffset' is
computed as line * width * 3 + column * 3, so an absolute escape with
a count larger than (width - column) keeps writing through the rest of
the row and into adjacent rows or past the end of the buffer entirely
on the last decoded scanline.

The neighbouring encoded-mode branches at lines 798 and 896 already use
"&& column < width" to clamp runs to the row width, and the delta-mode
branch at lines 758 and 863 rejects out-of-range row offsets, so the
absolute branches are the only RLE paths left without bounds checking.

Reject the file with return false when the absolute run would extend
past the right edge of the current row, matching the existing
"return false on malformed input" pattern in the same function.

Add a regression test that loads a 4x4 8bpp RLE BMP with an absolute
escape claiming 100 pixels on the first row and expects the loader to
fail rather than write past the image buffer.

Closes #26496.
2026-05-22 16:37:21 +02:00
MarkLee131 c7eb871978 Reject IFF images with out-of-range transparent colour index
Following review on the previous commit, switch from silently ignoring
an out-of-bounds BMHD transparent colour index to rejecting the file
outright in wxIFFDecoder::ConvertToImage. The earlier "ignore" approach
let the load succeed, which made the BadIFF test pass only as a side
effect of corruption from the unrelated overrun and so failed
intermittently in some wxMSW builds.

Apply the bounds check using the form suggested in the PR review.
2026-05-21 00:51:52 +08:00
MarkLee131 8f15d11704 Avoid out-of-bounds palette write in wxIFFDecoder::ConvertToImage
The transparent colour index from the IFF BMHD chunk is a 16-bit
value stored unclamped in m_image->transparent. Using it as a
palette index without checking it against the CMAP-derived colour
count writes 3 bytes at an attacker-controlled offset past the
palette buffer.

Validate the index against the actual palette size before applying
the magenta mask.
2026-05-21 00:51:52 +08:00
MarkLee131 f429679132 Avoid out-of-bounds read in wxXPMDecoder::ReadFile on unterminated comment
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK ASAN not compatible (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxQt (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxX11 (push) Has been cancelled
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Has been cancelled
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxDFB (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK UBSAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Has been cancelled
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Has been cancelled
CMake builds / macOS latest wxGTK 3 Unix Makefiles (push) Has been cancelled
CMake builds / MSW/MSVC wxMSW (push) Has been cancelled
CMake builds / MSW/Clang wxMSW (push) Has been cancelled
CMake builds / macOS latest wxOSX Ninja (push) Has been cancelled
CMake builds / macOS 14 wxOSX Xcode (push) Has been cancelled
CMake builds / macOS 14 wxIOS (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 5.15 (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 6.10 (push) Has been cancelled
Mac builds / wxMac ARM ASAN not compatible (push) Has been cancelled
Mac builds / wxMac Universal C++14 (push) Has been cancelled
Mac builds / wxiOS Simulator on Silicon Mac (push) Has been cancelled
Mac builds / wxiOS (push) Has been cancelled
Mac builds / wxMac Intel C++17 (push) Has been cancelled
Mac Xcode builds / iOS Simulator static (push) Has been cancelled
Mac Xcode builds / macOS dynamic Release (push) Has been cancelled
Mac Xcode builds / iOS static Debug (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Release x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 Debug Win32 (push) Has been cancelled
MSW builds / wxMSW vs2022 Release arm64 (push) Has been cancelled
MSW builds / wxMSW vs2026 DLL Release x64 (push) Has been cancelled
MSW cross-builds / wxMSW 64 bits not compatible (push) Has been cancelled
MSW cross-builds / wxMSW/Univ (push) Has been cancelled
MSW cross-builds / wxMSW 32 bits (push) Has been cancelled
Code Checks / Check Spelling (push) Has been cancelled
Code Checks / Check Whitespace (push) Has been cancelled
Code Checks / Check Mixed EOL (push) Has been cancelled
Code Checks / Check C++ Style (push) Has been cancelled
Code Checks / Check All Headers In allheaders.h (push) Has been cancelled
Update Documentation / Update Online Documentation (push) Has been cancelled
When the inner loop scanning for the '*/' that closes a '/*' comment
exits because *q == '\0' (no closing marker before end-of-buffer),
the subsequent strlen(q + 2) reads past the allocated wxCharBuffer.

Bail out of the outer loop in that case.

Closes #26442, #26444.
2026-05-11 01:12:07 +02:00
MarkLee131 edae38f44a Avoid out-of-bounds line-buffer read in wxPCXHandler::LoadFile
The PCX header's width and bytesperline are independent fields,
never cross-validated. A header with width > bytesperline produces a
small per-line buffer p and then reads p[i] for i < width past the
buffer end (the 24-bit branch additionally reads p[i + 2 * bytesperline]).

Reject the file when width exceeds bytesperline, or when either is
non-positive.

Closes #26441, #26443.
2026-05-11 01:10:25 +02:00
MarkLee131 b305cb4e4d Avoid out-of-bounds palette read in 8bpp BMP decoder
The non-RLE 8bpp branch at imagbmp.cpp:903, plus the RLE absolute and
RLE encoded branches a few lines above, all index cmap[aByte] without
checking aByte against the palette colour count. A BMP that pairs a
small palette with a colour-index byte >= ncolors reads past the
palette and the value flows into the decoded pixel.

Reject the file (return false) at each site, matching the surrounding
"return false on malformed input" pattern.

Closes #26438.

Closes #26439.
2026-05-11 00:29:40 +02:00
GenevensiS 4c2ffb0c5b Add support for working with PNG "Description" text chunk
Add wxIMAGE_OPTION_PNG_DESCRIPTION which is filled with the contents of
the (first) "Description" chunk from the PNG file when loading it and
saved into such (iTXt) chunk when saving.

Fixes #25556.

Closes #25565.
2025-06-29 01:35:38 +02:00
Vadim Zeitlin edde669769 Avoid warning about possibly uninitialized variable in a test
MSVS warns about "width" being possibly uninitialized, so do initialize
it and also initialize "height" for consistency.
2025-06-17 17:07:15 +02:00
Maarten Bent 312fa745d6 Update wxWEBPHandler tests 2025-05-10 17:19:30 +02:00
Hermann Höhne 15a2a622ec Add support for WebP image file format via libwebp. 2025-05-10 17:18:29 +02:00
Vadim Zeitlin 932bd6fa5e Add wxCursor constructor from wxBitmap
In all ports implementing creating wxCursor from wxImage the code for
creating it from wxBitmap was already there, so just factor it out to
allow using it directly, to avoid a conversion to and from wxImage when
we already have a wxBitmap.

For the other ports (wxX11 and wxDFB), leave this ctor unimplemented,
just as it was already the case for the one taking wxImage.
2025-05-05 21:48:33 +02:00
Vadim Zeitlin 376dcbff66 Add a pseudo-test to check wxImage resize quality
This provides at least some way of comparing the results of the
different rescaling algorithms.
2025-03-18 17:48:22 +01:00
Paul Cornett 4d5fbf5afa Fix BMP test under Wine
Unix builds / Ubuntu 24.04 wxGTK with ASAN (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Waiting to run
Unix builds / Ubuntu 18.04 wxQt (push) Waiting to run
Unix builds / Ubuntu 18.04 wxX11 (push) Waiting to run
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Waiting to run
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Waiting to run
Unix builds / Ubuntu 24.04 wxGTK with UBSAN (push) Waiting to run
Unix builds / Ubuntu 18.04 wxDFB (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Waiting to run
CMake builds / Windows MSVC (push) Waiting to run
CMake builds / macOS 14 wxIOS (push) Waiting to run
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Waiting to run
CMake builds / macOS 14 wxOSX (push) Waiting to run
Mac builds / wxMac Universal C++14 (push) Waiting to run
Mac builds / wxMac ARM with ASAN (push) Waiting to run
Mac builds / wxiOS (push) Waiting to run
Mac builds / wxMac macOS 14 (push) Waiting to run
Mac builds / wxMac Intel C++17 (push) Waiting to run
Mac Xcode builds / iOS static Debug (push) Waiting to run
Mac Xcode builds / iOS Simulator static (push) Waiting to run
Mac Xcode builds / macOS dynamic Release (push) Waiting to run
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Waiting to run
MSW builds / wxMSW vs2019 DLL Release x64 (push) Waiting to run
MSW builds / wxMSW vs2019 Debug Win32 (push) Waiting to run
MSW builds / wxMSW vs2022 Release arm64 (push) Waiting to run
MSW builds / msw-msys2-clang (push) Waiting to run
MSW cross-builds / wxMSW 64 bits (push) Waiting to run
MSW cross-builds / wxMSW/Univ (push) Waiting to run
MSW cross-builds / wxMSW 32 bits (push) Waiting to run
Code Checks / Check Spelling (push) Waiting to run
Code Checks / Check Whitespace (push) Waiting to run
Code Checks / Check Mixed EOL (push) Waiting to run
Code Checks / Check C++ Style (push) Waiting to run
Code Checks / Check All Headers In allheaders.h (push) Waiting to run
Apparently Wine does not handle BMP exactly like Windows
2025-02-22 15:10:03 -08:00
Paul Cornett e7e352d5f4 Handle BMP alpha the same way Windows does
Windows ignores alpha unless the format is 8-bit ARGB, and alpha is not all zeros
2025-02-22 13:48:16 -08:00
Paul Cornett 45a7efd642 Up-scale BMP color components using Windows-compatible method
This allows tests to compare against native behavior under Windows
2025-02-22 13:01:52 -08:00
Vadim Zeitlin 7d2abd119b Save test images in the test if WX_TEST_SAVE_SCALED_IMAGES is set
Allow to easily dump the generated images without recompiling the test,
as was necessary before, by simply setting an environment variable.
2025-02-22 16:43:14 +01:00
Vadim Zeitlin 05c441ea55 Replace ASSERT_IMAGE_EQUAL_TO_FILE macro with a function
Don't use multiline macro when we can just use a function instead.
2025-02-22 16:43:14 +01:00
Paul Cornett 5ff83b400c Avoid assertion failure on BMP file with invalid or too-large size 2024-11-27 18:54:12 -08:00
Paul Cornett 05404fd379 Avoid negative shift count with valid BMP file
Detected by undefined behavior sanitizer, on a file with 16 bpp and a color
component of more than 8 bits. Fix by using a different, and more accurate,
method to scale color components to 8 bits.
2024-11-27 18:54:12 -08:00
Paul Cornett 443b64c11c Avoid memory overwrite on malformed BMP with invalid RLE data 2024-11-27 18:54:12 -08:00
Paul Cornett dc83c4ca0e Fix loading ICO files with fully transparent alpha
Windows behavior is to ignore alpha in that case. Broken by b21642b72b
2024-11-19 13:50:33 -08:00
Paul Cornett b321af212d Fix loading ICO files with alpha
The rules are different than for BMP files. Broken by b21642b72b (Fix loading
BMP files which use 32bpp but do not have valid alpha (#24939), 2024-11-04)
See #24955
2024-11-18 16:55:19 -08:00
paulcor b21642b72b Fix loading BMP files which use 32bpp but do not have valid alpha (#24939)
Based on the behavior of WIN32 LoadFile(), and the gdk-pixbuf BMP loader source
code, the alpha values are ignored unless the compression method is BI_BITFIELDS.
See #10915, #24219
2024-11-04 19:38:54 -08:00
Maarten Bent bab5e37c56 Add more wxCursor tests
Move tests to image.cpp.
2024-03-27 20:14:09 +01:00
Vadim ZeitlinandPB c2e5749443 Fix crash when reading truncated GIF image
Add a unit test case checking that we don't crash any longer and still
read the image meta data correctly, even if not the image itself.

Also add another check for EOF and possibly invalid "bits" value in
another place where we were not checking for it when reading from the
stream.

Closes #23409.

Co-authored-by: PB <PBfordev@gmail.com>
2023-07-02 18:06:03 +01:00
Brian Nixon e1e2e982e3 Restore old delta-RLE bitmap background setting
Revert the change introduced in b473163da2
and restore the setting of the background of delta-RLE bitmaps to the
first entry in the colour table. This retains earlier wxWidgets
behaviour and matches Windows `LoadImage()` with `LR_CREATEDIBSECTION`.

Closes #23638.

Closes #23657.
2023-06-20 22:19:47 +02:00
Brian Nixon b473163da2 Correct delta-RLE bitmap background colour
Use black instead of the first palette colour for the implicit
background for RLE bitmaps for consistency with Windows itself.

Closes #23599.
2023-06-04 00:38:39 +02:00
Brian Nixon d78e9fb1cb Correct loading of BI_BITFIELDS bitmaps
This fixes several minor bugs in the loading of `BI_BITFIELDS` bitmaps,
related to handling different header sizes and the colour and alpha
masks.

Closes #23601.
2023-06-03 21:07:40 +02:00
Brian Nixon 28d6234bfe Add image test to compare BMP creation methods
Check that loading BMP files directly using wxDIB and via wxImage
built-in support for them produces the same result (which wasn't the
case for the RLE-compressed bitmaps until the last commit).
2023-05-31 21:19:14 +01:00
Vadim Zeitlin 92664881fe Fix lack of unsharing in wxImage::Clear()
Calling Clear() wrongly modified any other wxImage objects reusing the
same data.

Fix this by adding the missing call to AllocExclusive() to this function
and also add a check for the image validity which was missing there as
well ever since this function was added back in fc3762b5fc (add
wxImage::Clear (patch by troelsk); closes #10141, 2009-01-09).

Also add a unit test.

Closes #23553.
2023-05-18 00:31:15 +02:00
Vadim Zeitlin d56d773a55 Remove CppUnit boilerplate in wxImage unit test
No real changes, just remove all the ugly compatibility macros.
2023-05-18 00:25:35 +02:00