strukturag / libheif

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

libheif declines to open large images created by libheif #192

Open paulyc opened 4 years ago

paulyc commented 4 years ago

Issue: libheif declines to open large images created by libheif

Platform: MacOS (likely others)

Steps to reproduce: Github doesn't allow attachments larger than 10 MB so you'll have to download this scanned PNG image (148 MB, 10208x14032px) from my gdrive unless you have a nice fat >100MB image lying around your disk. heif-enc -o Scan00.heif -L Scan00.png heif-convert Scan00.heif Scan00.1.png

Result: libheif produces error message: Could not read HEIF file: Memory allocation error: Security limit exceeded: iloc box contained 85437828 bytes, total memory size would be 85437913 bytes, exceeding the security limit of 52428800 bytes

Temporary workaround: increase MAX_MEMORY_BLOCK_SIZE in libheif/heif_limits.h to something larger than... the largest iloc box you want to open? rebuild/reinstall.

I set it to 500 MB which seems reasonable but I wouldn't really know what is appropriate to submit a full on PR, since, after all, I know just as well why that limit exists and why it was set to 50 MB as anyone knows why Satoshi Nakomoto set the maximum block size to 1 MB in the original bitcoind! Plus, clearly, it shouldn't be creating an image it won't be able to open, in the first place, so that is just the proverbial band-aid on the aortic wound, and the real fix is beyond my knowledge of the code

farindk commented 4 years ago

I increased the memory limit. However, I leave this issue open as a reminder to find a better solution for handling security limits.