mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 23:59:12 +00:00
lottie/parser: fix uint8_t overflow in getValue function
Fix runtime error when float values exceed uint8_t range (0-255). The getValue(uint8_t&) function was directly casting float values multiplied by 2.55f to uint8_t without range validation. This caused overflow errors when input values exceeded ~100% (e.g. opacity value is greater than 100). Added tvg::clamp() to ensure values stay within valid uint8_t range (0-255), preventing runtime overflow errors.
This commit is contained in:
parent
9369642642
commit
6d60d5fd05
1 changed files with 2 additions and 2 deletions
|
@ -264,11 +264,11 @@ bool LottieParser::getValue(uint8_t& val)
|
|||
{
|
||||
if (peekType() == kArrayType) {
|
||||
enterArray();
|
||||
if (nextArrayValue()) val = (uint8_t)(getFloat() * 2.55f);
|
||||
if (nextArrayValue()) val = (uint8_t)(tvg::clamp(getFloat() * 2.55f, 0.0f, 255.0f));
|
||||
//discard rest
|
||||
while (nextArrayValue()) getFloat();
|
||||
} else {
|
||||
val = (uint8_t)(getFloat() * 2.55f);
|
||||
val = (uint8_t)(tvg::clamp(getFloat() * 2.55f, 0.0f, 255.0f));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue