Cannot create large image

Issue #122 new
Anonymous created an issue

When trying to create a very large image (e.g. 60000x60000), libgd fails with the message:

GD Warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully Segmentation fault (core dumped)

I can imagine this to happen in a 32-bit environment (although a more descriptive message would be useful ...), but it also happens in a 64-bit environment.

I suspect the cause of the problem is that computations for memory allocation are done using int instead of size_t.

I tested this using an application that uses libgd to create a PNG image, on 32-bit and on 64-bit debian testing (with libgd 2.1.0).

I'd appreciate if huge images could be supported on 64-bit architectures in the future.

Comments (3)

  1. Rogier-5

    Sorry for the confusion on the segmentation fault. That is caused by the application, which does not check the return value of gdImageCreateTrueColor, and tries to dereference the NULL pointer that is returned...

    The problem is not the segmentation fault, but just the inability to create images larger than INT_MAX pixels on 64-bit architectures.

  2. Pierre Joye

    The main issue is that some functions are limited to ~15k width or eight, mainly drawing functions.

    This is a limitation I like to kill for gd 2.2 and allow almost unlimited width and height, it is especially important with the growing amount of camera with very high resolution sensors or higher channels numbers (increasing the bytes per pixel).

    the use of cairo for the drawing operations will solve this problem too. All that for 2.2 :)

    Contribs welcome btw :)

  3. Log in to comment