Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: Source/core/svg/SVGTransformList.cpp

Issue 261603002: Prevent use of stale list length for to-animations of transform lists (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/svg/animations/animateTransform-list-crash-2-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2008 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2012. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2012. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 bool isToAnimation = animationElement->animationMode() == ToAnimation; 306 bool isToAnimation = animationElement->animationMode() == ToAnimation;
307 307
308 // Spec: To animations provide specific functionality to get a smooth change from the underlying value to the 308 // Spec: To animations provide specific functionality to get a smooth change from the underlying value to the
309 // ‘to’ attribute value, which conflicts mathematically with the requirement for additive transform animations 309 // ‘to’ attribute value, which conflicts mathematically with the requirement for additive transform animations
310 // to be post-multiplied. As a consequence, in SVG 1.1 the behavior of to an imations for ‘animateTransform’ is undefined 310 // to be post-multiplied. As a consequence, in SVG 1.1 the behavior of to an imations for ‘animateTransform’ is undefined
311 // FIXME: This is not taken into account yet. 311 // FIXME: This is not taken into account yet.
312 RefPtr<SVGTransformList> fromList = isToAnimation ? this : toSVGTransformLis t(fromValue); 312 RefPtr<SVGTransformList> fromList = isToAnimation ? this : toSVGTransformLis t(fromValue);
313 RefPtr<SVGTransformList> toList = toSVGTransformList(toValue); 313 RefPtr<SVGTransformList> toList = toSVGTransformList(toValue);
314 RefPtr<SVGTransformList> toAtEndOfDurationList = toSVGTransformList(toAtEndO fDurationValue); 314 RefPtr<SVGTransformList> toAtEndOfDurationList = toSVGTransformList(toAtEndO fDurationValue);
315 315
316 size_t fromListSize = fromList->length();
317 size_t toListSize = toList->length(); 316 size_t toListSize = toList->length();
318
319 if (!toListSize) 317 if (!toListSize)
320 return; 318 return;
321 319
320 // Get a reference to the from value before potentially cleaning it out (in the case of a To animation.)
321 RefPtr<SVGTransform> toTransform = toList->at(0);
322 RefPtr<SVGTransform> effectiveFrom = fromList->length() ? fromList->at(0) : SVGTransform::create(toTransform->transformType(), SVGTransform::ConstructZeroTr ansform);
323
322 // Never resize the animatedTransformList to the toList size, instead either clear the list or append to it. 324 // Never resize the animatedTransformList to the toList size, instead either clear the list or append to it.
323 if (!isEmpty() && !animationElement->isAdditive()) 325 if (!isEmpty() && !animationElement->isAdditive())
324 clear(); 326 clear();
325 327
326 RefPtr<SVGTransform> toTransform = toList->at(0);
327 RefPtr<SVGTransform> effectiveFrom = fromListSize ? fromList->at(0) : SVGTra nsform::create(toTransform->transformType(), SVGTransform::ConstructZeroTransfor m);
328 RefPtr<SVGTransform> currentTransform = SVGTransformDistance(effectiveFrom, toTransform).scaledDistance(percentage).addToSVGTransform(effectiveFrom); 328 RefPtr<SVGTransform> currentTransform = SVGTransformDistance(effectiveFrom, toTransform).scaledDistance(percentage).addToSVGTransform(effectiveFrom);
329 if (animationElement->isAccumulated() && repeatCount) { 329 if (animationElement->isAccumulated() && repeatCount) {
330 RefPtr<SVGTransform> effectiveToAtEnd = !toAtEndOfDurationList->isEmpty( ) ? toAtEndOfDurationList->at(0) : SVGTransform::create(toTransform->transformTy pe(), SVGTransform::ConstructZeroTransform); 330 RefPtr<SVGTransform> effectiveToAtEnd = !toAtEndOfDurationList->isEmpty( ) ? toAtEndOfDurationList->at(0) : SVGTransform::create(toTransform->transformTy pe(), SVGTransform::ConstructZeroTransform);
331 append(SVGTransformDistance::addSVGTransforms(currentTransform, effectiv eToAtEnd, repeatCount)); 331 append(SVGTransformDistance::addSVGTransforms(currentTransform, effectiv eToAtEnd, repeatCount));
332 } else { 332 } else {
333 append(currentTransform); 333 append(currentTransform);
334 } 334 }
335 } 335 }
336 336
337 float SVGTransformList::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, S VGElement*) 337 float SVGTransformList::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, S VGElement*)
338 { 338 {
339 // FIXME: This is not correct in all cases. The spec demands that each compo nent (translate x and y for example) 339 // FIXME: This is not correct in all cases. The spec demands that each compo nent (translate x and y for example)
340 // is paced separately. To implement this we need to treat each component as individual animation everywhere. 340 // is paced separately. To implement this we need to treat each component as individual animation everywhere.
341 341
342 RefPtr<SVGTransformList> toList = toSVGTransformList(toValue); 342 RefPtr<SVGTransformList> toList = toSVGTransformList(toValue);
343 if (isEmpty() || length() != toList->length()) 343 if (isEmpty() || length() != toList->length())
344 return -1; 344 return -1;
345 345
346 ASSERT(length() == 1); 346 ASSERT(length() == 1);
347 if (at(0)->transformType() == toList->at(0)->transformType()) 347 if (at(0)->transformType() == toList->at(0)->transformType())
348 return -1; 348 return -1;
349 349
350 // Spec: http://www.w3.org/TR/SVG/animate.html#complexDistances 350 // Spec: http://www.w3.org/TR/SVG/animate.html#complexDistances
351 // Paced animations assume a notion of distance between the various animatio n values defined by the ‘to’, ‘from’, ‘by’ and ‘values’ attributes. 351 // Paced animations assume a notion of distance between the various animatio n values defined by the ‘to’, ‘from’, ‘by’ and ‘values’ attributes.
352 // Distance is defined only for scalar types (such as <length>), colors and the subset of transformation types that are supported by ‘animateTransform’. 352 // Distance is defined only for scalar types (such as <length>), colors and the subset of transformation types that are supported by ‘animateTransform’.
353 return SVGTransformDistance(at(0), toList->at(0)).distance(); 353 return SVGTransformDistance(at(0), toList->at(0)).distance();
354 } 354 }
355 355
356 } 356 }
OLDNEW
« no previous file with comments | « LayoutTests/svg/animations/animateTransform-list-crash-2-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698