lzma: set general purpose bit flags appropriately
Also fix a bug in gpbf merging while here.
Addresses #198.
diff --git a/lib/zip_algorithm_xz.c b/lib/zip_algorithm_xz.c
index 984d45a..ee4548b 100644
--- a/lib/zip_algorithm_xz.c
+++ b/lib/zip_algorithm_xz.c
@@ -156,7 +156,17 @@
static zip_uint16_t
general_purpose_bit_flags(void *ud) {
- /* struct ctx *ctx = (struct ctx *)ud; */
+ struct ctx *ctx = (struct ctx *)ud;
+
+ if (!ctx->compress) {
+ return 0;
+ }
+
+ if (ctx->method == ZIP_CM_LZMA) {
+ /* liblzma always returns an EOS/EOPM marker, see
+ * https://sourceforge.net/p/lzmautils/discussion/708858/thread/84c5dbb9/#a5e4/3764 */
+ return 1 << 1;
+ }
return 0;
}
diff --git a/lib/zip_source_get_file_attributes.c b/lib/zip_source_get_file_attributes.c
index ee41544..734767a 100644
--- a/lib/zip_source_get_file_attributes.c
+++ b/lib/zip_source_get_file_attributes.c
@@ -88,7 +88,9 @@
}
if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS)) {
if (attributes->valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS) {
- attributes->general_purpose_bit_flags &= ~lower_attributes.general_purpose_bit_mask;
+ /* only take from lower level what is not defined at current level */
+ lower_attributes.general_purpose_bit_mask &= ~attributes->general_purpose_bit_mask;
+
attributes->general_purpose_bit_flags |= lower_attributes.general_purpose_bit_flags & lower_attributes.general_purpose_bit_mask;
attributes->general_purpose_bit_mask |= lower_attributes.general_purpose_bit_mask;
}
diff --git a/regress/testfile-lzma.zip b/regress/testfile-lzma.zip
index f6d0d40..f855b2a 100644
--- a/regress/testfile-lzma.zip
+++ b/regress/testfile-lzma.zip
Binary files differ