Bug 397131 - kmail crash due to MonitorPrivate::emitItemsNotification accessing empty items
Summary: kmail crash due to MonitorPrivate::emitItemsNotification accessing empty items
Status: RESOLVED FIXED
Alias: None
Product: Akonadi
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: GIT (master)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-03 17:25 UTC by Martin Koller
Modified: 2018-08-16 09:38 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 5.9.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Koller 2018-08-03 17:25:07 UTC
I see kmail crashing after todays update (akonadi @ f7ce8ab4af83b8a64e97e2a8f11c21674cde826c)

The problem is in akonadis MonitorPrivate::emitItemsNotification implementation, which gets called in line 555 via
        if (!items.isEmpty() || itemNtf.operation() == Protocol::ItemChangeNotification::Remove || !fetchItems()) {
            someoneWasListening = emitItemsNotification(itemNtf, items, parent, destParent);
        }

so obviously items CAN be empty (which it is in the crash case), but emitItemsNotification()
in line 1064 (and others) uses
    case Protocol::ItemChangeNotification::Add:
        return emitToListeners(&Monitor::itemAdded, its.first(), col);

and Qt asserts due to the first() call on the empty list.

The stack I have here is:
1   raise                                                                         0x7fa2fad6df67 
2   abort                                                                         0x7fa2fad6f33a 
3   qt_message_fatal                               qlogging.cpp              1842 0x7fa2fba08f1c 
4   QMessageLogger::fatal                          qlogging.cpp              880  0x7fa2fba08f1c 
5   qt_assert                                      qglobal.cpp               3188 0x7fa2fba08576 
6   QVector<Akonadi::Item>::first                  qvector.h                 237  0x7fa2f48bb98e 
7   Akonadi::MonitorPrivate::emitItemsNotification monitor_p.cpp             1064 0x7fa2f48b0f90 
8   Akonadi::MonitorPrivate::emitNotification      monitor_p.cpp             555  0x7fa2f48ae94c 
9   Akonadi::MonitorPrivate::dispatchNotifications monitor_p.cpp             1000 0x7fa2f48b58c5 
10  Akonadi::MonitorPrivate::slotNotify            monitor_p.cpp             969  0x7fa2f48b532a 
11  Akonadi::MonitorPrivate::handleCommands        monitor_p.cpp             864  0x7fa2f48b4963 
12  Akonadi::Monitor::qt_static_metacall           moc_monitor.cpp           338  0x7fa2f48a18b3 
13  QObject::event                                 qobject.cpp               1251 0x7fa2fbc07f76 
14  QApplicationPrivate::notify_helper             qapplication.cpp          3728 0x7fa2fc9821ac 
15  QApplication::notify                           qapplication.cpp          3487 0x7fa2fc988b52 
16  QCoreApplication::notifyInternal2              qcoreapplication.cpp      1048 0x7fa2fbbdc8f5 
17  QCoreApplication::sendEvent                    qcoreapplication.h        234  0x7fa2fbbdf2be 
18  QCoreApplicationPrivate::sendPostedEvents      qcoreapplication.cpp      1745 0x7fa2fbbdf2be 
19  QEventDispatcherUNIX::processEvents            qeventdispatcher_unix.cpp 466  0x7fa2fbc2c5c4 
20  QUnixEventDispatcherQPA::processEvents         qunixeventdispatcher.cpp  68   0x7fa2d1fbc34d
Comment 1 Daniel Vrátil 2018-08-16 09:38:51 UTC
Git commit f8fc30bac58da423038906fe86cd00393df14bb9 by Daniel Vrátil.
Committed on 16/08/2018 at 09:38.
Pushed by dvratil into branch 'Applications/18.08'.

Monitor: rebuild Item from ntf if it's mustRetrieve but IFS is empty

When Monitor's IFS is empty and it receives an Item notification
with mustRetrieve set to true, then the retrieval is bypassed, but
the later on the code attempts to extract a result from cache which
results crash as we try to access elements in an empty list.

The fix is to send as much metadata as we can in the mustRetrieve
notification, and the Monitor needs to rebuild the Item from the
metadata instead of attempting retrieval.
FIXED-IN: 5.9.0

M  +1    -1    src/core/monitor_p.cpp
M  +5    -0    src/server/storage/notificationcollector.cpp

https://commits.kde.org/akonadi/f8fc30bac58da423038906fe86cd00393df14bb9