From e4f935607becc9de597c12d06c1d732ce60618a4 Mon Sep 17 00:00:00 2001
From: dirk <dirk@git.imagemagick.org>
Date: Tue, 2 Feb 2016 21:15:13 +0100
Subject: [PATCH] Fix a outofbound access for psd file

Added extra check to fix https://github.com/ImageMagick/ImageMagick/issues/93

origin: upstream, https://github.com/ImageMagick/ImageMagick/commit/4b1b9c0522628887195bad3a6723f7000b0c9a58
bug: https://github.com/ImageMagick/ImageMagick/issues/93
bug-ubuntu: https://bugs.launchpad.net/ubuntu/+source/imagemagick/+bug/1537419
bug-debian: https://bugs.debian.org/832475
---
 coders/psd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/coders/psd.c b/coders/psd.c
index c7919891f..783ef0833 100644
--- a/coders/psd.c
+++ b/coders/psd.c
@@ -1772,7 +1772,7 @@ static Image *ReadPSDImage(const ImageInfo *image_info,
       if (blocks == (unsigned char *) NULL)
         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
       count=ReadBlob(image,(size_t) length,blocks);
-      if ((count != (ssize_t) length) ||
+      if ((count != (ssize_t) length) || (length < 4) ||
           (LocaleNCompare((char *) blocks,"8BIM",4) != 0))
         {
           blocks=(unsigned char *) RelinquishMagickMemory(blocks);
