Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Segmentation Fault on CSVStat when No Rows #208

Closed
chrishappy opened this issue Nov 21, 2022 · 1 comment
Closed

Bug: Segmentation Fault on CSVStat when No Rows #208

chrishappy opened this issue Nov 21, 2022 · 1 comment

Comments

@chrishappy
Copy link

chrishappy commented Nov 21, 2022

Input:

myfile.csv

a

test.cpp:

#include "csv.hpp"

using namespace csv;

int main(int argc, char *argv[]) {
    
  CSVStat stats("myfile.csv");
  auto min = stats.get_mins();

  return 0;
}

Output:

$ ./fuzz_csv 
Segmentation fault
CMake Details

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(fuzz-csv-parser)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

##################################################
# From: https://github.com/vincentlaucsb/csv-parser/issues/135#issuecomment-977528169
##################################################

# Install a header-only library from github as dependency.
FetchContent_Declare(
  csv
  GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser.git
  GIT_TAG        master
  )

FetchContent_MakeAvailable(csv)

include_directories(
  ${CMAKE_SOURCE_DIR}/${FolderSource} # Find headers from source folder
  ${csv_SOURCE_DIR}/single_include # Issue #139 for this repo
  )

##################################################
# End from
##################################################

add_executable(fuzz_csv)
target_sources(fuzz_csv
  PRIVATE
    test.cpp
)
target_link_libraries(fuzz_csv csv)

Full Command:

~/e4/build-testing$ cmake ../fuzz-csv-parser/
Building CSV library using C++17
-- Configuring done
-- Generating done
-- Build files have been written to: ~/e4/build-testing
~/e4/build-testing$ make clean all
[  5%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/basic_csv_parser.cpp.o
[ 11%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/col_names.cpp.o
[ 16%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_format.cpp.o
[ 22%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_reader.cpp.o
[ 27%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_reader_iterator.cpp.o
[ 33%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_row.cpp.o
[ 38%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_row_json.cpp.o
[ 44%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_stat.cpp.o
[ 50%] Building CXX object _deps/csv-build/include/internal/CMakeFiles/csv.dir/csv_utility.cpp.o
[ 55%] Linking CXX static library libcsv.a
[ 55%] Built target csv
[ 61%] Building CXX object CMakeFiles/fuzz_csv.dir/test.cpp.o
[ 66%] Linking CXX executable fuzz_csv
[ 66%] Built target fuzz_csv
[ 72%] Building CXX object CMakeFiles/fuzz_csv2.dir/test2.cpp.o
[ 77%] Linking CXX executable fuzz_csv2
[ 77%] Built target fuzz_csv2
[ 83%] Building CXX object _deps/csv-build/programs/CMakeFiles/csv_info.dir/csv_info.cpp.o
[ 88%] Linking CXX executable csv_info
[ 88%] Built target csv_info
[ 94%] Building CXX object _deps/csv-build/programs/CMakeFiles/csv_stats.dir/csv_stats.cpp.o
[100%] Linking CXX executable csv_stats
[100%] Built target csv_stats
~/e4/build-testing$ ./fuzz_csv 
Segmentation fault
@chrishappy chrishappy changed the title Bug: Segmentation Fault on Stats when No Rows Bug: Segmentation Fault on CSVStat when No Rows Nov 21, 2022
@vincentlaucsb
Copy link
Owner

Fixed by an earlier version but added a regression test in #228 to confirm the fix. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants