Blame SOURCES/ghostscript-check-icc-profile-errors.patch

ea5d11
From 8d65c0854c049e4c0c8e08006b595ad40a59e696 Mon Sep 17 00:00:00 2001
ea5d11
From: Robin Watts <robin.watts@artifex.com>
ea5d11
Date: Thu, 28 Mar 2013 21:12:18 +0000
ea5d11
Subject: [PATCH] Another memory squeeze fix.
ea5d11
ea5d11
Avoid SEGV in gsicc_alloc_link_entry and callers.
ea5d11
---
ea5d11
 base/gsicc_cache.c     | 17 +++++++++++------
ea5d11
 base/gsicc_manage.c    |  6 ++++--
ea5d11
 base/gsicc_nocm.c      |  3 +++
ea5d11
 base/gsicc_replacecm.c |  3 +++
ea5d11
 4 files changed, 21 insertions(+), 8 deletions(-)
ea5d11
ea5d11
diff --git a/base/gsicc_cache.c b/base/gsicc_cache.c
ea5d11
index 616db4c..65b2dd0 100644
ea5d11
--- a/base/gsicc_cache.c
ea5d11
+++ b/base/gsicc_cache.c
ea5d11
@@ -659,12 +659,14 @@ gsicc_alloc_link_entry(gsicc_link_cache_t *icc_link_cache,
ea5d11
     /* insert an empty link that we will reserve so we */
ea5d11
     /* can unlock while building the link contents     */
ea5d11
     (*ret_link) = gsicc_alloc_link(cache_mem->stable_memory, hash);
ea5d11
-    (*ret_link)->icc_link_cache = icc_link_cache;
ea5d11
-    (*ret_link)->next = icc_link_cache->head;
ea5d11
-    icc_link_cache->head = *ret_link;
ea5d11
-    icc_link_cache->num_links++;
ea5d11
-    /* now that we own this link we can release 
ea5d11
-       the lock since it is not valid */
ea5d11
+    if (*ret_link) {
ea5d11
+        (*ret_link)->icc_link_cache = icc_link_cache;
ea5d11
+        (*ret_link)->next = icc_link_cache->head;
ea5d11
+        icc_link_cache->head = *ret_link;
ea5d11
+        icc_link_cache->num_links++;
ea5d11
+        /* now that we own this link we can release
ea5d11
+          the lock since it is not valid */
ea5d11
+    }
ea5d11
     gx_monitor_leave(icc_link_cache->lock);
ea5d11
     return false;
ea5d11
 }
ea5d11
@@ -794,6 +796,9 @@ gsicc_get_link_profile(const gs_imager_state *pis, gx_device *dev,
ea5d11
     if (gsicc_alloc_link_entry(icc_link_cache, &link, hash, include_softproof,
ea5d11
                                include_devicelink)) 
ea5d11
         return link;
ea5d11
+    if (link == NULL)
ea5d11
+        return NULL;
ea5d11
+
ea5d11
     /* Now compute the link contents */
ea5d11
     cms_input_profile = gs_input_profile->profile_handle;
ea5d11
     if (cms_input_profile == NULL) {
ea5d11
diff --git a/base/gsicc_manage.c b/base/gsicc_manage.c
ea5d11
index e0e7d93..210be59 100644
ea5d11
--- a/base/gsicc_manage.c
ea5d11
+++ b/base/gsicc_manage.c
ea5d11
@@ -1521,8 +1521,8 @@ gsicc_set_device_profile(gx_device * pdev, gs_memory_t * mem,
ea5d11
             icc_profile =
ea5d11
                 gsicc_profile_new(str, mem, file_name, strlen(file_name));
ea5d11
             code = sfclose(str);
ea5d11
-        }
ea5d11
-        if (str != NULL && icc_profile != NULL) {
ea5d11
+            if (icc_profile == NULL)
ea5d11
+                return_error(gs_error_VMerror);
ea5d11
             if (pro_enum < gsPROOFPROFILE) {
ea5d11
                 if_debug1m(gs_debug_flag_icc, mem,
ea5d11
                            "[icc] Setting device profile %d\n", pro_enum);
ea5d11
@@ -1542,6 +1542,8 @@ gsicc_set_device_profile(gx_device * pdev, gs_memory_t * mem,
ea5d11
                 gsicc_get_profile_handle_buffer(icc_profile->buffer,
ea5d11
                                                 icc_profile->buffer_size,
ea5d11
                                                 mem);
ea5d11
+            if (icc_profile->profile_handle == NULL)
ea5d11
+                return_error(gs_error_unknownerror);
ea5d11
             /* Compute the hash code of the profile. Everything in the
ea5d11
                ICC manager will have it's hash code precomputed */
ea5d11
             gsicc_get_icc_buff_hash(icc_profile->buffer,
ea5d11
diff --git a/base/gsicc_nocm.c b/base/gsicc_nocm.c
ea5d11
index 8b2a353..bcc3138 100644
ea5d11
--- a/base/gsicc_nocm.c
ea5d11
+++ b/base/gsicc_nocm.c
ea5d11
@@ -372,6 +372,9 @@ gsicc_nocm_get_link(const gs_imager_state *pis, gx_device *dev,
ea5d11
     if (gsicc_alloc_link_entry(pis->icc_link_cache, &result, hash, false, false)) 
ea5d11
         return result;
ea5d11
 
ea5d11
+    if (result == NULL)
ea5d11
+        return NULL;
ea5d11
+
ea5d11
     /* Now compute the link contents */
ea5d11
     result->procs.map_buffer = gsicc_nocm_transform_color_buffer;
ea5d11
     result->procs.map_color = gsicc_nocm_transform_color;
ea5d11
diff --git a/base/gsicc_replacecm.c b/base/gsicc_replacecm.c
ea5d11
index 1a7c9e6..d1ab5ea 100644
ea5d11
--- a/base/gsicc_replacecm.c
ea5d11
+++ b/base/gsicc_replacecm.c
ea5d11
@@ -330,6 +330,9 @@ gsicc_rcm_get_link(const gs_imager_state *pis, gx_device *dev,
ea5d11
     if (gsicc_alloc_link_entry(pis->icc_link_cache, &result, hash, false, false)) 
ea5d11
         return result;
ea5d11
 
ea5d11
+    if (result == NULL)
ea5d11
+        return result;
ea5d11
+
ea5d11
     /* Now compute the link contents */
ea5d11
     result->procs.map_buffer = gsicc_rcm_transform_color_buffer;
ea5d11
     result->procs.map_color = gsicc_rcm_transform_color;
ea5d11
-- 
ea5d11
2.5.5
ea5d11