Skip to content

Commit 729e5d0

Browse files
mszczecinskJoogabYun
authored andcommitted
Fix integer overflow in Gradient::populate()
A signed integer overflow vulnerability existed in `src/lottie/lottiemodel.cpp` where the `colorPoints` value from untrusted JSON input (`g.p` field) could be set to values >= 0x40000000, causing `colorPoints * 4` to overflow to 0. This bypassed the bounds check and led to a heap buffer over-read during gradient rendering.
1 parent ffe6094 commit 729e5d0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/lottie/lottiemodel.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ void model::Gradient::populate(VGradientStops &stops, int frameNo)
250250
auto size = gradData.mGradient.size();
251251
float * ptr = gradData.mGradient.data();
252252
int colorPoints = mColorPoints;
253-
size_t colorPointsSize = colorPoints * 4;
254253
if (!ptr) return;
255-
if (colorPoints < 0 || colorPointsSize > size) { // for legacy bodymovin (ref: lottie-android)
254+
if (colorPoints > 0 && (size_t)colorPoints > size / 4) {
256255
colorPoints = int(size / 4);
257256
}
257+
if (colorPoints < 0) { // for legacy bodymovin (ref: lottie-android)
258+
colorPoints = int(size / 4);
259+
}
260+
size_t colorPointsSize = (size_t)colorPoints * 4;
258261
auto opacityArraySize = size - colorPointsSize;
259262
if (opacityArraySize % 2 != 0) {
260263
opacityArraySize = 0;

0 commit comments

Comments
 (0)