Skip to content
Permalink
Browse files

QgsDelimitedTextSourceSelect: add a limitation to the number of fields

Set to 10000 by default. Can be overriden through settings.

This is only for the preview in the source select dialog. (Attribute
table performs badly for much less columns)

Related to #36392

(cherry picked from commit fcf6203)
  • Loading branch information
rouault authored and nyalldawson committed Jul 21, 2020
1 parent c6b2ee0 commit 3c960708f6a0eeb3ba1841b16a30d8da9dc711a5
@@ -98,6 +98,7 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt:
mFileWidget->setDialogTitle( tr( "Choose a Delimited Text File to Open" ) );
mFileWidget->setFilter( tr( "Text files" ) + QStringLiteral( " (*.txt *.csv *.dat *.wkt);;" ) + tr( "All files" ) + QStringLiteral( " (* *.*)" ) );
mFileWidget->setSelectedFilter( settings.value( mSettingsKey + QStringLiteral( "/file_filter" ), QString() ).toString() );
mMaxFields = settings.value( mSettingsKey + QStringLiteral( "/max_fields" ), DEFAULT_MAX_FIELDS ).toInt();
connect( mFileWidget, &QgsFileWidget::fileChanged, this, &QgsDelimitedTextSourceSelect::updateFileName );
}

@@ -401,6 +402,7 @@ bool QgsDelimitedTextSourceSelect::loadDelimitedFileDefinition()
mFile->setUseHeader( cbxUseHeader->isChecked() );
mFile->setDiscardEmptyFields( cbxSkipEmptyFields->isChecked() );
mFile->setTrimFields( cbxTrimFields->isChecked() );
mFile->setMaxFields( mMaxFields );
return mFile->isValid();
}

@@ -50,6 +50,8 @@ class QgsDelimitedTextSourceSelect : public QgsAbstractDataSourceWidget, private
std::unique_ptr<QgsDelimitedTextFile> mFile;
int mExampleRowCount = 20;
int mBadRowCount = 0;
static constexpr int DEFAULT_MAX_FIELDS = 10000;
int mMaxFields = DEFAULT_MAX_FIELDS; // to avoid Denial Of Service (at least in source select). Configurable through /max_fields settings sub-key.
QString mSettingsKey;
QString mLastFileType;
QButtonGroup *bgFileFormat = nullptr;

0 comments on commit 3c96070

Please sign in to comment.
You can’t perform that action at this time.