status-im / status-desktop

Status Desktop client made in Nim & QML
https://status.app
Mozilla Public License 2.0
289 stars 78 forks source link

SFPM and Aggregator cause crash in specific cases #16012

Open micieslak opened 2 months ago

micieslak commented 2 months ago

Bug Report

Description

The problem has been noticed in https://github.com/status-im/status-desktop/pull/16011. In specific combination of SFPM with filters and sorter and Aggregator, the change of aggregator's value triggers a segfault in QSortFilterProxyModel's internals.

There are several components that may contain real source of the problem: Qt's QSortFilterProxyModel, SFPM or FunctionAggregator.

Minimal example (can be pasted e.g. to PlaygroundPage.qml in storybook):

import QtQuick 2.15
import QtQuick.Controls 2.15

import StatusQ 0.1
import SortFilterProxyModel 0.2

Item {
    id: root

    ListModel {
        id: source

        ListElement {
            name: "a"
            subname: "b"
        }
        ListElement {
            name: "b"
            subname: "a"
        }
    }

    Button {
        text: "remove " + source.count + "," + sfpm1.count + "," + sfpm2.count

        onClicked: source.clear()
    }

    SortFilterProxyModel {
        id: sfpm1

        sourceModel: source

        sorters: RoleSorter {
            roleName: (fa1.value && fa2.value) ? "name" : "subname"
        }

        filters: ValueFilter {
            roleName: (fa1.value && fa2.value) ? "name" : "subname"
            value: "a"
        }
    }

    SortFilterProxyModel {
        id: sfpm2

        sourceModel: source

        sorters: RoleSorter {
            roleName: (fa1.value && fa2.value) ? "name" : "subname"
        }

        filters: ValueFilter {
            roleName: (fa1.value && fa2.value) ? "name" : "subname"
            value: "b"
        }
    }

    FunctionAggregator {
        id: fa1

        model: sfpm1
        roleName: "name"
        initialValue: false

        aggregateFunction: () => true
    }

    FunctionAggregator {
        id: fa2

        model: sfpm2
        roleName: "name"
        initialValue: false

        aggregateFunction: () => true
    }
}

Pressing the button causes segfault:

Screenshot from 2024-08-07 11-17-06

alexjba commented 2 months ago

I can confirm the behaviour on MacOS with Qt 5.15.8

alexjba commented 2 months ago

Enabling the delayed flag on SFPM seems to fix the issues

caybro commented 2 months ago

Confirming the crash on Linux with Qt 5.15.14