Skip to content

Commit 14f591c

Browse files
authored
Remove LZMA (XZ) support (#139)
Context: https://tukaani.org/xz-backdoor/ In light of the recently discovered backdoor in xz-utils and its GitHub repository being blocked, remove the submodule from LibZipSharp and remove all the code to enable lzma compression support in it. Note that XZ support was disabled by default and was never released as part of any official LibZipSharp nugets/binaries, therefore we are not affected in any form or shape by the issue. The submodule is removed so that it is possible to clone and initialize this repository. When the issues surrounding xz-utils are fixed, we can restore support by reverting this commit.
1 parent 336a86f commit 14f591c

File tree

13 files changed

+4
-115
lines changed

13 files changed

+4
-115
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
path = external/bzip2
1313
url = https://sourceware.org/git/bzip2.git
1414
branch = master
15-
[submodule "external/xz"]
16-
path = external/xz
17-
url = https://github.com/tukaani-project/xz
1815
[submodule "zlib"]
1916
path = external/zlib
2017
url = https://github.com/madler/zlib.git

CMakeLists.txt

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.18)
33
#
44
# TODO:
55
#
6-
# * Windows: use vcpkg to build bzip2 and lzma (vcpkg can be used as a cmake subproject)
6+
# * Windows: use vcpkg to build bzip2 (vcpkg can be used as a cmake subproject)
77
# * Include portions of Mono.Posix native code (if necessary and when the new Mono.Posix is ready)
88
# * Add support Android builds
99
# * Add support for iOS/tvOS/macCatalyst builds
@@ -12,7 +12,6 @@ cmake_minimum_required(VERSION 3.18)
1212

1313
option(BUILD_DEPENDENCIES "Build only libzip dependencies" OFF)
1414
option(BUILD_LIBZIP "Build libzip and libZipSharp" OFF)
15-
option(ENABLE_XZ "Enable XZ (LZMA compression) in the build" OFF)
1615
option(ENABLE_ZLIBNG "Use zlib-ng instead of zlib" OFF)
1716

1817
set(CMAKE_POSITION_INDEPENDENT_CODE True CACHE BOOL "Always build position independent code" FORCE)
@@ -22,7 +21,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE True CACHE BOOL "Always build position indep
2221
#
2322

2423
#
25-
# libzip, zlib-ng, xz
24+
# libzip, zlib-ng
2625
#
2726
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build only as a static library" FORCE)
2827

@@ -48,10 +47,6 @@ set(ENABLE_MBEDTLS OFF CACHE BOOL "Do not use mbedtls for libzip" FORCE)
4847
set(ENABLE_WINDOWS_CRYPTO OFF CACHE BOOL "Do not use Windows Crypto" FORCE)
4948
set(ENABLE_ZSTD ON CACHE BOOL "Use zstd in libzip" FORCE)
5049

51-
if(NOT ENABLE_XZ)
52-
set(ENABLE_LZMA OFF CACHE BOOL "Do not use XZ for libzip" FORCE)
53-
endif()
54-
5550
#
5651
# zstd
5752
#
@@ -345,17 +340,6 @@ if(BUILD_DEPENDENCIES)
345340
"${ZLIB_EXTERN}"
346341
)
347342

348-
if(NOT WIN32 AND ENABLE_XZ)
349-
add_subdirectory(external/xz)
350-
351-
target_compile_options(
352-
liblzma
353-
PRIVATE
354-
${LZS_C_FLAGS}
355-
-fvisibility=hidden
356-
)
357-
endif()
358-
359343
add_subdirectory(external/zstd/build/cmake)
360344
if(UNIX)
361345
set(ZSTD_EXTERN "-DZSTDLIB_VISIBILITY=__attribute__((visibility(\"hidden\")))")
@@ -425,14 +409,7 @@ else()
425409

426410
set(ZLIB_ROOT "${ARTIFACTS_ROOT_DIR}" CACHE STRING "" FORCE)
427411
set(BZip2_ROOT "${ARTIFACTS_ROOT_DIR}" CACHE STRING "" FORCE)
428-
429-
if(ENABLE_XZ)
430-
if(WIN32)
431-
find_package(LibLZMA CONFIG REQUIRED)
432-
else()
433-
set(LibLZMA_ROOT "${ARTIFACTS_ROOT_DIR}" CACHE STRING "" FORCE)
434-
endif()
435-
endif()
412+
set(ENABLE_LZMA False CACHE BOOL "Disable lzma support, even if detected" FORCE)
436413

