diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c
index 4a6bad8..cca6ae2 100644
--- a/gdk-pixbuf/io-ico.c
+++ b/gdk-pixbuf/io-ico.c
@@ -1016,6 +1016,8 @@ fill_entry (IconEntry *icon,
 	icon->xor = g_new0 (guchar, icon->xor_rowstride * icon->height);
 
 	icon->and_rowstride = icon->width / 8;
+	if ((icon->width % 8) != 0)
+		icon->and_rowstride++;
 	if ((icon->and_rowstride % 4) != 0) 		
 		icon->and_rowstride = 4 * ((icon->and_rowstride / 4) + 1);
 	icon->and = g_new0 (guchar, icon->and_rowstride * icon->height);
