]> Cypherpunks repositories - gostls13.git/commitdiff
image/draw: fix crash in clip
authorDave Cheney <dave@cheney.net>
Sat, 20 Dec 2014 05:57:02 +0000 (16:57 +1100)
committerDave Cheney <dave@cheney.net>
Sat, 20 Dec 2014 06:00:38 +0000 (06:00 +0000)
Fixes #9177

Change-Id: I1c7e57f0f0a9b00fb3ddc7fa4844ac53ea6df46f
Reviewed-on: https://go-review.googlesource.com/1876
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/image/draw/clip_test.go
src/image/draw/draw.go

index 65381f72f658e756d7ca0f46b33b67816417b53c..20de4e3332b18b009bdbfd639e1fcc1d10ba65a6 100644 (file)
@@ -191,3 +191,13 @@ func TestClip(t *testing.T) {
                }
        }
 }
+
+func TestClipWithNilMP(t *testing.T) {
+       src := image.NewRGBA(image.Rect(0, 0, 100, 100))
+       // dst must be smaller than src for clipping to occur
+       dst := image.NewRGBA(image.Rect(50, 50, 100, 100))
+       r := image.Rect(0, 0, 100, 100)
+       sp := image.ZP
+       // issue 9177: floydSteinberg.Draw passes nil for mp, which used to cause clip to panic
+       clip(dst, &r, src, &sp, nil, nil)
+}
index 661230e7c5994385c3da434d7534fd5476abd798..a060fa5e74c4c4dd91ed23501ec996205dee642f 100644 (file)
@@ -83,8 +83,10 @@ func clip(dst Image, r *image.Rectangle, src image.Image, sp *image.Point, mask
        }
        (*sp).X += dx
        (*sp).Y += dy
-       (*mp).X += dx
-       (*mp).Y += dy
+       if mp != nil {
+               (*mp).X += dx
+               (*mp).Y += dy
+       }
 }
 
 func processBackward(dst Image, r image.Rectangle, src image.Image, sp image.Point) bool {