You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PNG tRNS palette pointer is round-tripped through a ULONG, truncating on 64-bit Windows #216
_gx_image_reader_png_decode stores the PNG tRNS palette pointer in gx_pixelmap_transparent_color, which is a ULONG, and _gx_image_reader_image_decode casts it straight back to a GX_COLOR *. The recovered pointer is then dereferenced as gx_image_reader_png_trans[0] at six sites in gx_image_reader_pixel_read_callback_set.c, and finally handed to _gx_system_memory_free in gx_image_reader_start.c.
ULONG is typedef unsigned long in gx_api.h. Under LP64, which is every 64-bit Unix target, that is 64 bits wide and the round trip is lossless. Under LLP64, which is 64-bit Windows, it is 32 bits against a 64-bit pointer, so the upper half is discarded. The truncated value is almost never zero, so the if (image_reader -> gx_image_reader_png_trans) guard passes, and GUIX reads through a pointer that no longer addresses the allocation and then frees it.
No shipped configuration reaches this today, which is why it has not bitten. The only Windows port is ports/win32, which is 32-bit, and there pointers and unsigned long are the same width. The defect becomes live the moment GUIX gains a 64-bit Windows port — and that is the direction of travel, since USBX, NetX Duo and FileX each added a ports/win64 in this release cycle and GUIX is now the only one of the four without one. An integrator building GUIX for Win64 themselves reaches it already.
Triggering it needs nothing unusual: a PNG carrying a tRNS chunk.
The underlying problem is that the field is overloaded. gx_pixelmap_transparent_color is documented as being for translated GIF images, is assigned GX_TRANSPARENT_COLOR in gx_image_reader_start.c, is copied around by the resize and rotate utilities, and is compared against pixel values in roughly forty places across the display drivers. The PNG path uses it to smuggle a palette pointer through to a later stage. Widening the field would silence the truncation while leaving a pointer being compared against pixel data, so the fix worth making is a separate pointer member on the image reader, set directly by the PNG decoder, with gx_pixelmap_transparent_color left to mean a colour.
Worth fixing before a 64-bit Windows port lands rather than after. Noticed while reviewing the PNG decoder; the compiler already warns on the cast.
Activity