Skip to content

Commit 1beb5dd

Browse files
authored
heifload: prevent possible int overflow for large images (#4399)
i.e. when the `unlimited` flag is set (> 16384x16384).
1 parent 9ab6784 commit 1beb5dd

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- matrixload: fix file format detect for some matrix types
2424
- radload: improve sanity check of colour-related headers [lovell]
2525
- heifsave: reject multiband images [lovell]
26+
- heifload: prevent possible int overflow for large images [kleisauke]
2627

2728
10/10/24 8.16.0
2829

libvips/foreign/heifload.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ vips_foreign_load_heif_build(VipsObject *object)
351351

352352
heif->ctx = heif_context_alloc();
353353
#ifdef HAVE_HEIF_SET_MAX_IMAGE_SIZE_LIMIT
354+
/* heifsave is limited to a maximum image size of 16384x16384,
355+
* so align the heifload defaults accordingly.
356+
*/
354357
heif_context_set_maximum_image_size_limit(heif->ctx,
355358
heif->unlimited ? USHRT_MAX : 0x4000);
356359
#endif /* HAVE_HEIF_SET_MAX_IMAGE_SIZE_LIMIT */
@@ -993,7 +996,7 @@ vips_foreign_load_heif_generate(VipsRegion *out_region,
993996
}
994997

995998
memcpy(VIPS_REGION_ADDR(out_region, 0, r->top),
996-
heif->data + heif->stride * line,
999+
heif->data + (size_t) heif->stride * line,
9971000
VIPS_IMAGE_SIZEOF_LINE(out_region->im));
9981001

9991002
/* We may need to swap bytes and shift to fill 16 bits.

libvips/foreign/heifsave.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ vips_foreign_save_heif_write_block(VipsRegion *region, VipsRect *area,
471471
int page = (area->top + y) / heif->page_height;
472472
int line = (area->top + y) % heif->page_height;
473473
VipsPel *p = VIPS_REGION_ADDR(region, 0, area->top + y);
474-
VipsPel *q = heif->data + line * heif->stride;
474+
VipsPel *q = heif->data + (size_t) heif->stride * line;
475475

476476
if (vips_foreign_save_heif_pack(heif,
477477
q, p, VIPS_REGION_N_ELEMENTS(region)))

0 commit comments

Comments
 (0)