• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git a/third_party/lcms/src/cmscgats.c b/third_party/lcms/src/cmscgats.c
2index a0c25c024..55f74ede8 100644
3--- a/third_party/lcms/src/cmscgats.c
4+++ b/third_party/lcms/src/cmscgats.c
5@@ -38,7 +38,10 @@
6 #define DEFAULT_DBL_FORMAT  "%.10g" // Double formatting
7
8 #ifdef CMS_IS_WINDOWS_
9-#    include <io.h>
10+//sunliang.liu modified 2010426 for wince error
11+# ifndef _WIN32_WCE
12+#   include <io.h>
13+# endif
14 #    define DIR_CHAR    '\\'
15 #else
16 #    define DIR_CHAR    '/'
17diff --git a/third_party/lcms/src/cmsgamma.c b/third_party/lcms/src/cmsgamma.c
18index eb3dd881c..6e36cf462 100644
19--- a/third_party/lcms/src/cmsgamma.c
20+++ b/third_party/lcms/src/cmsgamma.c
21@@ -749,14 +749,19 @@ void CMSEXPORT cmsFreeToneCurve(cmsToneCurve* Curve)
22 {
23     cmsContext ContextID;
24
25-    if (Curve == NULL) return;
26+    // added by Xiaochuan Liu
27+    // Curve->InterpParams may be null
28+    if (Curve == NULL || Curve->InterpParams == NULL) return;
29
30     ContextID = Curve ->InterpParams->ContextID;
31
32     _cmsFreeInterpParams(Curve ->InterpParams);
33+    Curve ->InterpParams = NULL;
34
35-    if (Curve -> Table16)
36+    if (Curve -> Table16) {
37         _cmsFree(ContextID, Curve ->Table16);
38+        Curve ->Table16 = NULL;
39+    }
40
41     if (Curve ->Segments) {
42
43@@ -766,20 +771,30 @@ void CMSEXPORT cmsFreeToneCurve(cmsToneCurve* Curve)
44
45             if (Curve ->Segments[i].SampledPoints) {
46                 _cmsFree(ContextID, Curve ->Segments[i].SampledPoints);
47+                Curve ->Segments[i].SampledPoints = NULL;
48             }
49
50-            if (Curve ->SegInterp[i] != 0)
51+            if (Curve ->SegInterp[i] != 0) {
52                 _cmsFreeInterpParams(Curve->SegInterp[i]);
53+                Curve->SegInterp[i] = NULL;
54+            }
55         }
56
57         _cmsFree(ContextID, Curve ->Segments);
58+        Curve ->Segments = NULL;
59         _cmsFree(ContextID, Curve ->SegInterp);
60+        Curve ->SegInterp = NULL;
61     }
62
63-    if (Curve -> Evals)
64+    if (Curve -> Evals) {
65         _cmsFree(ContextID, Curve -> Evals);
66+        Curve -> Evals = NULL;
67+    }
68
69-    if (Curve) _cmsFree(ContextID, Curve);
70+    if (Curve) {
71+        _cmsFree(ContextID, Curve);
72+        Curve = NULL;
73+    }
74 }
75
76 // Utility function, free 3 gamma tables
77@@ -799,7 +814,10 @@ void CMSEXPORT cmsFreeToneCurveTriple(cmsToneCurve* Curve[3])
78 // Duplicate a gamma table
79 cmsToneCurve* CMSEXPORT cmsDupToneCurve(const cmsToneCurve* In)
80 {
81-    if (In == NULL || In ->Segments == NULL || In ->Table16 == NULL) return NULL;
82+    // Xiaochuan Liu
83+    // fix openpdf bug(mantis id:0055683, google id:360198)
84+    // the function CurveSetElemTypeFree in cmslut.c also needs to check pointer
85+    if (In == NULL || In ->InterpParams == NULL || In ->Segments == NULL || In ->Table16 == NULL) return NULL;
86
87     return  AllocateToneCurveStruct(In ->InterpParams ->ContextID, In ->nEntries, In ->nSegments, In ->Segments, In ->Table16);
88 }
89diff --git a/third_party/lcms/src/cmsio0.c b/third_party/lcms/src/cmsio0.c
90index 1b026488d..cc5f89064 100644
91--- a/third_party/lcms/src/cmsio0.c
92+++ b/third_party/lcms/src/cmsio0.c
93@@ -479,6 +479,14 @@ cmsIOHANDLER* CMSEXPORT cmsGetProfileIOhandler(cmsHPROFILE hProfile)
94        return Icc->IOhandler;
95 }
96
97+#ifdef _WIN32_WCE
98+time_t wceex_time(time_t *timer);
99+struct tm * wceex_gmtime(const time_t *timer);
100+
101+#define time wceex_time
102+#define gmtime wceex_gmtime
103+#endif
104+
105 // Creates an empty structure holding all required parameters
106 cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
107 {
108@@ -570,6 +578,14 @@ int _cmsSearchTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, cmsBool lFollowLinks
109
110         // Yes, follow link
111         if (LinkedSig != (cmsTagSignature) 0) {
112+            // fix bug mantis id#0055942
113+            // assume that TRCTag and ColorantTag can't be linked.
114+            // Xiaochuan Liu 2014-04-23
115+            if ((sig == cmsSigRedTRCTag || sig == cmsSigGreenTRCTag || sig == cmsSigBlueTRCTag) &&
116+                (LinkedSig == cmsSigRedColorantTag || LinkedSig == cmsSigGreenColorantTag || LinkedSig == cmsSigBlueColorantTag))
117+            {
118+                return n;
119+            }
120             sig = LinkedSig;
121         }
122
123@@ -1363,6 +1379,12 @@ Error:
124     return 0;
125 }
126
127+#ifdef _WIN32_WCE
128+int wceex_unlink(const char *filename);
129+#ifndef remove
130+#   define remove wceex_unlink
131+#endif
132+#endif
133
134 // Low-level save to disk.
135 cmsBool  CMSEXPORT cmsSaveProfileToFile(cmsHPROFILE hProfile, const char* FileName)
136diff --git a/third_party/lcms/src/cmsio1.c b/third_party/lcms/src/cmsio1.c
137index 364741c9e..4b12ae18e 100644
138--- a/third_party/lcms/src/cmsio1.c
139+++ b/third_party/lcms/src/cmsio1.c
140@@ -201,7 +201,11 @@ cmsPipeline* BuildGrayInputMatrixPipeline(cmsHPROFILE hProfile)
141     return Lut;
142
143 Error:
144-    cmsFreeToneCurve(GrayTRC);
145+    // memory pointed by GrayTRC is not a new malloc memory, so don't free it here,
146+    // memory pointed by GrayTRC will be freed when hProfile is closed.
147+    // test file :0047776_Pocket Medicine_ The Massachusetts General Hospital Handbook of Internal Medicine-2.pdf
148+    // Xiaochuan Liu, 20140421
149+    //cmsFreeToneCurve(GrayTRC);
150     cmsPipelineFree(Lut);
151     return NULL;
152 }
153