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>
pull/22/head
Alexander Golubev 9 months ago
parent eed7134d32
commit 967c505233

@ -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 */);

Loading…
Cancel
Save