sct: qRound with param bigger than max int is undefined

oss-fuzz/399667098
This commit is contained in:
Albert Astals Cid 2025-03-03 21:51:03 +01:00
parent e98467d954
commit d0f2635e10
2 changed files with 13 additions and 4 deletions

View File

@ -207,10 +207,10 @@ public:
auto v = QString::fromLatin1(pchar_t(res.data()), res.size()).toDouble(&ok);
if (ok && v > 0) {
if (m_pb._unitsOfMeasurement) { // Inches
return qRound(width() / v / 25.4 * 1000);
return qRoundOrZero(width() / v / 25.4 * 1000);
}
// Millimeters
return qRound(width() / v * 1000);
return qRoundOrZero(width() / v * 1000);
}
return 0;
}
@ -221,10 +221,10 @@ public:
auto v = QString::fromLatin1(pchar_t(res.data()), res.size()).toDouble(&ok);
if (ok && v > 0) {
if (m_pb._unitsOfMeasurement) { // Inches
return qRound(height() / v / 25.4 * 1000);
return qRoundOrZero(height() / v / 25.4 * 1000);
}
// Millimeters
return qRound(height() / v * 1000);
return qRoundOrZero(height() / v * 1000);
}
return 0;
}

View File

@ -60,4 +60,13 @@ inline QImage imageAlloc(qint32 width, qint32 height, const QImage::Format &form
return imageAlloc(QSize(width, height), format);
}
inline double qRoundOrZero(double d)
{
// If the value d is outside the range of int, the behavior is undefined.
if (d > std::numeric_limits<int>::max()) {
return 0;
}
return qRound(d);
}
#endif // UTIL_P_H