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.
This commit is contained in:
Luca Bacci 2026-03-27 19:18:14 +01:00
parent 339b1580ea
commit 8a8262e9cd
3 changed files with 44 additions and 30 deletions

View file

@ -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);

View file

@ -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

View file

@ -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);