Skip to content

Apply AllocationLimitMegabytes against the total size of multi-frame images before attempting to decode them #2850

@antonfirsov

Description

@antonfirsov

Discussed in #2849

Originally posted by antonfirsov December 17, 2024

Configuration.Default.MemoryAllocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
{
    AllocationLimitMegabytes = 16
});

// Should throw InvalidMemoryOperationException when the total size of all frames
// to allocate for this image would be over 16MB, even if the individual frame sizes are below 16MB.
var img = Image.Load("multiframe.gif");

Even though strictly speaking this would be a hack since the allocation limit is originally meant to be per-buffer, #2848 made me think this is something users want us to do. For built-in decoders, this is possible to implement by adding an internal validation method toMemoryAllocator; we can figure out later whether we want to make the feature available to external decoders.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions