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

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