summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-02-22 04:54:37 +0300
committerAlexander Golubev <fatzer2@gmail.com>2024-02-22 05:49:11 +0300
commit967c50523329266e92d9ae590733b423cd0f646f (patch)
treed7def20e0b29f6a81d90ca1630a99a393692a6e0 /src
parenteed7134d3213d05a8afa96df56bbd1dfb1706d9d (diff)
downloadgwenview-967c50523329266e92d9ae590733b423cd0f646f.tar.gz
gwenview-967c50523329266e92d9ae590733b423cd0f646f.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 <fatzer2@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/gvcore/imageloader.cpp14
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 */);