Good mornning everyone

I'm trying to read a part of a PNG image file using Libpng and VC++ 2008 but unfortunately while executing the program an error " access violation memory" occured
Code:
 // Initialisation
png_bytep row_pointers;
png_structp png_ptr ;
..................
.....................
BYTE * buffer = (BYTE *)malloc((size*sizeof(BYTE)); //size : is less than image lenght 
row_pointers = (png_bytep)(buffer +size);
 png_read_image (png_ptr, row_pointers); //the problem occured here
...............
..............
Please help me and thanks in advance