Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
[zlib, minizip] Update to 1.2.13, and embed the ZLIB_DLL setting. (mi…
Browse files Browse the repository at this point in the history
…crosoft#27226)

* Don't use external ZLIB_DLL

* Update versions

* [minizip] Bump to zlib version

* Update versions

* [libkml] Fix mingw build

* [libkml] Modernize

* [libkml] Fix minizip dependency

* [libkml] No DLL

* Update versions

* [libkml] Update mingw patch

* Update versions

* Update versions

* [zlib] Update to 1.2.13

This picks up the official fix for CVE-2022-37434.

* Cherry pick installing the correct license from microsoft#27242

* Update version database.

* More version database.

* Also update minizip.

* Also guard ZLIB_DLL properties for BUILD_SHARED_LIBS.

* Version database.

* Fix minizip usage.

Co-authored-by: Kai Pastor <dg0yt@darc.de>
  • Loading branch information
2 people authored and ooeygui committed Jan 19, 2023
1 parent 527b037 commit 05f4864
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 148 deletions.
41 changes: 41 additions & 0 deletions ports/libkml/fix-mingw.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 028f50a..bb63ffb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,9 @@ set(LIBKML_DATA_DIR ${CMAKE_SOURCE_DIR}/testdata CACHE "Directory containing te
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -pedantic -fno-rtti")
set(TEST_FLAGS "-Wall -Wextra -Wno-unused-parameter -fno-rtti -DGTEST_HAS_RTTI=0")
+if(WIN32)
+ add_definitions(-DUNICODE -D_UNICODE)
+endif()

else()
if(MSVC)
diff --git a/src/kml/base/file_win32.cc b/src/kml/base/file_win32.cc
index 28ccb36..6ba79cd 100644
--- a/src/kml/base/file_win32.cc
+++ b/src/kml/base/file_win32.cc
@@ -34,7 +34,9 @@
#include "kml/base/file.h"
#include <windows.h>
#include <tchar.h>
+#ifndef __MINGW32__
#include <xstring>
+#endif
#include <algorithm>

namespace kmlbase {
diff --git a/src/kml/base/string_util.cc b/src/kml/base/string_util.cc
index b3a9654..842f1cd 100644
--- a/src/kml/base/string_util.cc
+++ b/src/kml/base/string_util.cc
@@ -113,7 +113,7 @@ bool StringEndsWith(const string& str, const string& end) {
}

bool StringCaseEqual(const string& a, const string& b) {
-#ifdef WIN32
+#if defined(WIN32) && !defined(__MINGW32__)
# define strncasecmp(s1, s2, n) _strnicmp (s1, s2, n)
#endif
return a.size() == b.size() && strncasecmp(a.data(), b.data(), a.size()) == 0;
72 changes: 72 additions & 0 deletions ports/libkml/fix-minizip.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9728ead..028f50a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -110,9 +110,9 @@ else()
list(APPEND MINIZIP_DEPENDS ZLIB)
endif()

-find_package(MiniZip)
+find_package(MINIZIP NAMES minizip REQUIRED)
if(MINIZIP_FOUND)
- include_directories(${MINIZIP_INCLUDE_DIR})
+ set(MINIZIP_LIBRARY minizip::minizip)
else()
include(External_minizip)
list(APPEND KMLBASE_DEPENDS MINIZIP)
diff --git a/cmake/LibKMLConfig.cmake.in b/cmake/LibKMLConfig.cmake.in
index 3e295f4..97826df 100644
--- a/cmake/LibKMLConfig.cmake.in
+++ b/cmake/LibKMLConfig.cmake.in
@@ -1,3 +1,6 @@
+include(CMakeFindDependencyMacro)
+find_dependency(minizip CONFIG)
+
# Compute paths
get_filename_component(LIBKML_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

diff --git a/src/kml/base/contrib/minizip/iomem_simple.c b/src/kml/base/contrib/minizip/iomem_simple.c
index be89226..6be61d5 100644
--- a/src/kml/base/contrib/minizip/iomem_simple.c
+++ b/src/kml/base/contrib/minizip/iomem_simple.c
@@ -219,7 +219,7 @@ int ZCALLBACK mem_error (opaque, stream)
return 0;
}

-ZEXTERN void* ZEXPORT mem_simple_create_file(zlib_filefunc_def* api, void* buffer, size_t buf_len)
+extern void* mem_simple_create_file(zlib_filefunc_def* api, void* buffer, size_t buf_len)
{
MEMFILE* handle = malloc(sizeof(*handle));
api->zopen_file = NULL;
diff --git a/src/kml/base/contrib/minizip/iomem_simple.h b/src/kml/base/contrib/minizip/iomem_simple.h
index ec11396..515e24e 100644
--- a/src/kml/base/contrib/minizip/iomem_simple.h
+++ b/src/kml/base/contrib/minizip/iomem_simple.h
@@ -70,7 +70,7 @@ void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
* This declaration is from the proposed iomem_simple package found at
* http://code.trak.dk. See iomem_simple.c
*/
-extern void* ZEXPORT mem_simple_create_file(zlib_filefunc_def* pzlib_filefunc_def, void* buffer, size_t buflen);
+extern void* mem_simple_create_file(zlib_filefunc_def* pzlib_filefunc_def, void* buffer, size_t buflen);

#ifdef __cplusplus
}
diff --git a/src/kml/base/contrib/minizip/unzip.c b/src/kml/base/contrib/minizip/unzip.c
index a062863..fb69189 100644
--- a/src/kml/base/contrib/minizip/unzip.c
+++ b/src/kml/base/contrib/minizip/unzip.c
@@ -43,6 +43,14 @@ woven in by Terry Thorsen 1/2003.
#include "unzip.h"
#include "iomem_simple.h"
#undef NOUNCRYPT
+#ifdef ZEXPORT
+# undef ZEXPORT
+#endif
+#define ZEXPORT
+#ifdef ZEXTERN
+# undef ZEXTERN
+#endif
+#define ZEXTERN extern

#ifdef STDC
# include <stddef.h>
39 changes: 24 additions & 15 deletions ports/libkml/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO libkml/libkml
Expand All @@ -6,26 +10,31 @@ vcpkg_from_github(
HEAD_REF master
PATCHES
patch_empty_literal_on_vc.patch
fix-mingw.patch
fix-minizip.patch
)

file(REMOVE ${SOURCE_PATH}/cmake/External_boost.cmake)
file(REMOVE
"${SOURCE_PATH}/cmake/External_boost.cmake"
"${SOURCE_PATH}/cmake/External_expat.cmake"
"${SOURCE_PATH}/cmake/External_minizip.cmake"
"${SOURCE_PATH}/cmake/External_uriparser.cmake"
"${SOURCE_PATH}/cmake/External_zlib.cmake"
"${SOURCE_PATH}/src/kml/base/contrib/minizip/ioapi.h"
)

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
)

vcpkg_install_cmake()
vcpkg_cmake_install()
vcpkg_copy_pdbs()

if (VCPKG_TARGET_IS_WINDOWS)
vcpkg_fixup_cmake_targets(CONFIG_PATH cmake)
elseif (VCPKG_TARGET_IS_LINUX)
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/libkml)
elseif (VCPKG_TARGET_IS_OSX)
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/libkml)
vcpkg_fixup_pkgconfig()
if(VCPKG_TARGET_IS_WINDOWS)
vcpkg_cmake_config_fixup(CONFIG_PATH cmake)
else()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/libkml)
endif()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
vcpkg_fixup_pkgconfig()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
18 changes: 11 additions & 7 deletions ports/libkml/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"name": "libkml",
"version-string": "1.3.0",
"port-version": 8,
"version": "1.3.0",
"port-version": 9,
"description": "Reference implementation of OGC KML 2.2",
"homepage": "https://github.com/libkml/libkml",
"license": "BSD-3-Clause",
"dependencies": [
"boost-smart-ptr",
"expat",
"minizip",
"uriparser",
{
"name": "minizip",
"features": [
"bzip2"
]
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"uriparser",
"zlib"
]
}
7 changes: 1 addition & 6 deletions ports/minizip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(minizip C)

