Fix crash when arguments().mimeType() is an invalid mimetype name.

I have a JIRA bug report with a PDF attached, and mid-clicking the PDF
in konqueror leads to opening an okularpart with mimetype="application/x-octet-stream"
(the x- in there is very unusual, and unknown to shared-mime-info).
Fixed with null pointer checks.

REVIEW: 122074
remotes/origin/Applications/14.12
David Faure 11 years ago
parent eb0da16e45
commit f264146e59
  1. 10
      part.cpp

@ -1325,18 +1325,20 @@ bool Part::openFile()
if ( !isstdin && !fileInfo.exists() ) if ( !isstdin && !fileInfo.exists() )
return false; return false;
KMimeType::Ptr pathMime = KMimeType::findByPath( fileNameToOpen ); KMimeType::Ptr pathMime = KMimeType::findByPath( fileNameToOpen );
if ( !arguments().mimeType().isEmpty() ) const QString argMimeType = arguments().mimeType();
if ( !argMimeType.isEmpty() )
{ {
KMimeType::Ptr argMime = KMimeType::mimeType( arguments().mimeType() ); KMimeType::Ptr argMime = KMimeType::mimeType( argMimeType );
// Select the "childmost" mimetype, if none of them // Select the "childmost" mimetype, if none of them
// inherits the other trust more what pathMime says // inherits the other trust more what pathMime says
// but still do a second try if that one fails // but still do a second try if that one fails
if ( argMime->is( pathMime->name() ) ) if ( argMime && argMime->is( pathMime->name() ) )
{ {
mimes << argMime; mimes << argMime;
} }
else if ( pathMime->is( argMime->name() ) ) else if ( !argMime || pathMime->is( argMime->name() ) )
{ {
mimes << pathMime; mimes << pathMime;
} }

Loading…
Cancel
Save