Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6825 Discussions

Unalign memory in ippiDilate3x3_8u_C1R causes crash

per_zetterlund
Beginner
1,187 Views
Hello all,

I'm having some trouble using ippiDilate3x3_8u_C1R(). When I use non-32byte-aligned memory, the function reads up to 14 bytes of data beyond the end of the buffer, causing the program to crash. I have a one pixel border around the ROI, so that should be OK. Any ideas on this behaviour? I will try to make a short example program and post it here.

Thanks,
Per

0 Kudos
5 Replies
Vladimir_Dudnik
Employee
1,187 Views

Hi Per,

what version of IPP do you use and what is your target platform l(processor and operating system)?

Could you please share a piece of code which cause problem?

Regards,
Vladimir

0 Kudos
per_zetterlund
Beginner
1,187 Views
I'm using IPP 5.1 on a Core2Duo system using WinXP. (Still working on the example code.)


0 Kudos
Vladimir_Dudnik
Employee
1,187 Views

Thanks for updating. By the way, any particular reasons you did not move to the latest IPP version, which is 5.2?

I recall there was such an issue with this function, I'm checking now when it was fixed.

Vladimir

0 Kudos
per_zetterlund
Beginner
1,187 Views
Here is the code. boundsCheckAlloc() is a function that write-protects
the page following the allocation, thus enabling me to detect out-of-buffer
reads.

If i change the row

tmpimg = boundsCheckAlloc(tmpWidth*tmpHeight);

to

tmpimg = boundsCheckAlloc(tmpWidth*tmpHeight+14);

The code works fine.



#include /* malloc */

#include "ipp.h"
#include "windows.h"
#include


static void *boundsCheckAlloc(int memSize) {
DWORD t;
BOOL res;
static unsigned char* memarea = NULL;
const int NUM_PAGES = 100;
const int PAGE_SIZE = 4096; // True for XP at least

assert(memSize < PAGE_SIZE*(NUM_PAGES-1));

if(!memarea) {
memarea = VirtualAlloc(0, PAGE_SIZE*NUM_PAGES, MEM_COMMIT, PAGE_READWRITE);
assert(memarea);
/// Read and write protect last page.
res = VirtualProtect(memarea+PAGE_SIZE*(NUM_PAGES-1), PAGE_SIZE, PAGE_NOACCESS, &t);
assert(res);
}

return memarea + PAGE_SIZE*(NUM_PAGES-1) - memSize;
}

int main(int argc, char** argv) {
IppStatus ippRes;
const int width = 256;
const int height = 20;

const int tmpWidth = width + 2;
const int tmpHeight = height + 2;

unsigned char* input;
unsigned char* tmpimg;
unsigned char* output;

const IppiSize roi = {width, height};
const IppiSize tmproi = {tmpWidth, tmpHeight};

input = malloc(width*height);
memset(input, 0, width*height);

output = malloc(width*height);

tmpimg = boundsCheckAlloc(tmpWidth*tmpHeight);

ippRes = ippiCopyConstBorder_8u_C1R(input, width, roi,
tmpimg, tmpWidth, tmproi,
1, 1, 0);
assert(ippRes == ippStsNoErr);

ippRes = ippiErode3x3_8u_C1R(tmpimg+tmpWidth+1, tmpWidth, output, width, roi);
assert(ippRes == ippStsNoErr);

free(input);
//free(tmpimg);
free(output);
}

0 Kudos
Intel_C_Intel
Employee
1,187 Views

You could use ippiFilterMaxBorderBorderReplicate_8u_C1R function. It does not require the boreder in memory and is generally faster

Thanks,

Alexander

0 Kudos
Reply