diff options
author | ChunLin Wang <wangchunlin@uniontech.com> | 2021-03-31 17:54:49 +0800 |
---|---|---|
committer | ChunLin Wang <wangchunlin@uniontech.com> | 2021-04-20 10:48:52 +0800 |
commit | c701e6bb38bbab9520b43297e8bc603f09227f44 (patch) | |
tree | a5222bbe0fc5b83b5063d2a6fb3588a51b778bed /src | |
parent | a7b9a9328e783f1f6033a4e8afacf3f91b8bba22 (diff) |
Fix get out of bounds index in QSortFilterProxyModel::filterAcceptsRow
Before calling the index function, we need to check the validity of the parameters.
Fixes: QTBUG-91878
Change-Id: I9ec7265fff3f81b8a288c4ba8fae606a2ec808a6
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit b8802071ed00689373da5817fc4824a30b5fcf86)
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 3c6eb19878..11992f7e2e 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -3004,8 +3004,9 @@ bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & if (d->filter_data.pattern().isEmpty()) return true; + + int column_count = d->model->columnCount(source_parent); if (d->filter_column == -1) { - int column_count = d->model->columnCount(source_parent); for (int column = 0; column < column_count; ++column) { QModelIndex source_index = d->model->index(source_row, column, source_parent); QString key = d->model->data(source_index, d->filter_role).toString(); @@ -3014,9 +3015,10 @@ bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & } return false; } - QModelIndex source_index = d->model->index(source_row, d->filter_column, source_parent); - if (!source_index.isValid()) // the column may not exist + + if (d->filter_column >= column_count) // the column may not exist return true; + QModelIndex source_index = d->model->index(source_row, d->filter_column, source_parent); QString key = d->model->data(source_index, d->filter_role).toString(); return d->filter_data.match(key).hasMatch(); } |