From 28e34b9942b7e338fc46d5ef14d5fcaafb12abe9 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Mon, 14 Nov 2022 20:07:37 +0100 Subject: [PATCH] Fix crash when scanning CSV file with more values in data than in header line. Closes #1698 --- source/csv_detector.pas | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/csv_detector.pas b/source/csv_detector.pas index 8409d056..fbaa4787 100644 --- a/source/csv_detector.pas +++ b/source/csv_detector.pas @@ -5,7 +5,8 @@ interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, SynEdit, SynMemo, extra_controls, apphelpers, - loaddata, dbconnection, Vcl.ExtCtrls, gnugettext, dbstructures, System.Math, SynRegExpr, System.IOUtils; + loaddata, dbconnection, Vcl.ExtCtrls, gnugettext, dbstructures, System.Math, SynRegExpr, System.IOUtils, + System.StrUtils; type TfrmCsvDetector = class(TExtForm) @@ -208,7 +209,7 @@ function TfrmCsvDetector.DetectColumnAttributes(Rows: TGridRows; IgnoreLines: In var Row: TGridRow; Value: TGridValue; - Col: TTableColumn; + Col, UnknownColumn: TTableColumn; i, j, k: Integer; UnknownTypeYet, IsInteger, IsFloat, IsDate, IsDatetime, IsText: Boolean; ValueSize, TypeSize: Int64; @@ -237,11 +238,15 @@ begin Break; end; + UnknownColumn := TTableColumn.Create(FConnection); for i:=IgnoreLines to Rows.Count-1 do begin MainForm.ProgressStep; for j:=0 to Rows[i].Count-1 do begin Value := Rows[i][j]; - Col := Result[j]; + if j >= Result.Count then + Col := UnknownColumn + else + Col := Result[j]; // Detect data type of current value