diff options
author | Alexander Golubev <[email protected]> | 2024-02-22 04:54:37 +0300 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2024-02-22 18:29:32 +0900 |
commit | ab31b74b6a2aa04a7918243f7536281c3adb532b (patch) | |
tree | 8fce9473c4a1dc62b0cd5e98be7e41b35f037be5 | |
parent | b97fb9f1a9ae7f4f7df8ad9f9ab07ed70bbbb6bc (diff) | |
download | gwenview-ab31b74b6a2aa04a7918243f7536281c3adb532b.tar.gz gwenview-ab31b74b6a2aa04a7918243f7536281c3adb532b.zip |
Fix a crash when loading a PPMRAW image
The crash is caused by the fact that TQImageIO::imageFormat() may return
some values not present in neighter KImageIO::types(KImageIO::Reading)
nor in TQImage::inputFormatList(), e.g. different flavours of ppm like
PPMRAW. Besides that it's possible theat TQt could support other formats
unknown to TDE.
Signed-off-by: Alexander Golubev <[email protected]>
(cherry picked from commit 967c50523329266e92d9ae590733b423cd0f646f)
-rw-r--r-- | src/gvcore/imageloader.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/gvcore/imageloader.cpp b/src/gvcore/imageloader.cpp index 406a378..17aedf2 100644 --- a/src/gvcore/imageloader.cpp +++ b/src/gvcore/imageloader.cpp @@ -444,7 +444,12 @@ static TQString mimeTypeFromFormat(const char* format) { TQStringList formats = KImageIO::types(KImageIO::Reading); TQStringList mimeTypes = KImageIO::mimeTypes(KImageIO::Reading); int pos = formats.findIndex(TQString::fromAscii(format)); - Q_ASSERT(pos != -1); + if(pos < 0) { + // TQImageIO::imageFormat() nay return some different types than listed by + // TQImage::inputFormats(), e.g. "PPMRAW". Also TDE might simly be ignorant + // abous some types known to TQt. + return TQString::null; + } return mimeTypes[pos]; } @@ -463,13 +468,18 @@ void ImageLoader::slotDataReceived(TDEIO::Job* job, const TQByteArray& chunk) { const char* format = TQImageIO::imageFormat(&buffer); if (format) { // This is a raster image, get the mime type now - d->mURLKind = MimeTypeUtils::KIND_RASTER_IMAGE; d->mMimeType = mimeTypeFromFormat(format); + if(d->mMimeType.isNull()) { // fall back to TDE's autoguess of mime by content + KMimeType::Ptr ptr = KMimeType::findByContent(d->mRawData); + d->mMimeType = ptr->name(); + } + d->mURLKind = MimeTypeUtils::KIND_RASTER_IMAGE; } else { KMimeType::Ptr ptr = KMimeType::findByContent(d->mRawData); d->mMimeType = ptr->name(); d->mURLKind = MimeTypeUtils::mimeTypeKind(d->mMimeType); } + if (d->mURLKind!=MimeTypeUtils::KIND_RASTER_IMAGE) { Q_ASSERT(!d->mDecoderTimer.isActive()); job->kill(true /* quietly */); |