summaryrefslogtreecommitdiff
path: root/CVE-2025-4638.patch
blob: 4673cecc44b8b41bf0ab2414ce8ac49650a78b5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
From 502bd2b013ce635f21632d523aa8cf2e04f7b7ac Mon Sep 17 00:00:00 2001
From: Kai Pastor <dg0yt@darc.de>
Date: Sun, 23 Apr 2023 06:24:02 +0200
Subject: [PATCH] Prefer system zlib over opennurbs vendored copy

---
 CMakeLists.txt                                |  9 +++++++
 pcl_config.h.in                               |  2 ++
 surface/CMakeLists.txt                        | 13 +++++++++-
 .../3rdparty/opennurbs/opennurbs_zlib.h       | 18 +++++++++++++
 .../src/3rdparty/opennurbs/openNURBS.cmake    | 23 ++--------------
 .../src/3rdparty/opennurbs/opennurbs_zlib.cpp |  8 ++++++
 surface/src/3rdparty/opennurbs/zlib.cmake     | 26 +++++++++++++++++++
 7 files changed, 77 insertions(+), 22 deletions(-)
 create mode 100644 surface/src/3rdparty/opennurbs/zlib.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8990960b427..8dd786981aa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -416,6 +416,15 @@ endif()
 # Boost (required)
 include("${PCL_SOURCE_DIR}/cmake/pcl_find_boost.cmake")
 
+# System zlib (for nurbs on surface)
+option(WITH_SYSTEM_ZLIB "Use system zlib" TRUE)
+if(WITH_SYSTEM_ZLIB)
+  find_package(ZLIB)
+  if(ZLIB_FOUND)
+    set(HAVE_ZLIB ON)
+  endif()
+endif()
+
 ### ---[ Create the config.h file
 set(pcl_config_h_in "${CMAKE_CURRENT_SOURCE_DIR}/pcl_config.h.in")
 set(pcl_config_h "${CMAKE_CURRENT_BINARY_DIR}/include/pcl/pcl_config.h")
diff --git a/pcl_config.h.in b/pcl_config.h.in
index b5ef2cbf9bf..13d04c3fbfc 100644
--- a/pcl_config.h.in
+++ b/pcl_config.h.in
@@ -52,6 +52,8 @@
 
 #cmakedefine HAVE_PNG
 
+#cmakedefine HAVE_ZLIB
+
 /* Precompile for a minimal set of point types instead of all. */
 #cmakedefine PCL_ONLY_CORE_POINT_TYPES
 
diff --git a/surface/CMakeLists.txt b/surface/CMakeLists.txt
index c29105e6a67..e42c81d1312 100644
--- a/surface/CMakeLists.txt
+++ b/surface/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(SUBSYS_NAME surface)
 set(SUBSYS_DESC "Point cloud surface library")
 set(SUBSYS_DEPS common search kdtree octree)
+set(SUBSYS_EXT_DEPS "")
 
 set(build TRUE)
 PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ON)
@@ -66,6 +67,16 @@ if(BUILD_surface_on_nurbs)
   
   include(src/3rdparty/opennurbs/openNURBS.cmake)
   include(src/on_nurbs/on_nurbs.cmake)
