Skip to content

Commit

Permalink
QgsDelimitedTextSourceSelect: add a limitation to the number of fields
Browse files Browse the repository at this point in the history
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 3c96070
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
Expand Up @@ -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;
Expand Down

0 comments on commit 3c96070

Please sign in to comment.