
< #define GETJSAMPLE(value)  ((int) (value))
---
> #define GETJSAMPLE(value)  ((int) (value))
> #define SAFE_COLORMAP_ACCESS(map, index, max) ((index) < (max) ? (map)[index] : 0)
> 
<     *outptr++ = colormap[0][t]; /* colormap[x] has size cmaplen */
---
>     *outptr++ = SAFE_COLORMAP_ACCESS(colormap[0], t, source->cmaplen);