437414
list(PREPEND CMAKE_PREFIX_PATH "${ARTIFACTS_ROOT_DIR}")
438415

@@ -499,11 +476,6 @@ else()
499476
LIBZIPSHARP_VERSION="${LZS_VERSION}"
500477
)
501478

502-
if(ENABLE_XZ)
503-
message(STATUS "LZMA: ${LIBLZMA_INCLUDE_DIR}")
504-
else()
505-
message(STATUS "LZMA: DISABLED")
506-
endif()
507479
message(STATUS "ZSTD: ${Zstd_INCLUDE_DIR}")
508480
message(STATUS "ZLIB: ${ZLIB_INCLUDE_DIR}")
509481
message(STATUS "BZ2: ${BZIP2_INCLUDE_DIR}")
@@ -517,20 +489,6 @@ else()
517489
${CMAKE_BINARY_DIR}/external/libzip
518490
)
519491

520-
if(ENABLE_XZ)
521-
target_include_directories(
522-
${PROJECT_NAME}
523-
PRIVATE
524-
${LIBLZMA_INCLUDE_DIR}
525-
)
526-
527-
target_compile_definitions(
528-
${PROJECT_NAME}
529-
PRIVATE
530-
HAVE_XZ=1
531-
)
532-
endif()
533-
534492
target_compile_options(
535493
${PROJECT_NAME}
536494
PRIVATE
@@ -606,27 +564,15 @@ else()
606564
set(BZ2_PATH "${CMAKE_BINARY_DIR}/libbz2-fat.a")
607565
set(ZSTD_PATH "${CMAKE_BINARY_DIR}/libzstd-fat.a")
608566

609-
if(ENABLE_XZ)
610-
set(LZMA_PATH "${CMAKE_BINARY_DIR}/liblzma-fat.a")
611-
endif()
612-
613567
make_fat_archive("${ARTIFACTS_ROOT_DIR}/lib/libz.a" "${ARTIFACTS_OTHER_ROOT_DIR}/lib/libz.a" "${ZLIB_PATH}")
614568
make_fat_archive("${ARTIFACTS_ROOT_DIR}/lib/libbz2.a" "${ARTIFACTS_OTHER_ROOT_DIR}/lib/libbz2.a" "${BZ2_PATH}")
615569
make_fat_archive("${ARTIFACTS_ROOT_DIR}/lib/libzstd.a" "${ARTIFACTS_OTHER_ROOT_DIR}/lib/libzstd.a" "${ZSTD_PATH}")
616570

617-
if(ENABLE_XZ)
618-
make_fat_archive("${ARTIFACTS_ROOT_DIR}/lib/liblzma.a" "${ARTIFACTS_OTHER_ROOT_DIR}/lib/liblzma.a" "${LZMA_PATH}")
619-
endif()
620-
621571
set(LIBS
622572
${ZLIB_PATH}
623573
${BZ2_PATH}
624574
${ZSTD_PATH}
625575
)
626-
627-
if(ENABLE_XZ)
628-
list(APPEND LIBS ${LZMA_PATH})
629-
endif()
630576
else()
631577
if(WIN32)
632578
if(ENABLE_ZLIBNG)
@@ -640,20 +586,12 @@ else()
640586
${ARTIFACTS_ROOT_DIR}/lib/bz2.lib
641587
${ARTIFACTS_ROOT_DIR}/lib/zstd.lib
642588
)
643-
644-
if(ENABLE_XZ)
645-
list(APPEND LIBS LibLZMA::LibLZMA)
646-
endif()
647589
else()
648590
set(LIBS
649591
${ARTIFACTS_ROOT_DIR}/lib/libz.a
650592
${ARTIFACTS_ROOT_DIR}/lib/libbz2.a
651593
${ARTIFACTS_ROOT_DIR}/lib/libzstd.a
652594
)
653-
654-
if(ENABLE_XZ)
655-
list(APPEND LIBS ${ARTIFACTS_ROOT_DIR}/lib/liblzma.a)
656-
endif()
657595
endif()
658596
endif()
659597

LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>
1010
<ReferenceNuget Condition="'$(ReferenceNuget)' == ''">False</ReferenceNuget>
1111
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">$(DefineConstants);WINDOWS</DefineConstants>
12-
<DefineConstants Condition=" '$(UseXZ)' == 'True' ">$(DefineConstants);HAVE_XZ</DefineConstants>
1312
</PropertyGroup>
1413

