ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.11k stars 440 forks source link

Safer EOF condition in next_line() #73

Closed daeyun closed 5 years ago

daeyun commented 5 years ago

I think there's a bug here. data_begin can sometimes be greater than data_end. When this happens, it will read the "line" beyond the allocated memory. I was getting "too few columns" error because of this.

I don't know exactly what's going on, but in at least one case, I confirmed this happens right before line 445:

data_begin=161731 data_end=161730

I think it has something to do with the file not ending with a newline character. Line 467 doesn't seem to handle it correctly for some reason.

And it doesn't always happen given the same file. It seems to depend on the state of the rest of the application somehow. Threading was turned off.

It's probably better to fix whatever caused this problem, but for now, I think this >= check fixes it; probably safer this way anyway.

daeyun commented 5 years ago

Seems related to #72

ben-strasser commented 5 years ago

Hi,

thanks for the bug report.

Could you check whether changing line 477 from

if(buffer[line_end] == '\n')

to

if(data_end != line_end && buffer[line_end] == '\n')

solves the issue? If not a test file that exhibits the problem would be useful.

Best Regards Dr. Ben Strasser

ben-strasser commented 5 years ago

Commited the change that I described.