strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.
Other
1.75k stars 302 forks source link

1.19.0: API break in `heif_context_set_maximum_image_size_limit` after commit 2374ade #1359

Closed kleisauke closed 3 days ago

kleisauke commented 4 days ago

After commit 2374ade0a24f107d5de8fb6bd5f9ceef04b6c510, there's a breaking change in the heif_context_set_maximum_image_size_limit() API. Previously, this function restricted the maximum dimension along each axis; it now limits the total pixel count of the image.

Condensed diff:

@@ -2,6 +2,6 @@
   // of the image size (width * height) will be "maximum_size * maximum_size".
   void set_maximum_image_size_limit(uint32_t maximum_size)
   {
-    m_maximum_image_size_limit = uint64_t(maximum_size) * maximum_size;
+    m_limits.max_image_size_pixels = maximum_size;
   }

This change impacts libvips: https://github.com/libvips/libvips/blob/v8.16.0/libvips/foreign/heifload.c#L353-L356

For example, nearly all images are failing with the following error:

heif: Memory allocation error: Security limit exceeded: Image size 290x442 exceeds the maximum image size 16384
 (6.1000)

/cc @jcupitt @lovell FYI.

farindk commented 4 days ago

Right, thanks for the report. I'll change this.

farindk commented 4 days ago

BTW: in your libvips code, when you want "unlimited" image sizes, you currently set the limit to USHRT_MAX, which is 65535. This is a high limit, but not "unlimited". To get really "unlimited" (with v1.19.1), you should use

struct heif_security_limits* limits = heif_context_get_security_limits(context);
limits->max_image_size_pixels = 0; // setting to zero disables the limit (starting with v1.19.1)

Of course you might want to process the image tile by tile for these extreme sizes.

On this page you find an example image with a size > 65535x65535: https://github.com/farindk/tiled-image-viewer

kleisauke commented 3 days ago

Thanks! I confirm commit e394bbe0dde70ab4218ca7ba7040186095d313ca (available in v1.19.1) fixes this.

farindk commented 3 days ago

Thanks for the confirmation.