1514
<ItemGroup>

LibZipSharp.UnitTest/ZipTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ public void NativeVersions ()
3232
Assert.IsNotEmpty (versions.LibZip, "libzip version must not be empty");
3333
Assert.IsNotEmpty (versions.Zlib, "zlib version must not be empty");
3434
Assert.IsNotEmpty (versions.ZlibNG, "zlib-ng version must not be empty");
35-
#if HAVE_XZ
36-
Assert.IsNotEmpty (versions.LZMA, "LZMA version must not be empty");
37-
#endif
3835
Assert.IsNotEmpty (versions.LibZipSharp, "LibZipSharp version must not be empty");
3936

4037
Console.WriteLine ($"LibZipSharp version: {versions.LibZipSharp}");
4138
Console.WriteLine ($"BZip2 version: {versions.BZip2}");
4239
Console.WriteLine ($"libzip version: {versions.LibZip}");
4340
Console.WriteLine ($"zlib version: {versions.Zlib}");
4441
Console.WriteLine ($"zlib-ng version: {versions.ZlibNG}");
45-
Console.WriteLine ($"LZMA version: {versions.LZMA}");
4642
}
4743

4844
[Test]
@@ -217,9 +213,6 @@ public void SmallTextFile ()
217213
[TestCase (CompressionMethod.Deflate)]
218214
[TestCase (CompressionMethod.Bzip2)]
219215
[TestCase (CompressionMethod.ZSTD)]
220-
#if HAVE_XZ
221-
[TestCase (CompressionMethod.XZ)]
222-
#endif
223216
public void UpdateEntryCompressionMethod (CompressionMethod method)
224217
{
225218
var zipStream = new MemoryStream ();

LibZipSharp.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
<_NativeBuildDir>$(MSBuildThisFileDirectory)lzsbuild</_NativeBuildDir>
1616
<_ExternalDir>$(MSBuildThisFileDirectory)external</_ExternalDir>
1717
<_MonoPosixNugetVersion>7.1.0-final.1.21458.1</_MonoPosixNugetVersion>
18-
<UseXZ Condition=" '$(UseXZ)' == '' ">false</UseXZ>
1918
</PropertyGroup>
2019
</Project>

LibZipSharp/Xamarin.Tools.Zip/Native.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public struct LZSVersions
4747
public string zlib;
4848
public string zlibng;
4949
public string zstd;
50-
public string lzma;
5150
public string libzipsharp;
5251
};
5352

@@ -149,7 +148,6 @@ public static Versions get_versions ()
149148
Zlib = ret.zlib ?? String.Empty,
150149
ZlibNG = ret.zlibng ?? String.Empty,
151150
ZStd = ret.zstd ?? String.Empty,
152-
LZMA = ret.lzma ?? String.Empty,
153151
LibZipSharp = ret.libzipsharp ?? String.Empty
154152
};
155153
}

LibZipSharp/Xamarin.Tools.Zip/Versions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ public string ZlibNG {
2222
get; internal set;
2323
}
2424

25-
public string LZMA {
26-
get; internal set;
27-
}
28-
2925
public string LibZipSharp {
3026
get; internal set;
3127
}

LibZipSharp/libZipSharp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
<None Include="..\LICENSE" PackagePath="Licences" Pack="true" />
6060
<None Include="$(_ExternalDir)\libzip\LICENSE" PackagePath="Licences\libzip" Pack="true" />
6161
<None Include="$(_ExternalDir)\bzip2\LICENSE" PackagePath="Licences\bzip2" Pack="true" />
62-
<None Include="$(_ExternalDir)\xz\COPYING.LGPLv2.1" PackagePath="Licences\liblzma" Pack="true" />
6362
<None Include="$(_ExternalDir)\zlib-ng\LICENSE.md" PackagePath="Licences\zlib-ng" Pack="true" />
6463
</ItemGroup>
6564
<ItemGroup>

build.sh

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ JOBS=""
3030
CONFIGURATION="RelWithDebInfo"
3131
REBUILD="no"
3232
VERBOSE="no"
33-
USE_XZ="no"
3433
USE_ZLIBNG="no"
3534

