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
  • Loading branch information
rouault committed May 28, 2020
1 parent 644a564 commit fcf6203cb8ae2bc1c5f337a6461da1954fbac790
@@ -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 );
}

@@ -403,6 +404,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 fcf6203

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