| Summary: | Crash when closing print preview dialog on Linux | ||
|---|---|---|---|
| Product: | [Applications] okular | Reporter: | nyanpasu64 <nyanpasu64> |
| Component: | general | Assignee: | Okular developers <okular-devel> |
| Status: | RESOLVED FIXED | ||
| Severity: | crash | CC: | oliver.sander, rjvbertin |
| Priority: | NOR | Keywords: | drkonqi |
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | unspecified | ||
| OS: | Linux | ||
| Latest Commit: | https://invent.kde.org/kde/okular/commit/6e170312d8560963108365ee9e5c124d5c76f0e9 | Version Fixed/Implemented In: | |
| Sentry Crash Report: | |||
|
Description
nyanpasu64
2019-12-19 02:29:59 UTC
Okular 78cf6bd910aa2dfeb55ea110a1d0423fc54f58a5 via AUR okular-git. Running with valgrind causes okular to crash as soon as I open a document. Is this a false positive? I managed to build Okular with `-fsanitize=address,undefined -fno-sanitize=vptr`. (Omitting -fno-sanitize results in a nondescript linking error like `undefined reference to `typeinfo for MyObject'`. I eventually found https://stackoverflow.com/a/48322000 which mentions that the vptr sanitizer is incompatible with RTTI off.) The resulting asan Okular does not crash as soon as I open a document, nor when I open print preview. It prints the following message when I close print preview: /home/nyanpasu64/aur/okular-git/src/okular/ui/pageview.cpp:1595:49: runtime error: member access within null pointer of type 'struct KToggleAction' /home/nyanpasu64/aur/okular-git/src/okular/ui/pageview.cpp:1595:49: runtime error: member call on null pointer of type 'struct QAction' The crash occurs after ~FilePrinterPreview finishes, while unwinding FilePrinterPreview's Qt child widgets (via QObjectPrivate::deleteChildren).
Okular::Part::~Part calls Okular::Document::closeDocument calls d->saveDocumentInfo().
void DocumentPrivate::saveDocumentInfo() const
{
...
for ( View *view : qAsConst(m_views) )
{
QDomElement viewEntry = doc.createElement( QStringLiteral("view") );
viewEntry.setAttribute( QStringLiteral("name"), view->name() );
viewsNode.appendChild( viewEntry );
saveViewsInfo( view, viewEntry );
}
void DocumentPrivate::saveViewsInfo( View *view, QDomElement &e ) const
{
...
const bool mode = view->capability( View::Continuous ).toBool();
QVariant PageView::capability( ViewCapability capability ) const
{
switch ( capability )
{
...
case Continuous:
return d->aViewContinuous->isChecked();
## Null pointers
The problem is that PageView::d's member pointers are mostly nullptr (assigned by the constructor). This is what causes the crash.
Is the PageViewPrivate of a print preview document supposed to contain many nullptr, or should the pointers be initialized through PageView::setupViewerActions()? (This method constructs QAction and whatnot. Maybe it makes no sense to initialize them to QAction/etc, since the print preview dialog has no buttons.)
## Operating on null pointers.
I'm suspicious that Okular::Document::closeDocument unconditionally calls DocumentPrivate::saveDocumentInfo() (which leads to the crash). Is it necessary to save the info of a print-preview document? (It crashes if PageView::setupViewerActions() has not been called.)
The hacky workaround is to patch PageView::capability() to return some dummy value instead of dereferencing null pointers.
PageView::capability() did not call methods on d->ptr until commit bd25d17e704ed4bfed8e0db1dd233fe584fa96ef, which I think introduced the crash. >Save view information per file > >Adds the functionality to save the view mode (single page, facing...), >continuous scrolling, and margin trimming to the document information, >as it is already done with the zoom information. https://cgit.kde.org/okular.git/commit/?id=bd25d17e704ed4bfed8e0db1dd233fe584fa96ef https://github.com/KDE/okular/commit/bd25d17e704ed4bfed8e0db1dd233fe584fa96ef Indeed. For me it even crashes when *opening* the print preview. A fix for this should be accompagnied by a unit test. (In reply to Oliver Sander from comment #4) > Indeed. For me it even crashes when *opening* the print preview. > > A fix for this should be accompagnied by a unit test. If that's the case, this may be the same issue as bug 414937, where a Windows user reports that Okular crashes as soon as they open print preview. And my analysis of the bug may be incomplete as well. Interestingly I got no error or warnings at all when opening print preview, not even in an asan+ubsan build (which dramatically slowed down build speed). I tried flatpak Okular on Kubuntu 18.04 (not Manjaro) and also only got the crash when closing print preview. app/org.kde.okular/x86_64/master 7b82eadb1b05a162de9aec5e67ee6d90dc47fd1bf683a18f1a98f29c31bf6018 Git commit 6e170312d8560963108365ee9e5c124d5c76f0e9 by Albert Astals Cid. Committed on 28/12/2019 at 22:28. Pushed by aacid into branch 'release/19.12'. Fix crash when closing print preview dialog M +4 -3 ui/pageview.cpp https://invent.kde.org/kde/okular/commit/6e170312d8560963108365ee9e5c124d5c76f0e9 Git commit 5b5ef039cbc52a42d540b3705b67c9732ec4fbda by Albert Astals Cid. Committed on 28/12/2019 at 22:43. Pushed by aacid into branch 'master'. Add test that opens the print preview dialog At least this way we may find earlier gross mistakes like the one causing bug 415340 M +12 -0 autotests/parttest.cpp https://invent.kde.org/kde/okular/commit/5b5ef039cbc52a42d540b3705b67c9732ec4fbda *** Bug 439216 has been marked as a duplicate of this bug. *** |