CPack/DEB: Do not use lzma or bzip2 compression for control.tar

Since commit 57eed59f35 (CPack/DEB: Use the same compression type for
control tar, 2025-07-29), control.tar uses CPACK_DEBIAN_COMPRESSION_TYPE.
deb(5) allows lzma and bzip2 only for data.tar, so dpkg rejects packages
built with either type.  Fall back to gzip for control.tar in those cases,
as before that commit.

Fixes: #28169
This commit is contained in:
Olaf Mandel authored and Brad King committed 2026-10-14 10:42:42 -04:00
1 parent 07ebd37501
commit c98126d433
6 files changed
+62 -5

No files matched your search

+21 -5
View File
@@ -55,6 +55,7 @@ private:
std::string const OutputName;
std::string const WorkDir;
std::string CompressionSuffix;
std::string ControlCompressionSuffix;
std::string const TopLevelDir;
std::string const TemporaryDir;
std::string const DebianArchiveType;
@@ -72,6 +73,7 @@ private:
bool const PermissionStrictPolicy;
std::vector<std::string> const PackageFiles;
cmArchiveWrite::Compress TarCompressionType;
cmArchiveWrite::Compress ControlTarCompressionType;
int CompressionLevel = 0;
};
@@ -111,21 +113,35 @@ DebGenerator::DebGenerator(
if (debianCompressionType == "lzma") {
this->CompressionSuffix = ".lzma";
this->TarCompressionType = cmArchiveWrite::CompressLZMA;
// deb(5) does not allow lzma for control.tar.
this->ControlCompressionSuffix = ".gz";
this->ControlTarCompressionType = cmArchiveWrite::CompressGZip;
} else if (debianCompressionType == "xz") {
this->CompressionSuffix = ".xz";
this->TarCompressionType = cmArchiveWrite::CompressXZ;
this->ControlCompressionSuffix = this->CompressionSuffix;
this->ControlTarCompressionType = this->TarCompressionType;
} else if (debianCompressionType == "bzip2") {
this->CompressionSuffix = ".bz2";
this->TarCompressionType = cmArchiveWrite::CompressBZip2;
// deb(5) does not allow bzip2 for control.tar.
this->ControlCompressionSuffix = ".gz";
this->ControlTarCompressionType = cmArchiveWrite::CompressGZip;
} else if (debianCompressionType == "gzip") {
this->CompressionSuffix = ".gz";
this->TarCompressionType = cmArchiveWrite::CompressGZip;
this->ControlCompressionSuffix = this->CompressionSuffix;
this->ControlTarCompressionType = this->TarCompressionType;
} else if (debianCompressionType == "zstd") {
this->CompressionSuffix = ".zst";
this->TarCompressionType = cmArchiveWrite::CompressZstd;
this->ControlCompressionSuffix = this->CompressionSuffix;
this->ControlTarCompressionType = this->TarCompressionType;
} else if (debianCompressionType == "none") {
this->CompressionSuffix.clear();
this->TarCompressionType = cmArchiveWrite::CompressNone;
this->ControlCompressionSuffix.clear();
this->ControlTarCompressionType = cmArchiveWrite::CompressNone;
} else {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error unrecognized compression type: "
@@ -333,7 +349,7 @@ std::string DebGenerator::generateMD5File() const
bool DebGenerator::generateControlTar(std::string const& md5Filename) const
{
std::string filename_control_tar =
cmStrCat(this->WorkDir, "/control.tar", this->CompressionSuffix);
cmStrCat(this->WorkDir, "/control.tar", this->ControlCompressionSuffix);
cmGeneratedFileStream fileStream_control_tar;
fileStream_control_tar.Open(filename_control_tar, false, true);
@@ -343,9 +359,9 @@ bool DebGenerator::generateControlTar(std::string const& md5Filename) const
<< filename_control_tar << "\" for writing" << std::endl);
return false;
}
cmArchiveWrite control_tar(fileStream_control_tar, this->TarCompressionType,
this->DebianArchiveType, "UTF-8",
this->CompressionLevel);
cmArchiveWrite control_tar(
fileStream_control_tar, this->ControlTarCompressionType,
this->DebianArchiveType, "UTF-8", this->CompressionLevel);
if (!control_tar.Open()) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error opening the archive \""
@@ -520,7 +536,7 @@ bool DebGenerator::generateDeb() const
deb.SetUNAMEAndGNAME("root", "root");
if (!deb.Add(tlDir + "debian-binary", tlDir.length()) ||
!deb.Add(cmStrCat(tlDir, "control.tar", this->CompressionSuffix),
!deb.Add(cmStrCat(tlDir, "control.tar", this->ControlCompressionSuffix),
tlDir.length()) ||
!deb.Add(cmStrCat(tlDir, "data.tar", this->CompressionSuffix),
tlDir.length())) {
+1
View File
@@ -1457,6 +1457,7 @@ set(cpack_tests
DEB.MD5SUMS
DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY
DEB.DEB_DESCRIPTION
DEB.DEB_COMPRESSION_TYPE
DEB.PROJECT_META
DEB.COMPONENT_WITH_SPECIAL_CHARS
DEB.MULTIARCH
+1
View File
@@ -67,6 +67,7 @@ run_cpack_test(MD5SUMS "DEB.MD5SUMS" false "MONOLITHIC;COMPONENT")
run_cpack_test_subtests(CPACK_INSTALL_SCRIPTS "singular;plural;both" "ZIP" false "MONOLITHIC")
run_cpack_test(CPACK_CUSTOM_INSTALL_VARIABLES "ZIP" false "MONOLITHIC")
run_cpack_test(DEB_PACKAGE_VERSION_BACK_COMPATIBILITY "DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY" false "MONOLITHIC;COMPONENT")
run_cpack_test_subtests(DEB_COMPRESSION_TYPE "gzip;bzip2;lzma;xz;zstd;none" "DEB.DEB_COMPRESSION_TYPE" false "MONOLITHIC")
run_cpack_test_subtests(EXTERNAL "none;good;good_multi;bad_major;bad_minor;invalid_good;invalid_bad;stage_and_package" "External" false "MONOLITHIC;COMPONENT")
run_cpack_test_subtests(
DEB_DESCRIPTION
@@ -0,0 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
@@ -0,0 +1,34 @@
# deb(5) allows bzip2 and lzma only for data.tar, so control.tar must
# fall back to gzip for those.
set(control_suffix_gzip ".gz")
set(control_suffix_bzip2 ".gz")
set(control_suffix_lzma ".gz")
set(control_suffix_xz ".xz")
set(control_suffix_zstd ".zst")
set(control_suffix_none "")
set(data_suffix_gzip ".gz")
set(data_suffix_bzip2 ".bz2")
set(data_suffix_lzma ".lzma")
set(data_suffix_xz ".xz")
set(data_suffix_zstd ".zst")
set(data_suffix_none "")
set(expected_members
"debian-binary"
"control.tar${control_suffix_${RunCMake_SUBTEST_SUFFIX}}"
"data.tar${data_suffix_${RunCMake_SUBTEST_SUFFIX}}"
)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar tf "${FOUND_FILE_1}"
OUTPUT_VARIABLE actual_members
RESULT_VARIABLE result
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "\n" ";" actual_members "${actual_members}")
if(NOT result EQUAL 0 OR NOT actual_members STREQUAL expected_members)
message(FATAL_ERROR
"Unexpected members in '${FOUND_FILE_1}':\n"
" expected: ${expected_members}\n"
" actual: ${actual_members}")
endif()
@@ -0,0 +1,3 @@
install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
set(CPACK_DEBIAN_COMPRESSION_TYPE "${RunCMake_SUBTEST_SUFFIX}")