Project

General

Profile

Segfault in WSortFilterProxyModel::sourceDataChanged() with empty source model

Added by Jan Lindemann about 8 years ago

Hello all,

void WSortFilterProxyModel::sourceDataChanged() crashes on me as soon as

all rows from the source model are removed. The source model emits

dataChanged(WModelIndex(), WModelIndex()), advertising a change at the

root node. Inspection of the stack trace reveals that the segfault is

triggered by accessing item->sourceRowMap_[row]. row is zero, but still

out of bounds, since sourceRowMap_ is of zero length. As the source

model doesn't have any more rows, that does look fine to me. Once that

function is invoked, and it should be, the only way around that access

and subsequent inevitable crash is a check before:

if(topLeft.parent().isValid() && !parent.isValid())

return;

but I don't see how I could possibly make that happen. I might miss

something obvious here, but I have patched the attached

safeguard into WSourceFilterProxyModel.C, which does the trick for me

and might describe what I mean.

Could somebody please shed some light on this?

Regards

Jan


Replies (4)

RE: Segfault in WSortFilterProxyModel::sourceDataChanged() with empty source model - Added by Koen Deforche about 8 years ago

Hey Jan,

I believe the reason is that dataChanged() should not be emitted with invalid indexes. Is it your own model that does that?

The invisible root node / sentinel root index does not have any data and thus advertising data changes does not make any sense.

If rows are being removed, then that is handled by the rowsRemoved() signal.

The fix in WSortFilterProxyModel should be to ignore this event in case topLeft or bottomRight is invalid.

Regards,

koen

RE: Segfault in WSortFilterProxyModel::sourceDataChanged() with empty source model - Added by Jan Lindemann about 8 years ago

Hi Koen,

thanks for the answer.

I believe the reason is that dataChanged() should not be emitted with

invalid indexes. Is it your own model that does that?

indeed.

If rows are being removed, then that is handled by the rowsRemoved()

signal.

Yep, that's emitted and handled fine before.

The invisible root node / sentinel root index does not have any data

and thus advertising data changes does not make any sense.

Oh, well, in my model it has, and I begin to see that it should not.

Figure stat data on a file system's root node: In the attempt to solely

use the model API to access the file system's data, I'm doing something

along the lines of

data(index, MyStatDataRole)

That works, also for the root node. I understand that advertising

changes on that node doesn't make any difference for connected Wt views,

as they don't show it. It works fine with all views and proxies,

however, with the exception of WSortFilterProxyModel, and it is also

correctly processed by non-Wt listeners to that signal.

Is putting data into the root node considered misuse of the API?

Regards

Jan

RE: Segfault in WSortFilterProxyModel::sourceDataChanged() with empty source model - Added by Koen Deforche about 8 years ago

Hey,

I wouldn't say it's misuse, but it was clearly "unexpected". I've pushed a fix in

I've added the following in WSortFilterProxyModel which should fix the issue.

  if (!topLeft.isValid() || !bottomRight.isValid())
    return;

Regards,

koen

RE: Segfault in WSortFilterProxyModel::sourceDataChanged() with empty source model - Added by Jan Lindemann about 8 years ago

Koen Deforche wrote:

I've added the following in WSortFilterProxyModel which

should fix the issue.

Cool, thanks!

Jan

    (1-4/4)