+  
+  if(WITH_SYSTEM_ZLIB)
+    find_package(ZLIB REQUIRED)
+    list(APPEND ON_NURBS_LIBRARIES ${ZLIB_LIBRARIES})
+    list(APPEND SUBSYS_EXT_DEPS zlib)
+  else()
+    include(src/3rdparty/opennurbs/zlib.cmake)
+    list(APPEND OPENNURBS_INCLUDES ${ZLIB_INCLUDES})
+    list(APPEND OPENNURBS_SOURCES ${ZLIB_SOURCES})
+  endif()
 endif()
 
 set(POISSON_INCLUDES
@@ -196,7 +207,7 @@ if(QHULL_FOUND)
   target_link_libraries("${LIB_NAME}" QHULL::QHULL)
 endif()
 
-PCL_MAKE_PKGCONFIG(${LIB_NAME} COMPONENT ${SUBSYS_NAME} DESC ${SUBSYS_DESC} PCL_DEPS ${SUBSYS_DEPS})
+PCL_MAKE_PKGCONFIG(${LIB_NAME} COMPONENT ${SUBSYS_NAME} DESC ${SUBSYS_DESC} PCL_DEPS ${SUBSYS_DEPS} EXT_DEPS ${SUBSYS_EXT_DEPS})
 
 # Install include files
 PCL_ADD_INCLUDES("${SUBSYS_NAME}" "${SUBSYS_NAME}" ${incs})
diff --git a/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_zlib.h b/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_zlib.h
index 12787e1201f..7622b3a6a7d 100644
--- a/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_zlib.h
+++ b/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_zlib.h
@@ -28,6 +28,22 @@
 // and statically link with the zlib library. All the necessary
 // header files are included by opennurbs.h.
 
+// PCL can use an external zlib.
+
+#include <pcl/pcl_config.h>
+
+#if defined(HAVE_ZLIB)
+
+#define z_deflate deflate
+#define z_inflate inflate
+#define z_Bytef Bytef
+
+#define zcalloc pcl_zcalloc
+#define zcfree pcl_zcfree
+
+#include <zlib.h>
+
+#else
 
 #if !defined(Z_PREFIX)
 /* decorates zlib functions with a "z_" prefix to prevent symbol collision. */
@@ -41,6 +57,8 @@
 
 #include "zlib.h"
 
+#endif // HAVE_ZLIB
+
 ON_BEGIN_EXTERNC
 voidpf zcalloc (voidpf, unsigned, unsigned);
 void  zcfree (voidpf, voidpf);
diff --git a/surface/src/3rdparty/opennurbs/openNURBS.cmake b/surface/src/3rdparty/opennurbs/openNURBS.cmake
index 51ca678d018..fdcfa7e92dd 100644
--- a/surface/src/3rdparty/opennurbs/openNURBS.cmake
+++ b/surface/src/3rdparty/opennurbs/openNURBS.cmake
@@ -102,16 +102,7 @@ set(OPENNURBS_INCLUDES
     include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/opennurbs_workspace.h
     include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/opennurbs_xform.h
     include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/opennurbs_zlib.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/crc32.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/deflate.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inffast.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inffixed.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inflate.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inftrees.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/trees.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/zconf.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/zlib.h
-    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/zutil.h)
+)
 
 set(OPENNURBS_SOURCES
     src/3rdparty/opennurbs/opennurbs_3dm_attributes.cpp
@@ -222,14 +213,4 @@ set(OPENNURBS_SOURCES
     src/3rdparty/opennurbs/opennurbs_xform.cpp
     src/3rdparty/opennurbs/opennurbs_zlib.cpp
     src/3rdparty/opennurbs/opennurbs_zlib_memory.cpp
-    src/3rdparty/opennurbs/adler32.c
-    src/3rdparty/opennurbs/compress.c
-    src/3rdparty/opennurbs/crc32.c
-    src/3rdparty/opennurbs/deflate.c
-    src/3rdparty/opennurbs/infback.c
-    src/3rdparty/opennurbs/inffast.c
-    src/3rdparty/opennurbs/inflate.c
-    src/3rdparty/opennurbs/inftrees.c
-    src/3rdparty/opennurbs/trees.c
-    src/3rdparty/opennurbs/uncompr.c
-    src/3rdparty/opennurbs/zutil.c)
+)
diff --git a/surface/src/3rdparty/opennurbs/opennurbs_zlib.cpp b/surface/src/3rdparty/opennurbs/opennurbs_zlib.cpp
index 688c803df65..03e61993177 100644
--- a/surface/src/3rdparty/opennurbs/opennurbs_zlib.cpp
+++ b/surface/src/3rdparty/opennurbs/opennurbs_zlib.cpp
@@ -16,6 +16,8 @@
 
 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
 
+#if !defined(HAVE_ZLIB)
+
 #if defined(ON_DLL_EXPORTS)
 // When compiling a Windows DLL opennurbs, we
 // statically link ./zlib/.../zlib....lib into
@@ -72,6 +74,8 @@
 
 #endif // ON_DLL_EXPORTS
 
+#endif // !HAVE_ZLIB
+
 
 bool ON_BinaryArchive::WriteCompressedBuffer(
         std::size_t sizeof__inbuffer,  // sizeof uncompressed input data
@@ -641,7 +645,11 @@ struct ON_CompressedBufferHelper
     sizeof_x_buffer = 16384
   };
   unsigned char    buffer[sizeof_x_buffer];
+#if defined(HAVE_ZLIB)
+  z_stream         strm = []() { z_stream zs; zs.zalloc = pcl_zcalloc; zs.zfree = pcl_zcfree; return zs; } ();
+#else
   z_stream         strm;
+#endif
   std::size_t           m_buffer_compressed_capacity;
 };
 
diff --git a/surface/src/3rdparty/opennurbs/zlib.cmake b/surface/src/3rdparty/opennurbs/zlib.cmake
new file mode 100644
index 00000000000..d730f223975
--- /dev/null
+++ b/surface/src/3rdparty/opennurbs/zlib.cmake
@@ -0,0 +1,26 @@
+set(ZLIB_INCLUDES
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/crc32.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/deflate.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inffast.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inffixed.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inflate.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/inftrees.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/trees.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/zconf.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/zlib.h
+    include/pcl/${SUBSYS_NAME}/3rdparty/opennurbs/zutil.h
+)
+
+set(ZLIB_SOURCES
+    src/3rdparty/opennurbs/adler32.c
+    src/3rdparty/opennurbs/compress.c
+    src/3rdparty/opennurbs/crc32.c
+    src/3rdparty/opennurbs/deflate.c
+    src/3rdparty/opennurbs/infback.c
+    src/3rdparty/opennurbs/inffast.c
+    src/3rdparty/opennurbs/inflate.c
+    src/3rdparty/opennurbs/inftrees.c
+    src/3rdparty/opennurbs/trees.c
+    src/3rdparty/opennurbs/uncompr.c
+    src/3rdparty/opennurbs/zutil.c
+)