From 8a8262e9cde0a6368d1da6be8904b26a546adad7 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 27 Mar 2026 19:18:14 +0100 Subject: [PATCH] cairo-script: Fix build on 64bit Windows with LZO enabled lzo_uint is a typedef for a machine-sized unsigned integral. We track sizes using unsigned long, which is machine-sized on most (all?) Unices, but 32bit on 64bit Windows. This means that lzo_uint and unsigned long are not really interchangeable (should have used size_t!). Fix the build by using intermediate variables. The cairo-script file format ensures that uncompressed data fits within 4GB. Fixes -Wincompatible-pointer-types errors. --- util/cairo-script/cairo-script-file.c | 7 ++- util/cairo-script/cairo-script-operators.c | 60 ++++++++++++---------- util/cairo-script/cairo-script-scanner.c | 7 ++- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/util/cairo-script/cairo-script-file.c b/util/cairo-script/cairo-script-file.c index c45cc5086..0da4bb649 100644 --- a/util/cairo-script/cairo-script-file.c +++ b/util/cairo-script/cairo-script-file.c @@ -162,7 +162,6 @@ csi_file_new_from_string (csi_t *ctx, file->base.ref = 1; if (src->deflate) { - uLongf len = src->deflate; csi_object_t tmp_obj; csi_string_t *tmp_str; csi_status_t status; @@ -179,20 +178,26 @@ csi_file_new_from_string (csi_t *ctx, break; case ZLIB: + { #if HAVE_ZLIB + uLongf len = src->deflate; if (uncompress ((Bytef *) tmp_str->string, &len, (Bytef *) src->string, src->len) != Z_OK) #endif status = _csi_error (CAIRO_STATUS_NO_MEMORY); break; + } case LZO: + { #if HAVE_LZO + lzo_uint len = src->deflate; if (lzo2a_decompress ((lzo_bytep) src->string, src->len, (lzo_bytep) tmp_str->string, &len, NULL)) #endif status = _csi_error (CAIRO_STATUS_NO_MEMORY); break; + } } if (_csi_unlikely (status)) { csi_string_free (ctx, tmp_str); diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c index a5eca6ffc..b3b03457f 100644 --- a/util/cairo-script/cairo-script-operators.c +++ b/util/cairo-script/cairo-script-operators.c @@ -1758,46 +1758,47 @@ _mmap_bytes (const struct mmap_vec *vec, int count) static void * inflate_string (csi_t *ctx, csi_string_t *src) { - uLongf len; uint8_t *bytes; - len = src->deflate; - bytes = _csi_alloc (ctx, len + 1); + bytes = _csi_alloc (ctx, src->deflate + 1); if (bytes == NULL) return NULL; switch (src->method) { - default: - case NONE: - free (bytes); - return NULL; - case ZLIB: + { #if HAVE_ZLIB - if (uncompress ((Bytef *) bytes, &len, - (Bytef *) src->string, src->len) != Z_OK) -#endif + uLongf length = src->deflate; + if (uncompress ((Bytef *) bytes, &length, + (Bytef *) src->string, src->len) == Z_OK) { - _csi_free (ctx, bytes); - return NULL; + bytes[length] = '\0'; + return bytes; } - break; - - case LZO: -#if HAVE_LZO - if (lzo2a_decompress ((Bytef *) src->string, src->len, - (Bytef *) bytes, &len, - NULL)) #endif - { - _csi_free (ctx, bytes); - return NULL; - } break; } + case LZO: + { +#if HAVE_LZO + lzo_uint length = src->deflate; + if (lzo2a_decompress ((Bytef *) src->string, src->len, + (Bytef *) bytes, &length, + NULL) == LZO_E_OK) + { + bytes[length] = '\0'; + return bytes; + } +#endif + break; + } + case NONE: + default: + break; + } - bytes[len] = '\0'; - return bytes; + _csi_free (ctx, bytes); + return NULL; } static csi_status_t @@ -2982,7 +2983,6 @@ _image_read_raw (csi_t *ctx, len == src->datum.string->deflate) { csi_string_t *s = src->datum.string; - unsigned long out = s->deflate; switch (s->method) { default: @@ -2992,21 +2992,27 @@ err_decompress: return _csi_error (CSI_STATUS_READ_ERROR); case ZLIB: + { #if HAVE_ZLIB + uLongf out = s->deflate; if (uncompress ((Bytef *) data, &out, (Bytef *) s->string, s->len) != Z_OK) #endif goto err_decompress; break; + } case LZO: + { #if HAVE_LZO + lzo_uint out = s->deflate; if (lzo2a_decompress ((Bytef *) s->string, s->len, (Bytef *) data, &out, NULL)) #endif goto err_decompress; break; + } } } else diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c index 167cd7a1e..09677a1e1 100644 --- a/util/cairo-script/cairo-script-scanner.c +++ b/util/cairo-script/cairo-script-scanner.c @@ -1595,7 +1595,10 @@ _translate_string (csi_t *ctx, #if HAVE_LZO if (method == NONE && buf_len > 16) { - unsigned long mem_len = 2*string->len > LZO2A_999_MEM_COMPRESS ? 2*string->len : LZO2A_999_MEM_COMPRESS; + lzo_uint mem_len = 2 * (lzo_uint)string->len; + if (mem_len < LZO2A_999_MEM_COMPRESS) + mem_len = LZO2A_999_MEM_COMPRESS; + void *mem = malloc (mem_len); void *work = malloc(LZO2A_999_MEM_COMPRESS); @@ -1628,7 +1631,7 @@ _translate_string (csi_t *ctx, method = NONE; deflate = 0; } else { - unsigned long mem_len = 2*string->deflate; + lzo_uint mem_len = 2*string->deflate; void *mem = malloc (mem_len); void *work = malloc(LZO2A_999_MEM_COMPRESS);