ben-strasser / fast-cpp-csv-parser

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

Bug in LineReader #72

Closed ppwwyyxx closed 5 years ago

ppwwyyxx commented 6 years ago

The LineReader has the following logic at https://github.com/ben-strasser/fast-cpp-csv-parser/blob/master/csv.h#L466 to check whether the file ends with "\n":

                        while(buffer[line_end] != '\n' && line_end != data_end){
                                ++line_end;
                        }

                ......

                        if(buffer[line_end] == '\n'){
                                buffer[line_end] = '\0';
                        }else{
                                // some files are missing the newline at the end of the
                                // last line
                                ++data_end;
                                buffer[line_end] = '\0';
                        }

However this is wrong in the following conditions:

  1. there is a missing "\n" at the end of the last line in the file
  2. buffer[line_end] (which contains uninitialized random memory data) happens to be "\n"

In the above case, data_end is not correctly incremented, and cause an assertion error later.

ben-strasser commented 5 years ago

I believe this is fixed with the latest commit. If not, please reopen.