diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2021-06-28 15:47:09 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2021-06-28 16:01:33 +0100 |
commit | 518efd9e15c7d729332997abd031427616edab69 (patch) | |
tree | f38614c1e12c5b1fd52279e57d154c151d092471 /base/gdevmem.c | |
parent | 224ddcf95c43272be0511e2c66be73602e4cdbc7 (diff) | |
download | ghostpdl-518efd9e15c7d729332997abd031427616edab69.tar.gz |
Fix SEGVs seen in alldevs tests.
We see SEGVs in the alldevs tests with the escp device where
map_color_rgb is being called on an 8-bit memory device. The
implementation assumes that there will be a palette record
and so indexes into it.
It seems that palettes are actually unusual; the only time we
get one is if the device was created using the makewordimagedevice
operator from postscript.
Accordingly, we here update the map_color_rgb routine to behave
differently in the no-palette-present case. We return rgb values
as if the color index supplied was a greyscale value.
I believe this fixes the same issue seen with some other devices
including lj4dith and lj4dithp.
Diffstat (limited to 'base/gdevmem.c')
-rw-r--r-- | base/gdevmem.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/base/gdevmem.c b/base/gdevmem.c index e0d247214..59e10bd47 100644 --- a/base/gdevmem.c +++ b/base/gdevmem.c @@ -858,11 +858,20 @@ mem_mapped_map_color_rgb(gx_device * dev, gx_color_index color, gx_color_value prgb[3]) { gx_device_memory * const mdev = (gx_device_memory *)dev; - const byte *pptr = mdev->palette.data + (int)color * 3; + const byte *pptr = mdev->palette.data; - prgb[0] = gx_color_value_from_byte(pptr[0]); - prgb[1] = gx_color_value_from_byte(pptr[1]); - prgb[2] = gx_color_value_from_byte(pptr[2]); + if (pptr == NULL) { + color = color * gx_max_color_value / ((1<<mdev->color_info.depth)-1); + prgb[0] = color; + prgb[1] = color; + prgb[2] = color; + } else { + pptr += (int)color * 3; + + prgb[0] = gx_color_value_from_byte(pptr[0]); + prgb[1] = gx_color_value_from_byte(pptr[1]); + prgb[2] = gx_color_value_from_byte(pptr[2]); + } return 0; } |