That's great, thanks Michael. I'll remove my patch and update from your repo.
On Mon, 5 Apr 2021 at 14:51, Michael Drake
> Hi John,
> Thanks for the patch. It is an improvement and I've applied it.
> I'm currently considering moving the call to gif_initialise_sprite
> into gif_decode_frame so that the bitmap area is always created
> when a client calls gif_decode_frame. At the moment it will only
> happen for the first frame that is to be displayed, which is a
> change in behavior.
> I've fixed decode_gif.c to consult the display flag.
> By the way, your patch had tabs for indent, but that file
> (inexplicably) uses spaces. I changed the patch to use
> spaces to match but I plan to convert the whole file to
> tabs soon.
> Best regards,
> On 03/04/2021 12:33, jcupitt(a)gmail.com wrote:
> > Here's a better version of the patch:
> > (removes a stray create_bitmap call)
> > On Fri, 2 Apr 2021 at 11:58, <jcupitt(a)gmail.com> wrote:
> >> Hi all,
> >> I had a thought regarding memory allocation in libnsgif.
> >> At the moment, calling `gif_initialise()` will parse the GIF file and
> >> allocate memory for rendering. You then call gif_decode_frame() to
> >> decompress and render each frame of the animation.
> >> However, this means just opening the GIF can trigger very large memory
> >> allocations, with no chance for the caller to intervene, except by
> >> putting a hard pixel limit into the bitmap_create() callback. For
> >> example, a 20 byte GIF can cause a 17gb malloc.
> >> How about delaying the allocation of the bitmap until the first call
> >> to gif_decode_frame()? This would allow the caller to check the
> >> detected width and height and apply some kind of size policy before
> >> allowing rendering to occur.
> >> Here's a possible patch that does this. It's very simple and does
> >> affect the API, just the memory behaviour (I think):
> >> John
> > _______________________________________________
> > netsurf-dev mailing list -- netsurf-dev(a)netsurf-browser.org
> > To unsubscribe send an email to netsurf-dev-leave(a)netsurf-browser.org
> Michael Drake https://www.codethink.co.uk/