6839133: lcms 1.18 update breaks ICC_ProfileRGB Tests
authoraph
Thu, 21 May 2009 18:41:50 +0100
changeset 2801 3d1b54bcdbbe
parent 2800 f7318b0bd705
child 2820 21261fc963f2
child 3010 1284f414492b
6839133: lcms 1.18 update breaks ICC_ProfileRGB Tests Reviewed-by: avu, prr
jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c
--- a/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c	Thu May 21 16:29:58 2009 +0100
+++ b/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c	Thu May 21 18:41:50 2009 +0100
@@ -610,14 +610,19 @@
         return FALSE;
     }
 
-    if (!Icc->Grow(Icc, delta)) {
-        free(ptr);
-        if(isNew) {
-            Icc->TagCount--;
+    /* We change the size of Icc here only if we know it'll actually
+     * grow: if Icc is about to shrink we must wait until we've read
+     * the previous data.  */
+    if (delta > 0) {
+        if (!Icc->Grow(Icc, delta)) {
+            free(ptr);
+            if(isNew) {
+                Icc->TagCount--;
+            }
+            J2dRlsTraceLn(J2D_TRACE_ERROR,
+                          "_cmsModifyTagData: Icc->Grow() == FALSE");
+            return FALSE;
         }
-        J2dRlsTraceLn(J2D_TRACE_ERROR,
-                      "_cmsModifyTagData: Icc->Grow() == FALSE");
-        return FALSE;
     }
 
     /* Compute size of tag data before/after the modified tag */
@@ -680,6 +685,18 @@
     temp = TransportValue32(profileSize);
     Icc->Write(Icc, sizeof(icUInt32Number), &temp);
 
+    /* Shrink Icc, if needed.  */
+    if (delta < 0) {
+        if (!Icc->Grow(Icc, delta)) {
+            free(ptr);
+            if(isNew) {
+                Icc->TagCount--;
+            }
+            J2dRlsTraceLn(J2D_TRACE_ERROR,
+                          "_cmsModifyTagData: Icc->Grow() == FALSE");
+            return FALSE;
+        }
+    }
 
     /* Adjust tag offsets: if the tag is new, we must account
        for the new tag table entry; otherwise, only those tags after