3635
# The color block is pilfered from the dotnet installer script
@@ -79,7 +78,6 @@ where OPTIONS are one or more of:
7978
-n|--ninja PATH use ninja at PATH instead of the default of '${NINJA}'
8079
-m|--cmake PATH use cmake at PATH instead of the default of '${CMAKE}'
8180
82-
-x|--xz use the XZ library for LZMA support (default: ${USE_XZ})
8381
-g|--zlib-ng use the zlib-ng library instead of zlib (default: ${USE_ZLIBNG}
8482
-c|--configuration NAME build using configuration NAME instead of the default of '${CONFIGURATION}'
8583
-j|--jobs NUM run at most this many build jobs in parallel
@@ -124,16 +122,11 @@ function cmake_configure()
124122
fi
125123
shift
126124

127-
local use_xz
128-
if [ "${USE_XZ}" == "yes" ]; then
129-
use_xz="-DENABLE_XZ=ON"
130-
fi
131-
132125
run_cmake_common \
133126
-B "${build_dir}" \
134127
-S "${MY_DIR}" \
135128
-G "${GENERATOR}" \
136-
-DCMAKE_BUILD_TYPE="${CONFIGURATION}" ${use_xz} \
129+
-DCMAKE_BUILD_TYPE="${CONFIGURATION}" \
137130
"$@"
138131
}
139132

@@ -235,11 +228,6 @@ while (( "$#" )); do
235228
fi
236229
;;
237230

238-
-x|--xz)
239-
USE_XZ="yes"
240-
GENERATOR="Unix Makefiles"
241-
shift ;;
242-
243231
-g|--zlib-ng) USE_ZLIBNG="yes"; shift ;;
244232

245233
-v|--verbose) VERBOSE="yes"; shift ;;
@@ -347,7 +335,3 @@ cmake_configure "${LZS_BUILD_DIR}" -DBUILD_LIBZIP=ON "-DARTIFACTS_ROOT_DIR=${ART
347335

348336
print_banner "Building libZipSharpNative"
349337
cmake_build "${LZS_BUILD_DIR}"
350-
351-
if [ "${USE_XZ}" == "yes" ]; then
352-
echo "${BRIGHT_BLUE}DON'T FORGET TO BUILD THE MANAGED CODE WITH THE /p:UseXZ=True OPTION!${NORMAL}"
353-
fi

build_windows.bat

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ popd
4343
external\vcpkg\vcpkg.exe integrate install
4444
if %errorlevel% neq 0 exit /b %errorlevel%
4545

46-
external\vcpkg\vcpkg.exe install liblzma:x64-windows-static liblzma:x86-windows-static liblzma:arm-windows-static
47-
if %errorlevel% neq 0 exit /b %errorlevel%
48-
4946
REM 64-bit deps
5047
mkdir "%DEPS_BUILD_DIR_ROOT_64%"
5148
cmake %COMMON_CMAKE_PARAMS% ^

external/xz

Lines changed: 0 additions & 1 deletion
This file was deleted.

native/version.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include <bzlib.h>
33
#include <zlib.h>
44
#include <zstd.h>
5-
#if defined (HAVE_XZ)
6-
#include <lzma.h>
7-
#endif // def HAVE_XZ
85
#include <zipconf.h>
96

107
#include "version.hh"
@@ -17,11 +14,6 @@ constexpr char libzlibng_version[] = ZLIBNG_VERSION;
1714
#else
1815
constexpr char libzlibng_version[] = "not used";
1916
#endif // ndef ZLIBNG_VERSION
20-
#if defined (HAVE_XZ)
21-
constexpr char lzma_version[] = LZMA_VERSION_STRING;
22-
#else
23-
constexpr char lzma_version[] = "not supported";
24-
#endif // def HAVE_XZ
2517

2618
void lzs_get_versions (LZSVersions *versions)
2719
{
@@ -34,6 +26,5 @@ void lzs_get_versions (LZSVersions *versions)
3426
versions->zlib = strdup (libzlib_version);
3527
versions->zlibng = strdup (libzlibng_version);
3628
versions->zstd = strdup (ZSTD_versionString ());
37-
versions->lzma = strdup (lzma_version);
3829
versions->libzipsharp = strdup (libzipsharp_version);
3930
}

native/version.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct LZSVersions
1010
const char *zlib;
1111
const char *zlibng;
1212
const char *zstd;
13-
const char *lzma;
1413
const char *libzipsharp;
1514
};
1615

0 commit comments

Comments
 (0)