Project

General

Profile

Actions

Bug #2039

closed

segfault (vector subscript out of range) in WSortFilterProxyModel::sourceDataChanged(...) when setting a new icon for a WStandardItem

Added by Anonymous almost 11 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
High
Assignee:
Target version:
Start date:
07/16/2013
Due date:
% Done:

0%

Estimated time:

Description

I think the root of the problem is WSortFilterProxyModel::mapFromSource(...) method returning an invalid WModelIndex for both:

1) valid source indexes that are not meant to be displayed on the view (e.g. filtered out by the proxy via filterAcceptRow() method)

and

2) invalid source indexes.

So, as the method currently stands, when an invalid WModelIndex is returned, there is no way to detect which of the two cases we are dealing with.

Now, let's consider this snippet of code (used in several places inside WSortFilterProxyModel class):

WModelIndex parent = mapFromSource(validIndex.parent());
Item *item = itemFromIndex(parent);

Let's assume validIndex is a valid source index with a valid parent, but not meant to be displayed in the proxy model (e.g. an index belonging to case 1 mentioned above). What item will we get from the call to itemFromIndex(...) ? The invisible root item. Why? Because:

a) mapFromSource(...) returns an invalid WModelIndex for case 1 (parent in example above)

and

b) there is always an item which parent index is invalid; that item is the invisible root item.

I can think of two possible ways to fix this:

I) change mapFromSource() method signature to return whether we are dealing with case 1 or 2

II) add code to detect whether we are dealing with case 1 or 2 outside mapFromSource()

Please find attached a patch with solution II applied.

Mind: this patch will fix sourceDataChanged() method only, but the problem could potentially affect other methods, namely:

_WSortFilterProxyModel::sourceRowsAboutToBeInserted()

WSortFilterProxyModel::sourceRowsInserted()

WSortFilterProxyModel::sourceRowsAboutToBeRemoved()

WSortFilterProxyModel::sourceRowsRemoved()_

Regards


Files

Actions #1

Updated by Pierluigi Vicinanza almost 11 years ago

Sorry, just realized I forgot to sign in when I reported the bug. Feel free to ask more clarifications if needed.

Regards

Pierluigi

Actions #2

Updated by Koen Deforche almost 11 years ago

  • Status changed from New to InProgress
  • Assignee set to Korneel Dumon
  • Target version set to 3.3.1

I agree with the problem diagnosis! Everywhere mappedFromSource() is used we need to make sure we do not consider changes/events related to a valid source indexes for which mappedFromSource() returns an invalid index.

Thus, I would do this as:

  WModelIndex pparent = mapFromSource(parent);
  if (parent.isValid() && !pparent.isValid()) { ... /* filtered out, do not treat this case, i.e. return from the function in most cases */ }

Most places where mapFromSource() need attention indeed.

Best is to create a test case where you filter and then modify / insert-at in the source model at a filtered index.

Actions #3

Updated by Korneel Dumon over 10 years ago

  • Status changed from InProgress to Resolved
Actions #4

Updated by Koen Deforche over 10 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF