From 00c09e752ff7e482e1308e0e34721dc979204595 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 4 Sep 2017 18:23:56 +0200 Subject: [PATCH] QAbstractItemModel: add more checks in begin{Insert,Remove}{Rows,Columns} Check that the inserted/removed range is indeed valid. Change-Id: Ifccbe13f0753252ee1450c8668df782dc699f05b Reviewed-by: David Faure --- src/corelib/itemmodels/qabstractitemmodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 44622a0ad9..7e1ab851d7 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2686,6 +2686,7 @@ bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &pare void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last) { Q_ASSERT(first >= 0); + Q_ASSERT(first <= rowCount(parent)); // == is allowed, to insert at the end Q_ASSERT(last >= first); Q_D(QAbstractItemModel); d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); @@ -2741,6 +2742,7 @@ void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, i { Q_ASSERT(first >= 0); Q_ASSERT(last >= first); + Q_ASSERT(last < rowCount(parent)); Q_D(QAbstractItemModel); d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); emit rowsAboutToBeRemoved(parent, first, last, QPrivateSignal()); @@ -2987,6 +2989,7 @@ void QAbstractItemModel::endMoveRows() void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last) { Q_ASSERT(first >= 0); + Q_ASSERT(first <= columnCount(parent)); // == is allowed, to insert at the end Q_ASSERT(last >= first); Q_D(QAbstractItemModel); d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); @@ -3043,6 +3046,7 @@ void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first { Q_ASSERT(first >= 0); Q_ASSERT(last >= first); + Q_ASSERT(last < columnCount(parent)); Q_D(QAbstractItemModel); d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); emit columnsAboutToBeRemoved(parent, first, last, QPrivateSignal());