Skip to content

Commit d87f9ed

Browse files
authored
heifload: limit per-image memory usage to 2GB by default (#4514)
The existing unlimited flag can be used to remove this
1 parent 6c52989 commit d87f9ed

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ master
3232
- jxlsave writes in chunks, for lower memory use on large images (but we now
3333
need libjxl 0.11 at minimum)
3434
- increase minimum version of libheif dependency to 1.11.0
35+
- heifload: limit per-image memory usage to 2GB (requires libheif 1.20.0+).
3536

3637
8.16.1
3738

libvips/foreign/heifload.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ vips_foreign_load_heif_build(VipsObject *object)
355355
*/
356356
heif_context_set_maximum_image_size_limit(heif->ctx,
357357
heif->unlimited ? USHRT_MAX : 0x4000);
358+
#ifdef HAVE_HEIF_MAX_TOTAL_MEMORY
359+
if (!heif->unlimited)
360+
heif_context_get_security_limits(heif->ctx)
361+
->max_total_memory = 2UL * 1024 * 1024 * 1024;
362+
#endif /* HAVE_HEIF_MAX_TOTAL_MEMORY */
358363
#ifdef HAVE_HEIF_GET_DISABLED_SECURITY_LIMITS
359364
if (heif->unlimited)
360365
heif_context_set_security_limits(heif->ctx,

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ if libheif_dep.found()
500500
cfg_var.set('HAVE_HEIF_ERROR_SUCCESS', libheif_dep.version().version_compare('>=1.17.0'))
501501
# heif_get_disabled_security_limits added in 1.19.0
502502
cfg_var.set('HAVE_HEIF_GET_DISABLED_SECURITY_LIMITS', cpp.has_function('heif_get_disabled_security_limits', prefix: '#include <libheif/heif.h>', dependencies: libheif_dep))
503+
# heif_security_limits.max_total_memory added in 1.20.0
504+
cfg_var.set('HAVE_HEIF_MAX_TOTAL_MEMORY', cpp.has_member('struct heif_security_limits', 'max_total_memory', prefix: '#include <libheif/heif.h>', dependencies: libheif_dep))
503505
endif
504506

505507
# need v0.11+ for chunked write

0 commit comments

Comments
 (0)