danielgtaylor / jpeg-archive

Utilities for archiving JPEGs for long term storage.
1.16k stars 121 forks source link

Memory leak #109

Open ThomasdenH opened 4 years ago

ThomasdenH commented 4 years ago

Compiling with CFLAGS="-fsanitize=address" will reliably crash jpeg-hash with the following image file:

index

zvezdochiot commented 4 years ago

https://github.com/danielgtaylor/jpeg-archive/blob/8da4bf76b6c3c0e11e4941294bfc1857c119419b/src/hash.c#L23-L27

pos < height * width
pos + 1 !< height * width

Maybe:

    int hw, pos;
    hw = height * width;
    for (pos = 0; pos < (hw - 1); pos++)
    {
        (*hash)[pos] = (image[pos] < image[pos + 1]);
    }
    (*hash)[hw - 1] = (image[hw - 1] < image[0]);

Not?

zvezdochiot commented 4 years ago

I will add one more such "miss", but already "from the side": https://github.com/danielgtaylor/jpeg-archive/blob/8da4bf76b6c3c0e11e4941294bfc1857c119419b/src/smallfry.c#L74-L81 to:

 for (j = 7; j < width - 2; j += 8) {

https://github.com/danielgtaylor/jpeg-archive/blob/8da4bf76b6c3c0e11e4941294bfc1857c119419b/src/smallfry.c#L96-L103 to:

 for (i = 7; i < height - 2; i += 8) {

See https://github.com/ImageProcessing-ElectronicPublications/libsmallfry