mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 23:59:12 +00:00
sw_engine: prevent NaN in gradient pixel calculations
Add std::isfinite() check in _pixel() to prevent undefined behavior when NaN values are cast to int32_t. This prevents potential crashes during gradient color table indexing. NaN can occur from: - Division by zero in radial gradient calculations - Negative values passed to sqrtf() in radial gradient determinant
This commit is contained in:
parent
9369642642
commit
c9fb28402a
1 changed files with 1 additions and 0 deletions
|
@ -308,6 +308,7 @@ static inline uint32_t _fixedPixel(const SwFill* fill, int32_t pos)
|
|||
|
||||
static inline uint32_t _pixel(const SwFill* fill, float pos)
|
||||
{
|
||||
if (!std::isfinite(pos)) pos = 0;
|
||||
auto i = static_cast<int32_t>(pos * (GRADIENT_STOP_SIZE - 1) + 0.5f);
|
||||
return fill->ctable[_clamp(fill, i)];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue