Looks like in most Linux distributions due to the memory limit of 512MB in libheif source code, we cannot open photos which needs higher than 512MB of memory to decode.
Thanks for sharing this! I was running into issues with large HEIF images, and this fix is exactly what I needed. Installing libheif-highmem worked like a charm. Really appreciate the info!