esheldon / pymangle

Simple code to read mangle masks, calculate ids and weights, and generate random points
14 stars 15 forks source link

Potential fix for read failure described in issue #15. #17

Closed kerstinpaech closed 4 years ago

kerstinpaech commented 4 years ago

The line https://github.com/esheldon/pymangle/blob/master/pymangle/polygon.c#L279 nread = getline(&linebuf, &n, fptr); n is set to the size of the buffer originally allocated by getline, not the size of the buffer actually read. The return value nread is the actual number of characters read. Using n when parsing the line with get_next_nonblank(linebuf, n, i) or et_next_nonblank(linebuf, n, i) will go beyond the end of the line (for some reason this is not caught) to allocated, but un-initialized memory. This can be prevented by replacing n by nread in the appropriate places.

esheldon commented 4 years ago

thanks, this does indeed look like a bug and I think your fix is correct