The Compression Expansion Ratio
Modern compression formats compress solid color or repetitive pattern blocks with extreme efficiency. A JPEG with dimensions of 40,000 x 40,000 pixels can weigh just 50KB on disk.
However, when backend libraries (ImageMagick, Sharp, PIL) decompress the file, they allocate a raw RGBA memory buffer: 40,000 * 40,000 * 4 bytes = 6.4 GB RAM.
Always parse image dimensions from headers before passing buffers to image decoders, and enforce hard limits (e.g. max 25 Megapixels).