Skip to content

Commit cb80992

Browse files
core: Clamp min coordinates in color_transform
The current behavior assumes the max value can be larger than the target size, but that the min can't. This reasoning seems faulty, since one could pass (min:100,max:150) to a target of size 50, in which case both min and max are larger, but only max would get clamped. We now clamp both min and max to correctly enforce invariants.
1 parent f8f88b7 commit cb80992

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

core/src/bitmap/operations.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ pub fn color_transform<'gc>(
494494
return;
495495
}
496496

497+
// Clamp both min and max coordinates to target size to enforce invariants
498+
let x_min = x_min.min(target.width());
499+
let y_min = y_min.min(target.height());
497500
let x_max = x_max.min(target.width());
498501
let y_max = y_max.min(target.height());
499502

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package
2+
{
3+
import flash.display.MovieClip;
4+
5+
public class Test extends MovieClip
6+
{
7+
public function Test()
8+
{
9+
super();
10+
}
11+
}
12+
}
13+
14+
import flash.display.BitmapData;
15+
import flash.geom.ColorTransform;
16+
import flash.geom.Rectangle;
17+
18+
var bitmap:BitmapData = new BitmapData(8,8,false,0);
19+
20+
// Try to do a colorTransform with an out of bounds Rectangle.
21+
// This doesn't crash FP
22+
bitmap.colorTransform(new Rectangle(9,9,10,10),new ColorTransform(1,1,1,1,1,1,1,1));
23+
trace("// bitmap.rect (sanity check)");
24+
trace(bitmap.rect.toString());
25+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// bitmap.rect (sanity check)
2+
(x=0, y=0, w=8, h=8)
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_frames = 1

0 commit comments

Comments
 (0)