From e0a8b5ce88bc50440dcec2fe3a86d83e2a7dc7b0 Mon Sep 17 00:00:00 2001 From: Arnaud Bienner Date: Sat, 4 Oct 2014 18:14:55 +0200 Subject: QHeaderView: check that length is correct during restoreState. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Length is supposed to be equal to the section items length, but the state saved might be corrupted. If so, print a warning, return false and don't restore this corrupted state. Change-Id: I4d3dfec528a65fc81ed70d1c8cc69c11faf414e0 Task-number: QTBUG-40462 Reviewed-by: Friedemann Kleint Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qheaderview.cpp | 75 ++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index e887434d14..aad382ed49 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3674,6 +3674,17 @@ bool QHeaderViewPrivate::read(QDataStream &in) QVector visualIndicesIn; QVector logicalIndicesIn; QHash hiddenSectionSizeIn; + bool movableSectionsIn; + bool clickableSectionsIn; + bool highlightSelectedIn; + bool stretchLastSectionIn; + bool cascadingResizingIn; + int stretchSectionsIn; + int contentsSectionsIn; + int defaultSectionSizeIn; + int minimumSectionSizeIn; + QVector sectionItemsIn; + in >> orient; in >> order; @@ -3695,6 +3706,37 @@ bool QHeaderViewPrivate::read(QDataStream &in) if (in.status() != QDataStream::Ok || lengthIn < 0) return false; + in >> movableSectionsIn; + in >> clickableSectionsIn; + in >> highlightSelectedIn; + in >> stretchLastSectionIn; + in >> cascadingResizingIn; + in >> stretchSectionsIn; + in >> contentsSectionsIn; + in >> defaultSectionSizeIn; + in >> minimumSectionSizeIn; + + in >> align; + + in >> global; + + in >> sectionItemsIn; + // In Qt4 we had a vector of spans where one span could hold information on more sections. + // Now we have an itemvector where one items contains information about one section + // For backward compatibility with Qt4 we do the following + QVector newSectionItems; + for (int u = 0; u < sectionItemsIn.count(); ++u) { + int count = sectionItemsIn.at(u).tmpDataStreamSectionCount; + for (int n = 0; n < count; ++n) + newSectionItems.append(sectionItemsIn[u]); + } + + int sectionItemsLengthTotal = 0; + foreach (const SectionItem& section, sectionItemsIn) + sectionItemsLengthTotal += section.size; + if (sectionItemsLengthTotal != lengthIn) + return false; + orientation = static_cast(orient); sortIndicatorOrder = static_cast(order); sortIndicatorSection = sortIndicatorSectionIn; @@ -3704,32 +3746,19 @@ bool QHeaderViewPrivate::read(QDataStream &in) hiddenSectionSize = hiddenSectionSizeIn; length = lengthIn; - in >> movableSections; - in >> clickableSections; - in >> highlightSelected; - in >> stretchLastSection; - in >> cascadingResizing; - in >> stretchSections; - in >> contentsSections; - in >> defaultSectionSize; - in >> minimumSectionSize; + movableSections = movableSectionsIn; + clickableSections = clickableSectionsIn; + highlightSelected = highlightSelectedIn; + stretchLastSection = stretchLastSectionIn; + cascadingResizing = cascadingResizingIn; + stretchSections = stretchSectionsIn; + contentsSections = contentsSectionsIn; + defaultSectionSize = defaultSectionSizeIn; + minimumSectionSize = minimumSectionSizeIn; - in >> align; defaultAlignment = Qt::Alignment(align); + globalResizeMode = static_cast(global); - in >> global; - globalResizeMode = (QHeaderView::ResizeMode)global; - - in >> sectionItems; - // In Qt4 we had a vector of spans where one span could hold information on more sections. - // Now we have an itemvector where one items contains information about one section - // For backward compatibility with Qt4 we do the following - QVector newSectionItems; - for (int u = 0; u < sectionItems.count(); ++u) { - int count = sectionItems.at(u).tmpDataStreamSectionCount; - for (int n = 0; n < count; ++n) - newSectionItems.append(sectionItems[u]); - } sectionItems = newSectionItems; setHiddenSectionsFromBitVector(sectionHidden); recalcSectionStartPos(); -- cgit v1.2.3