Skip to content

Gracefully handle time limit #333

@nicofff

Description

@nicofff

Setting the time resource limit to some value, either by policy or by calling Imagick::setResourceLimit(Imagick::RESOURCETYPE_TIME,$timeout); and executing an action that exceeds that time limit causes the process to exit without returning control to the php code.

From the ImageMagick code here and here it looks like they just call _exit() when the time limit is reached. Not sure if have any control from the calling code, or if I should report this in ImageMagick as well.

Repro case (but any slow code should do):

<?php
Imagick::setResourceLimit(Imagick::RESOURCETYPE_TIME,5); 

try {
    $imagick = new Imagick("giphy.gif");
    $imagick = $imagick->coalesceImages();
    do {
        $imagick->resizeImage(10000, 10000, Imagick::FILTER_BOX, 1);
    } while ($imagick->nextImage());
    $imagick = $imagick->deconstructImages();
    $imagick->writeImages('new_10000x10000.gif', true);
} catch (\Exception $e) {
    var_dump($e);
}

I tried it both with IM6 and 7.
On IM6, o got a single

php: time limit exceeded `Operation canceled' @ fatal/cache.c/GetImagePixelCache/1700.`

before it exited

On IM7 I got a several of those, and then segfaults most of the time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions