Community
cancel
Showing results for 
Search instead for 
Did you mean: 
riarhhs
Beginner
181 Views

Heap corruption when decoding a jpeg image

I am using following code todecode a jpegimage. At the end of the function call, the image is decoded successfully. However, when execution returns from the function, I get an error saying that heap is corrupted. I am using Visual C++ 2008. I tried to isolate the problem and found that heap corruptionoccurs when ImageDataOrder's destructor is called (as in dataOrder.~ImageDataOrder()). I guess, this would happen at the end of the function call.

void Decode(unsigned char* data, int len)
{

int err;
CMemBuffInput streamIn;
ExcStatus status;

JPEGDecoder _dec;
if(ExcStatusOk != _dec.Init())
throw "";

if(JPEG_OK != streamIn.Open(data, len))
throw "";

if (_dec.AttachStream(streamIn) != ExcStatusOk)
throw "";

ImageColorSpec colorSpec;
ImageSamplingGeometry geometry;
if(ExcStatusOk != _dec.ReadHeader(colorSpec,geometry))
throw "";

ImageDataOrder dataOrder;
int numOfComponents = geometry.NOfComponents();

if(colorSpec.DataRange()->BitDepth() + 1 <= 8)
dataOrder.SetDataType(T8u);
else
dataOrder.SetDataType(T16u);


dataOrder.ReAlloc(Interleaved, numOfComponents);

dataOrder.PixelStep()[0] = numOfComponents;
dataOrder.LineStep() [0] = AlignStep(
geometry.RefGridRect().Width() * numOfComponents);
geometry.SetEnumSampling(S444);

Image imageCn;

imageCn.Buffer().ReAlloc(dataOrder, geometry);
imageCn.ColorSpec().ReAlloc(numOfComponents);
imageCn.ColorSpec().SetColorSpecMethod(Enumerated);
imageCn.ColorSpec().SetComponentToColorMap(Direct);
int i;
for(i = 0; i < numOfComponents; i++)
{
if(colorSpec.DataRange()->BitDepth() + 1 <= 8)
imageCn.ColorSpec().DataRange().SetAsRange8u(255);
else
imageCn.ColorSpec().DataRange().SetAsRange16u(1 <<
colorSpec.DataRange()->BitDepth());
}
imageCn.ColorSpec().SetEnumColorSpace(RGB);
status = _dec.SetParams(imageCn.ColorSpec(),
imageCn.Buffer().BufferFormat().SamplingGeometry());
if(ExcStatusOk != status)
throw "";

status = _dec.SetParams(imageCn.ColorSpec(),imageCn.Buffer().BufferFormat().SamplingGeometry());
if(ExcStatusOk != status)throw "";

status = _dec.ReadData(imageCn.Buffer().DataPtr(),dataOrder);
if(ExcStatusOk != status)throw "";

// use the decoded image
}

0 Kudos
15 Replies
riarhhs
Beginner
181 Views


Is there a problem with my question or nobody knows the answer? :-)
Vladimir_Dudnik
Employee
181 Views

Did you try to reproduce that issue with uic_transcoder_con application?

Vladimir
riarhhs
Beginner
181 Views

Did you try to reproduce that issue with uic_transcoder_con application?

Vladimir

The uic_transcoder_con causes the exact same problem. In this case, the error pops up when ittries to return from the method ReadImageJPEG in jpeg.cpp.
Vladimir_Dudnik
Employee
181 Views


Could you please attach the image which cause the issue? We just test on arbitrary JPEG file with the latest IPP 6.0 update 1 and were not able to reproduce the issue.

Regards,
Vladimir
riarhhs
Beginner
181 Views


Could you please attach the image which cause the issue? We just test on arbitrary JPEG file with the latest IPP 6.0 update 1 and were not able to reproduce the issue.

Regards,
Vladimir

I am also running IPP 6.0 update 1. Are you running the debug or release? It does not seem to happen in the release mode (I guess no heap checks for release versions). I need to find a way to send you the jpeg data as it is a byte array I get from a camera. I ma prety sure it is a valid jpeg image as I amable to decode it using the .NET Bitmapclass.

If I run my MFC program in debug mode, I am able to reproduce the problem by just running following function:

void IntelJpegCodec::Test()
{
ImageDataOrder dataOrder;
dataOrder.ReAlloc(Interleaved, 1);
dataOrder.~ImageDataOrder();
}

3rd line causes the error I mentioned originally. The function _CrtCheckMemory returns TRUE after 2nd line, meaning that before the 3rd line heap is OK. I guess that means that something is done inside the destructor to cause the problem.
Vladimir_Dudnik
Employee
181 Views

Just to be on one board with this, what is the sample package file name (it include number of build so we can identify what version of samples you use with IPP 6.0 update 1)

Vladimir
riarhhs
Beginner
181 Views

Just to be on one board with this, what is the sample package file name (it include number of build so we can identify what version of samples you use with IPP 6.0 update 1)

Vladimir

It is w_ipp-samples_p_6.0.0.127

The IPP folder is C:Program FilesIntelIPP6.0.1.070ia32

Do I have wrong samples? I could not find any other version on your site.
riarhhs
Beginner
181 Views


Could someone please let me know if there is a problem with files I have?
Vladimir_Dudnik
Employee
181 Views

You are using correct version of files. We are trying to reproduce your issue, please stay tuned.

Vladimir
riarhhs
Beginner
181 Views

You are using correct version of files. We are trying to reproduce your issue, please stay tuned.

Vladimir

No news yet?
Vladimir_Dudnik
Employee
181 Views


We were not able to reproduce the issue. Could you please attach complete MSVC project, we may need to check project settings, may be there is some mismatch between CRT variants

Vladimir
riarhhs
Beginner
181 Views


We were not able to reproduce the issue. Could you please attach complete MSVC project, we may need to check project settings, may be there is some mismatch between CRT variants

Vladimir

The attached VS 2008 project causes the problem if compiled in debug mode. Just run it in debug mode and press Test button on the form. The zip file is called IppTest.zip. Thanks.
Vladimir_Dudnik
Employee
181 Views

I do not see your attachment. Please check 'How to attach files to this forum' post (it is one of the most top messages on forum)

Vladimir
fanguts
Beginner
181 Views

I do not see your attachment. Please check 'How to attach files to this forum' post (it is one of the most top messages on forum)

Vladimir

Is this problem solved ? I have exactly same problem in 64 bits system in release mode.
Vladimir_Dudnik
Employee
181 Views

I'm not sure if exactly this issue was solved as we did not get reproducable test case. But there was an issue with similar sympthoms which we plan to fix in the nearest IPP 6.1 update 2 (sometime in Q4'09)

Regards,
Vladimir
Reply