Avoid assert or crash on plateauing transfer table

If the same value repeats many times the values y1 and y2
can end up being the same cauing an assert or division by 0.

Fixes oss-fuzz 42535976. Credit to OSS-Fuzz for finding the case.

Change-Id: I30afd5cd61163c51949a8c13d4034f4bc11d27a7
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit aa1293f043f5df34ee7501efda6a6a2e8da5fa99)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Allan Sandfeld Jensen 2024-10-25 11:34:08 +02:00 committed by Qt Cherry-pick Bot
parent a6ffdfec98
commit f0c51f8f83

View File

@ -111,7 +111,7 @@ public:
return x;
}
// Apply inverse, optimized by giving a previous result a value < x.
// Apply inverse, optimized by giving a previous result for a value < x.
float applyInverse(float x, float resultLargerThan = 0.0f) const
{
Q_ASSERT(resultLargerThan >= 0.0f && resultLargerThan <= 1.0f);
@ -191,7 +191,7 @@ private:
template<typename T>
static float inverseLookup(float needle, float resultLargerThan, const QList<T> &table, quint32 tableMax)
{
uint32_t i = static_cast<uint32_t>(resultLargerThan * tableMax);
uint32_t i = qMax(static_cast<uint32_t>(resultLargerThan * tableMax), 1U) - 1;
auto it = std::lower_bound(table.cbegin() + i, table.cend(), needle);
i = it - table.cbegin();
if (i == 0)