diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c
index 2f56de3..e4d39ab 100644
--- a/pixman/pixman-bits-image.c
+++ b/pixman/pixman-bits-image.c
@@ -102,6 +102,9 @@ bits_image_fetch_pixel_nearest (bits_image_t   *image,
 
     if (image->common.repeat != PIXMAN_REPEAT_NONE)
     {
+	if (image->width <= 0 || image->height <= 0)
+	    return 0;
+
 	repeat (image->common.repeat, &x0, image->width);
 	repeat (image->common.repeat, &y0, image->height);
 
@@ -139,15 +142,22 @@ bits_image_fetch_pixel_bilinear (bits_image_t   *image,
 
     if (repeat_mode != PIXMAN_REPEAT_NONE)
     {
-	repeat (repeat_mode, &x1, width);
-	repeat (repeat_mode, &y1, height);
-	repeat (repeat_mode, &x2, width);
-	repeat (repeat_mode, &y2, height);
-
-	tl = get_pixel (image, x1, y1, FALSE);
-	bl = get_pixel (image, x1, y2, FALSE);
-	tr = get_pixel (image, x2, y1, FALSE);
-	br = get_pixel (image, x2, y2, FALSE);
+	if (width <= 0 || height <= 0)
+	{
+	    tl = bl = tr = br = 0;
+	}
+	else
+	{
+	    repeat (repeat_mode, &x1, width);
+	    repeat (repeat_mode, &y1, height);
+	    repeat (repeat_mode, &x2, width);
+	    repeat (repeat_mode, &y2, height);
+
+	    tl = get_pixel (image, x1, y1, FALSE);
+	    bl = get_pixel (image, x1, y2, FALSE);
+	    tr = get_pixel (image, x2, y1, FALSE);
+	    br = get_pixel (image, x2, y2, FALSE);
+	}
     }
     else
     {
@@ -411,10 +421,17 @@ bits_image_fetch_pixel_convolution (bits_image_t   *image,
 
 		if (repeat_mode != PIXMAN_REPEAT_NONE)
 		{
-		    repeat (repeat_mode, &rx, width);
-		    repeat (repeat_mode, &ry, height);
-
-		    pixel = get_pixel (image, rx, ry, FALSE);
+		    if (width <= 0 || height <= 0)
+		    {
+			pixel = 0;
+		    }
+		    else
+		    {
+			repeat (repeat_mode, &rx, width);
+			repeat (repeat_mode, &ry, height);
+
+			pixel = get_pixel (image, rx, ry, FALSE);
+		    }
 		}
 		else
 		{
@@ -694,18 +711,25 @@ bits_image_fetch_bilinear_affine (pixman_image_t * image,
 
 	    mask = PIXMAN_FORMAT_A (format)? 0 : 0xff000000;
 
-	    repeat (repeat_mode, &x1, width);
-	    repeat (repeat_mode, &y1, height);
-	    repeat (repeat_mode, &x2, width);
-	    repeat (repeat_mode, &y2, height);
+	    if (height <= 0)
+	    {
+		tl = bl = tr = br = mask;
+	    }
+	    else
+	    {
+		repeat (repeat_mode, &x1, width);
+		repeat (repeat_mode, &y1, height);
+		repeat (repeat_mode, &x2, width);
+		repeat (repeat_mode, &y2, height);
 
-	    row1 = (uint8_t *)bits->bits + bits->rowstride * 4 * y1;
-	    row2 = (uint8_t *)bits->bits + bits->rowstride * 4 * y2;
+		row1 = (uint8_t *)bits->bits + bits->rowstride * 4 * y1;
+		row2 = (uint8_t *)bits->bits + bits->rowstride * 4 * y2;
 
-	    tl = convert_pixel (row1, x1) | mask;
-	    tr = convert_pixel (row1, x2) | mask;
-	    bl = convert_pixel (row2, x1) | mask;
-	    br = convert_pixel (row2, x2) | mask;
+		tl = convert_pixel (row1, x1) | mask;
+		tr = convert_pixel (row1, x2) | mask;
+		bl = convert_pixel (row2, x1) | mask;
+		br = convert_pixel (row2, x2) | mask;
+	    }
 	}
 	else
 	{
@@ -840,15 +864,22 @@ bits_image_fetch_nearest_affine (pixman_image_t * image,
 	{
 	    uint32_t mask = PIXMAN_FORMAT_A (format)? 0 : 0xff000000;
 
-	    if (repeat_mode != PIXMAN_REPEAT_NONE)
+	    if (height <= 0)
 	    {
-		repeat (repeat_mode, &x0, width);
-		repeat (repeat_mode, &y0, height);
+		buffer [i] = mask;
 	    }
+	    else
+	    {
+		if (repeat_mode != PIXMAN_REPEAT_NONE)
+		{
+		    repeat (repeat_mode, &x0, width);
+		    repeat (repeat_mode, &y0, height);
+		}
 
-	    row = (uint8_t *)bits->bits + bits->rowstride * 4 * y0;
+		row = (uint8_t *)bits->bits + bits->rowstride * 4 * y0;
 
-	    buffer[i] = convert_pixel (row, x0) | mask;
+		buffer[i] = convert_pixel (row, x0) | mask;
+	    }
 	}
 
     next:
@@ -1051,7 +1082,11 @@ bits_image_fetch_untransformed_repeat_normal (bits_image_t *image,
     while (y >= image->height)
 	y -= image->height;
 
-    if (image->width == 1)
+    if (image->width <= 0 || image->height <= 0)
+    {
+	return;
+    }
+    else if (image->width == 1)
     {
 	if (wide)
 	    replicate_pixel_64 (image, 0, y, width, buffer);
diff --git a/pixman/pixman-inlines.h b/pixman/pixman-inlines.h
index 3532867..90be795 100644
--- a/pixman/pixman-inlines.h
+++ b/pixman/pixman-inlines.h
@@ -63,6 +63,11 @@ repeat (pixman_repeat_t repeat, int *c, int size)
     }
     else if (repeat == PIXMAN_REPEAT_NORMAL)
     {
+	if (size == 0) {
+	    *c = 0;
+	    return TRUE;
+	}
+
 	while (*c >= size)
 	    *c -= size;
 	while (*c < 0)
@@ -850,8 +855,15 @@ fast_composite_scaled_bilinear ## scale_func_name (pixman_implementation_t *imp,
 	{											\
 	    src_width = 0;									\
 												\
-	    while (src_width < REPEAT_NORMAL_MIN_WIDTH && src_width <= max_x)			\
-		src_width += src_image->bits.width;						\
+	    if (src_image->bits.width == 0)							\
+	    {											\
+		src_width = MIN (REPEAT_NORMAL_MIN_WIDTH, max_x + 1);				\
+	    }											\
+	    else										\
+	    {											\
+		while (src_width < REPEAT_NORMAL_MIN_WIDTH && src_width <= max_x)		\
+		    src_width += src_image->bits.width;						\
+	    }											\
 												\
 	    need_src_extension = TRUE;								\
 	}											\
@@ -1031,10 +1043,19 @@ fast_composite_scaled_bilinear ## scale_func_name (pixman_implementation_t *imp,
 	    {											\
 		for (i=0; i<src_width;)								\
 		{										\
-		    for (j=0; j<src_image->bits.width; j++, i++)				\
+		    if (src_image->bits.width <= 0)						\
+		    {										\
+			extended_src_line0[i] = 0;						\
+			extended_src_line1[i] = 0;						\
+			i++;									\
+		    }										\
+		    else									\
 		    {										\
-			extended_src_line0[i] = src_line_top[j];				\
-			extended_src_line1[i] = src_line_bottom[j];				\
+			for (j=0; j<src_image->bits.width; j++, i++)				\
+			{									\
+			    extended_src_line0[i] = src_line_top[j];				\
+			    extended_src_line1[i] = src_line_bottom[j];				\
+			}									\
 		    }										\
 		}										\
 												\
