mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-10-11 00:34:18 -04:00
Fix assert when read corrupted floats
This commit is contained in:
@ -1030,20 +1030,32 @@ static QImage readUnsignedImage(QDataStream &s, const DDSHeader &dds, quint32 wi
|
||||
|
||||
static qfloat16 readFloat16(QDataStream &s)
|
||||
{
|
||||
qfloat16 f16;
|
||||
qfloat16 f16 = 0;
|
||||
if (s.status() != QDataStream::Ok) {
|
||||
return f16;
|
||||
}
|
||||
s >> f16;
|
||||
if (qIsNaN(f16)) {
|
||||
s.setStatus(QDataStream::ReadCorruptData);
|
||||
}
|
||||
return f16;
|
||||
}
|
||||
|
||||
static inline float readFloat32(QDataStream &s)
|
||||
{
|
||||
Q_ASSERT(sizeof(float) == 4);
|
||||
float value;
|
||||
float value = 0;
|
||||
if (s.status() != QDataStream::Ok) {
|
||||
return value;
|
||||
}
|
||||
// TODO: find better way to avoid setting precision each time
|
||||
QDataStream::FloatingPointPrecision precision = s.floatingPointPrecision();
|
||||
s.setFloatingPointPrecision(QDataStream::SinglePrecision);
|
||||
s >> value;
|
||||
s.setFloatingPointPrecision(precision);
|
||||
if (qIsNaN(value)) {
|
||||
s.setStatus(QDataStream::ReadCorruptData);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -1126,11 +1138,7 @@ static QImage readR32F(QDataStream &s, const quint32 width, const quint32 height
|
||||
for (quint32 y = 0; y < height; y++) {
|
||||
float *line = reinterpret_cast<float *>(image.scanLine(y));
|
||||
for (quint32 x = 0; x < width; x++) {
|
||||
const float f = readFloat32(s);
|
||||
if (std::isnan(f)) {
|
||||
return {};
|
||||
}
|
||||
line[x * 4] = f;
|
||||
line[x * 4] = readFloat32(s);
|
||||
line[x * 4 + 1] = 0;
|
||||
line[x * 4 + 2] = 0;
|
||||
line[x * 4 + 3] = 1;
|
||||
|
Reference in New Issue
Block a user