Skip to content

Crash on non-supported input image #2

@jtippet

Description

@jtippet

If a non-supported file format is passed to Image::Hash->new, then the module crashes (around line 105 on v0.03, if using GD backend). The test against $self->{'im'} == 0 is incorrect, as that's not how an undef result gets stored.

I patched it on my copy with this:

my $img = GD::Image->new($self->{'image'});
if (not defined $img) {
    . . . return undef;
}

That fixes the crash.

Sidenote 1: But actually there's still a massive memory leak. If you pass multiple non-image files, you watch perl's RAM usage skyrocket and eventually get OOM-killed. Apparently the image buffer isn't cleaned up in that error path. I imagine that's a bug in libgd (v 2.1.0-3) or its Perl binding (v 2.50).

Sidenote 2: I encountered this problem because my corpus of ".jpg" files contains some files that are actually Windows BMP files with a .jpg extension. Apparently mis-labeling files is fairly common. GD doesn't support Windows BMP files, so it rejects those inputs. It would be helpful if Image::Hash automatically detected this sort of problem, and fell back to ImageMagik or some other backend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions