gifflen-sample icon indicating copy to clipboard operation
gifflen-sample copied to clipboard

signal 7 (SIGBUS), code 2 (BUS_ADRERR) on large images

Open jedld opened this issue 9 years ago • 2 comments

When encoding large images (640x480) + I encounter a crash during quantization especially on this line (gifflen.cpp:919):

while (i < samplepixels) {
    /*b = p[0] << netbiasshift;
    g = p[1] << netbiasshift;
    r = p[2] << netbiasshift;*/
    b = (((*p)) & 0xff) << netbiasshift;
    g = (((*p) >> 8) & 0xff) << netbiasshift;
    r = (((*p) >> 16) & 0xff) << netbiasshift;
    j = contest(b,g,r);

*p might not be pointing to the right place

Happens both on x86 and ARM, so it wouldn't be alignment issues.

jedld avatar Jul 27 '15 08:07 jedld

Just located the source of the weirdness!

on line 928:

if (p >= (unsigned int *)lim) p -= lengthcount;

p is deducted by lengthcount, however lengthcount is w_h_4 due to:

435:  initnet(srcimage->bits, srcimage->width*srcimage->height*PIXEL_SIZE, 31-quality);

however p is unsigned *int already, and thus p-=lengthcount results in an additioal *4 in pointer decrement. What I did was:

if (p >= (unsigned int *)lim)  p = (unsigned int*) ((char*)p - lengthcount);

and it was solved. Maybe if you have a better way of resolving it?

jedld avatar Jul 27 '15 09:07 jedld

@jedld thx, using your solution, no crash anymore

luojin avatar Mar 19 '17 11:03 luojin