View Ticket
Not logged in
Ticket Hash: 321a68420d3e89d5e29aa15ae53506cd4fedcaff
Title: segfault reading malformed CSV file
Status: Closed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Rejected
Last Modified: 2015-10-30 19:21:41
Version Found In: 4.3.0a
User Comments:
anonymous added on 2015-10-29 16:05:16:

A segfault happens when a data line has more ";" than allowed by the header, eg. a file with 1 field in the header and one or more extra ";" at the end of a line:

HEADER
value;
I created a table with:
CREATE VIRTUAL TABLE test USING VirtualText('test.csv', ISO-8859-1, 1, COMMA, DOUBLEQUOTE, ';');
then using the table will cause a segfault:
SELECT Count(*) FROM test;

[...]

(gdb) bt
#0  0xb756a124 in __strcasecmp_nonascii (s1=0x809d4a8 "HEADER", s2=0x0) at ../string/strcasecmp.c:63
#1  0xb7bc8e5b in gaiaTextReaderParse () from /usr/lib/i386-linux-gnu/libspatialite.so.7
#2  0xb7bc9324 in ?? () from /usr/lib/i386-linux-gnu/libspatialite.so.7
#3  0xb76f5904 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#4  0xb76f5cc0 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#5  0xb772a5c5 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#6  0xb76cd7e6 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#7  0xb76d41b0 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#8  0xb770f7c1 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#9  0xb773a5e9 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#10 0xb773d44c in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#11 0xb773dba5 in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#12 0xb773defb in ?? () from /usr/lib/i386-linux-gnu/libsqlite3.so.0
#13 0x0805245c in ?? ()
#14 0x0804aa69 in ?? ()
#15 0xb74efa63 in __libc_start_main (main=0x804a460, argc=3, argv=0xbffff384, init=0x8052c60, fini=0x8052cd0, rtld_fini=0xb7fecca0 <_dl_fini>, 
    stack_end=0xbffff37c) at libc-start.c:287
#16 0x0804b635 in ?? ()
(gdb)


sandro added on 2015-10-30 19:21:41:
SpatiaLite's own CSV/TXT reader stricly requires a well-formed file.
If the input file is someway misconfigured or malformed a crash can eventually happen; unhappily the current implementation does not allow to robustly shield againt such possible mishaps.

Workarounds:
1. use the sqlite3 own command line frontend as a replacement; it supports an ".import" dot macro surely more robust than the one implemented by spatialite.
2. manually edit the input file thus correcting any offending cause.