{"record":{"id":"d15eddb163969b96","repo":"SixLabors/ImageSharp","slug":"image-is-too-large-to-encode-in-exr-format","errorCode":null,"errorMessage":"Image is too large to encode in EXR format.","messagePattern":"Image is too large to encode in EXR format\\.","errorType":"exception","errorClass":"ImageFormatException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Exr/ExrEncoderCore.cs","lineNumber":178,"sourceCode":"    /// <param name=\"compression\">The compression to use.</param>\n    /// <param name=\"cancellationToken\">The cancellation token.</param>\n    /// <returns>The array of pixel row offsets.</returns>\n    private ulong[] EncodeFloatingPointPixelData<TPixel>(\n        Stream stream,\n        Buffer2D<TPixel> pixels,\n        int width,\n        int height,\n        List<ExrChannelInfo> channels,\n        ExrCompression compression,\n        CancellationToken cancellationToken)\n        where TPixel : unmanaged, IPixel<TPixel>\n    {\n        ulong bytesPerRow = ExrUtils.CalculateBytesPerRow(channels, (uint)width);\n        uint rowsPerBlock = ExrUtils.RowsPerBlock(compression);\n        ulong bytesPerBlock = bytesPerRow * rowsPerBlock;\n        if (bytesPerRow > uint.MaxValue || bytesPerBlock > int.MaxValue)\n        {\n            throw new ImageFormatException(\"Image is too large to encode in EXR format.\");\n        }\n\n        using IMemoryOwner<float> rgbBuffer = this.memoryAllocator.Allocate<float>(width * 4, AllocationOptions.Clean);\n        using IMemoryOwner<byte> rowBlockBuffer = this.memoryAllocator.Allocate<byte>((int)bytesPerBlock, AllocationOptions.Clean);\n        Span<float> redBuffer = rgbBuffer.GetSpan()[..width];\n        Span<float> greenBuffer = rgbBuffer.GetSpan().Slice(width, width);\n        Span<float> blueBuffer = rgbBuffer.GetSpan().Slice(width * 2, width);\n        Span<float> alphaBuffer = rgbBuffer.GetSpan().Slice(width * 3, width);\n\n        using ExrBaseCompressor compressor = ExrCompressorFactory.Create(compression, this.memoryAllocator, stream, (uint)bytesPerBlock, (uint)bytesPerRow, rowsPerBlock, width);\n\n        ulong[] rowOffsets = new ulong[height];\n        for (uint y = 0; y < height; y += rowsPerBlock)\n        {\n            rowOffsets[y] = (ulong)stream.Position;\n\n            // Write row index.\n            BinaryPrimitives.WriteUInt32LittleEndian(this.buffer, y);","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Exr/ExrEncoderCore.cs#L160-L196","documentation":"The EXR encoder buffers one block of rows and one row of pixel data in memory, so both the bytes-per-row (kept in a uint-backed calculation) and the bytes-per-compression-block (allocated as an int-sized buffer) must fit within 32-bit limits. Images whose width × channels × 4 bytes exceed those bounds throw ImageFormatException because EXR encoding cannot proceed safely on this code path.","triggerScenarios":"Calling SaveAsExr/EncodeAsExr with an image whose bytesPerRow (channels × width × 4) exceeds uint.MaxValue, or whose bytesPerRow × RowsPerBlock(compression) exceeds int.MaxValue — i.e. extremely wide images or huge widths combined with high rows-per-block compression settings.","commonSituations":"Encoding gigapixel panorama tiles or scientific float images with very large widths; picking a compression type that packs many rows per block (e.g. low-resolution variants) on wide images.","solutions":["Reduce the image width (crop, downscale, or tile the image) before EXR export.","Choose a compression type with fewer rows per block to shrink bytesPerBlock.","Reduce channel count (e.g. drop alpha or unused channels) to lower bytes per row."],"exampleFix":"// before\nimage.SaveAsExr(stream); // throws for ultra-wide images\n// after\nif ((ulong)(channels * image.Width * 4) <= uint.MaxValue) image.SaveAsExr(stream);\nelse { using Image tiled = image.Clone(ctx => ctx.Crop(tileWidth, image.Height)); tiled.SaveAsExr(stream); }","handlingStrategy":"validation","validationCode":"ulong bytesPerRow = (ulong)channels * (uint)image.Width * 4;\nif (bytesPerRow > uint.MaxValue || bytesPerRow * rowsPerBlock > int.MaxValue)\n    throw new InvalidOperationException(\"Image too large for EXR encoding.\");","typeGuard":null,"tryCatchPattern":"try { image.SaveAsExr(stream); }\ncatch (ImageFormatException) { /* tile the image or switch compression and retry */ }","preventionTips":["Check width × channels × 4 against uint.MaxValue before EXR export.","Tile very wide images instead of encoding whole panoramas.","Prefer compression types with moderate rows-per-block for wide images."],"tags":["exr","encoding","memory-limit","image-size"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}