xinxinlx / openjpeg

Automatically exported from code.google.com/p/openjpeg
Other
0 stars 0 forks source link

Bug in image components allocation and other fix #241

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[reported on the ML by Loïc Carrère]

in opj_image_create the image components is allocated this way:

image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * 
sizeof(opj_image_comp_t));

this call should be followed by a memset or replaced by using opj_calloc (my 
favorite option):

image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * 
sizeof(opj_image_comp_t));

If data is not initialized to zero value we have a potential memory access 
violation issue in case one of the subsequent call to comp->data = (OPJ_INT32*) 
opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32)); fails.

The problem is in this part:

if(!comp->data) {
    fprintf(stderr,"Unable to allocate memory for image.\n");
    opj_image_destroy(image); <------------------------if(image_comp->data) {   opj_free(image_comp->data); }
    return NULL;
}

Second problem is in opj_encode:

l_codec->m_codec_data.m_compression.opj_encode(l_codec->m_codec,    l_stream,   &(l_c
odec->m_event_mgr));
return OPJ_TRUE;

should be replaced by:

return 
l_codec->m_codec_data.m_compression.opj_encode(l_codec->m_codec,    l_stream,   &(l_c
odec->m_event_mgr));

Let me know if you need further info, the first issue sounds critical.

Original issue reported on code.google.com by mathieu.malaterre on 26 Sep 2013 at 9:22

GoogleCodeExporter commented 9 years ago

Original comment by mathieu.malaterre on 25 Feb 2014 at 3:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Everything suggested was merged in r2347. closing

Original comment by mathieu.malaterre on 26 Feb 2014 at 4:09