Menu

#97 Segmentation fault on call of zbar_image_convert_resize() for converting from NV12 to GRAY

version_0.10
open
nobody
None
5
2021-03-11
2021-03-11
No

When I try to crop image and convert in to GRAY from NV12 using zbar_image_convert_resize() (zbar/convert.c) I got an segmentation fault. So I debug it and figure out following:
On a call of zbar_image_convert_resize() zbar_image_t dst struct is allocated;
Then after several checks you search for a conversion function:

conversion_handler_t *func =
     conversions[srcfmt->group][dstfmt->group].func;

function is set to convert_copy()
After that this function is called;
In convert_copy() after several checks there is a call of convert_y_resize() where actual problem starts.
after some checks that size of dst image is not the same as in src image (due to I need to crop image size is different) you copy pointer form dst->data witch is NULL and then call memcpy that is leads to segmentation fault.

    uint8_t *psrc = (void*)src->data;
    uint8_t *pdst = (void*)dst->data;
    unsigned width = (dst->width > src->width) ? src->width : dst->width;
    unsigned xpad = (dst->width > src->width) ? dst->width - src->width : 0;
    unsigned height = (dst->height > src->height) ? src->height : dst->height;
    unsigned y;
    for(y = 0; y < height; y++) {
        memcpy(pdst, psrc, width);
        pdst += width;
        psrc += src->width;
        if(xpad) {
            memset(pdst, *(psrc - 1), xpad);
            pdst += xpad;
        }
    }

Attachment contain patch to fix this issue.

1 Attachments

Discussion


Log in to post a comment.

MongoDB Logo MongoDB