From 3b557f7fb004570b7ee568670b9634ced7729488 Mon Sep 17 00:00:00 2001 From: Colin Dellow Date: Sun, 18 Mar 2018 11:58:23 -0400 Subject: [PATCH] Add explicit test for file not found ...caching the metadata moved where ParquetTable did I/O, which introduced a segfault on not found --- parquet/parquet.cc | 11 +++++------ tests/test-all | 1 + tests/test-non-existent | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100755 tests/test-non-existent diff --git a/parquet/parquet.cc b/parquet/parquet.cc index 3828766..4d32e27 100644 --- a/parquet/parquet.cc +++ b/parquet/parquet.cc @@ -80,27 +80,26 @@ static int parquetConnect( // Remove the delimiting single quotes std::string fname = argv[3]; fname = fname.substr(1, fname.length() - 2); - std::unique_ptr table(new ParquetTable(fname)); - std::unique_ptr vtab( (sqlite3_vtab_parquet*)sqlite3_malloc(sizeof(sqlite3_vtab_parquet)), sqlite3_free); memset(vtab.get(), 0, sizeof(*vtab.get())); try { + std::unique_ptr table(new ParquetTable(fname)); + std::string create = table->CreateStatement(); int rc = sqlite3_declare_vtab(db, create.data()); if(rc) return rc; + vtab->table = table.release(); + *ppVtab = (sqlite3_vtab*)vtab.release(); + return SQLITE_OK; } catch (const std::exception& e) { *pzErr = sqlite3_mprintf(e.what()); return SQLITE_ERROR; } - - vtab->table = table.release(); - *ppVtab = (sqlite3_vtab*)vtab.release(); - return SQLITE_OK; } /* diff --git a/tests/test-all b/tests/test-all index 11d0f91..594dc26 100755 --- a/tests/test-all +++ b/tests/test-all @@ -4,6 +4,7 @@ set -euo pipefail here=$(dirname "${BASH_SOURCE[0]}") set -x +"$here"/test-non-existent "$here"/test-unsupported "$here"/test-supported "$here"/test-queries diff --git a/tests/test-non-existent b/tests/test-non-existent new file mode 100755 index 0000000..564f267 --- /dev/null +++ b/tests/test-non-existent @@ -0,0 +1,33 @@ +#!/bin/bash +set -euo pipefail + +# Verify that loading a non existent file is an error, not a segfault + +load_nonexistent() { + cat < /dev/null 2> testcase-stderr.txt + + # We expect the 'SELECT 123' command to NOT have been run + if grep -q 123 testcase-out.txt; then + echo "...FAILED; expected an error message. Check testcase-{out,err}.txt" >&2 + exit 1 + fi +} + +main "$@"