3706c3f
From 309eca4e0a31ea70dcc844812691439312dad091 Mon Sep 17 00:00:00 2001
3706c3f
From: Ken Sharp <ken.sharp@artifex.com>
3706c3f
Date: Mon, 20 Mar 2017 09:34:11 +0000
3706c3f
Subject: [PATCH] Ensure a device has raster memory, before trying to read it.
3706c3f
3706c3f
Bug #697676 "Null pointer dereference in mem_get_bits_rectangle()"
3706c3f
3706c3f
This is only possible by abusing/mis-using Ghostscript-specific
3706c3f
language extensions, so cannot happen in a general PostScript program.
3706c3f
3706c3f
Nevertheless, Ghostscript should not crash. So this commit checks the
3706c3f
memory device to see if raster memory has been allocated, before trying
3706c3f
to read from it.
3706c3f
---
3706c3f
 base/gdevmem.c | 2 ++
3706c3f
 1 file changed, 2 insertions(+)
3706c3f
3706c3f
diff --git a/base/gdevmem.c b/base/gdevmem.c
3706c3f
index afd05bd..d52d684 100644
3706c3f
--- a/base/gdevmem.c
3706c3f
+++ b/base/gdevmem.c
3706c3f
@@ -606,6 +606,8 @@ mem_get_bits_rectangle(gx_device * dev, const gs_int_rect * prect,
3706c3f
             GB_PACKING_CHUNKY | GB_COLORS_NATIVE | GB_ALPHA_NONE;
3706c3f
         return_error(gs_error_rangecheck);
3706c3f
     }
3706c3f
+    if (mdev->line_ptrs == 0x00)
3706c3f
+        return_error(gs_error_rangecheck);
3706c3f
     if ((w <= 0) | (h <= 0)) {
3706c3f
         if ((w | h) < 0)
3706c3f
             return_error(gs_error_rangecheck);
3706c3f
-- 
3706c3f
2.9.3
3706c3f