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:
Jinny You 2025-07-25 01:50:13 +09:00
parent 9369642642
commit 6d60d5fd05

View file

@ -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;
}