diff --git a/coders/xpm.c b/coders/xpm.c
index b78b0f9..72cd647 100644
--- a/coders/xpm.c
+++ b/coders/xpm.c
@@ -424,6 +424,9 @@
       /*
         Read image pixels.
       */
+      status=SetImageExtent(image,image->columns,image->rows,exception);
+      if (status == MagickFalse)
+        return(DestroyImageList(image));
       for (y=0; y < (ssize_t) image->rows; y++)
       {
         p=NextXPMLine(p);