The negative line size indicates that the frame is inverted (raw AVI are coded this way).
The data pointer points to the top line and if you add the negative linesize to the pointer you get to the next line. This means you are reading the image backwards, so using a non negative linesize for the memcpy in the code aboves means you will read the image forwards and go into unallocated memory after the first line.