set(PROJECT_VERSION 1.2.11)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 2)
set(PROJECT_VERSION_PATCH 11)
project(minizip VERSION 1.2.13 LANGUAGES C)

if(MSVC)
add_compile_options(/W3 /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
Expand Down
12 changes: 8 additions & 4 deletions ports/minizip/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# When this port is updated, the minizip port should be updated at the same time

vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO madler/zlib
REF v1.2.11
SHA512 104c62ed1228b5f1199bc037081861576900eb0697a226cafa62a35c4c890b5cb46622e399f9aad82ee5dfb475bae26ae75e2bd6da3d261361b1c8b996970faf
REF v1.2.13
SHA512 44b834fbfb50cca229209b8dbe1f96b258f19a49f5df23b80970b716371d856a4adf525edb4c6e0e645b180ea949cb90f5365a1d896160f297f56794dd888659
HEAD_REF master
PATCHES
0001-remove-ifndef-NOUNCRYPT.patch
Expand All @@ -13,7 +15,8 @@ vcpkg_from_github(
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
bzip2 ENABLE_BZIP2
FEATURES
bzip2 ENABLE_BZIP2
)

configure_file(${CMAKE_CURRENT_LIST_DIR}/minizipConfig.cmake.in ${SOURCE_PATH}/cmake/minizipConfig.cmake.in COPYONLY)
Expand Down Expand Up @@ -43,4 +46,5 @@ if ("bzip2" IN_LIST FEATURES)
endforeach()
endif()

file(INSTALL ${SOURCE_PATH}/contrib/minizip/MiniZip64_info.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${SOURCE_PATH}/contrib/minizip/MiniZip64_info.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
4 changes: 4 additions & 0 deletions ports/minizip/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minizip provides CMake targets:

find_package(minizip CONFIG REQUIRED)
target_link_libraries(main PRIVATE minizip::minizip)
4 changes: 2 additions & 2 deletions ports/minizip/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "minizip",
"version-semver": "1.2.11",
"port-version": 10,
"version-semver": "1.2.13",
"description": "Zip compression library",
"homepage": "https://github.com/madler/zlib",
"license": "Zlib",
"supports": "!uwp",
"dependencies": [
"zlib"
Expand Down
17 changes: 17 additions & 0 deletions ports/zlib/0002-skip-building-examples.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b412dc7..f46c8e6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -194,6 +194,7 @@ endif()
# Example binaries
#============================================================================

+if (0)
add_executable(example test/example.c)
target_link_libraries(example zlib)
add_test(example example)
@@ -211,3 +212,4 @@ if(HAVE_OFF64_T)
target_link_libraries(minigzip64 zlib)
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
endif()
+endif()
53 changes: 53 additions & 0 deletions ports/zlib/0003-build-static-or-shared-not-both.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f46c8e6..6fa5575 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -121,9 +121,11 @@ set(ZLIB_SRCS
)

if(NOT MINGW)
+ if(BUILD_SHARED_LIBS)
set(ZLIB_DLL_SRCS
win32/zlib1.rc # If present will override custom build rule below.
)
+ endif()
endif()

# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
@@ -144,13 +146,16 @@ if(MINGW)
-I ${CMAKE_CURRENT_BINARY_DIR}
-o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
-i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
+ if(BUILD_SHARED_LIBS)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
+ endif()
endif(MINGW)

-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
+add_library(zlib ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
+if (BUILD_SHARED_LIBS)
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
set_target_properties(zlib PROPERTIES SOVERSION 1)
+endif()

if(NOT CYGWIN)
# This property causes shared libraries on Linux to have the full version
@@ -165,7 +170,7 @@ endif()

if(UNIX)
# On unix-like platforms the library is almost always called libz
- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
+ set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
if(NOT APPLE)
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
endif()
@@ -175,7 +180,7 @@ elseif(BUILD_SHARED_LIBS AND WIN32)
endif()

if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
- install(TARGETS zlib zlibstatic
+ install(TARGETS zlib
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt (date 1618364429263)
+++ b/CMakeLists.txt (date 1618364429263)
@@ -170,7 +170,7 @@
index 6fa5575..7c345db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,7 +56,7 @@ endif()
#
check_include_file(unistd.h Z_HAVE_UNISTD_H)

-if(MSVC)
+if(WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
@@ -133,7 +133,7 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})

Expand All @@ -10,12 +20,12 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt
# This gets us DLL resource information when compiling on MinGW.
if(NOT CMAKE_RC_COMPILER)
set(CMAKE_RC_COMPILER windres.exe)
@@ -186,7 +186,7 @@
@@ -149,7 +149,7 @@ if(MINGW)
if(BUILD_SHARED_LIBS)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
endif()
-endif(MINGW)
+endif(MINGW AND NOT ANDROID)

add_library(zlib ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
if (BUILD_SHARED_LIBS)
13 changes: 0 additions & 13 deletions ports/zlib/add_debug_postfix_on_mingw.patch

This file was deleted.

Loading

0 comments on commit 05f4864

Please sign in to comment.