Skip to content

AllocationLimitMegabytes seems not to be followed with GIF's #2799

Answered by antonfirsov
ErazerBrecht asked this question in Q&A
Discussion options

You must be logged in to vote

AllocationLimitMegabytes only limit a single allocation while gif-s are multi frame / multi buffer objects.

My recommendation would be to either set DecoderOptions.MaxFrames, or use Image.Identify(Async) before decoding to set a limit for the overall image allocation before decoding:

int totalImageLimitInBytes = 192 * 1024 * 1024;
ImageInfo info = await Image.IdentifyAsync(...);
int frameCount = info.FrameMetadataCollection.Count;

if (info.Width * info.Height * frameCount * sizeof(Rgba32) > totalImageLimitInBytes)
{
    throw new Exception("Image too large.");
}

Note: we shall probably consider a built-in feature to achieve the above.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ErazerBrecht
Comment options

@JimBobSquarePants
Comment options

@JimBobSquarePants
Comment options

Answer selected by ErazerBrecht
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants