From 9e89a4cb43eb65b1d381914948e21fba467bcf70 Mon Sep 17 00:00:00 2001 From: Senthil455 Date: Fri, 5 Jun 2026 20:43:20 +0530 Subject: [PATCH] Fix boolean type mismatch on Windows when windows.h is included On Windows, the standard windows.h header defines 'boolean' as 'unsigned char' (1 byte), while jpeglib's jmorecfg.h defines it as 'int' (4 bytes) when HAVE_BOOLEAN is not defined. This causes a struct layout mismatch between the library and the application, triggering the size check error in jpegli_CreateDecompress. The fix adds a #ifdef _WIN32 block in include_jpeglib.h (which is included before jpeglib.h) that: - Defines boolean as unsigned char (matching Windows convention) - Sets HAVE_BOOLEAN to prevent jmorecfg.h from redefining it as int - Defines INT32 as signed int (not long) per Windows ABI convention - Sets XMD_H to prevent jmorecfg.h from redefining INT16/INT32 Also updates decode_internal.h and input.cc to include jpeglib.h through include_jpeglib.h so they also benefit from the Windows fix. This mirrors the upstream libjpeg-turbo fix in jconfig.h.in. --- lib/base/include_jpeglib.h | 16 ++++++++++++++++ lib/jpegli/decode_internal.h | 2 +- lib/jpegli/input.cc | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/base/include_jpeglib.h b/lib/base/include_jpeglib.h index e73e7628..fde2afaa 100644 --- a/lib/base/include_jpeglib.h +++ b/lib/base/include_jpeglib.h @@ -13,6 +13,22 @@ // NOLINTBEGIN /* clang-format off */ #include // IWYU pragma: keep + +#ifdef _WIN32 +#undef RIGHT_SHIFT_IS_UNSIGNED +/* Define "boolean" as unsigned char, not int, per Windows custom */ +#ifndef __RPCNDR_H__ +typedef unsigned char boolean; +#endif +#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +/* Define "INT32" as int, not long, per Windows custom */ +#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) +typedef short INT16; +typedef signed int INT32; +#endif +#define XMD_H /* prevent jmorecfg.h from redefining it */ +#endif + #include // IWYU pragma: export #include // IWYU pragma: export /* clang-format on */ diff --git a/lib/jpegli/decode_internal.h b/lib/jpegli/decode_internal.h index b0b7f302..0595a81d 100644 --- a/lib/jpegli/decode_internal.h +++ b/lib/jpegli/decode_internal.h @@ -11,7 +11,7 @@ #include #include -#include "jpeglib.h" +#include "lib/base/include_jpeglib.h" #include "lib/base/compiler_specific.h" #include "lib/jpegli/common_internal.h" #include "lib/jpegli/huffman.h" diff --git a/lib/jpegli/input.cc b/lib/jpegli/input.cc index 0ca01171..fcf7f253 100644 --- a/lib/jpegli/input.cc +++ b/lib/jpegli/input.cc @@ -9,7 +9,7 @@ #include #include -#include "jpeglib.h" +#include "lib/base/include_jpeglib.h" #include "lib/jpegli/common_internal.h" #include "lib/jpegli/types.h"