Skip to content

Commit

Permalink
Reusing code from zip size known and adjusting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaT75 committed Oct 27, 2021
1 parent eecf295 commit 02cfa8a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions libarchive/archive_write_set_format_zip.c
Expand Up @@ -740,17 +740,15 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
/* We may know the size, but never the CRC. */
zip->entry_flags |= ZIP_ENTRY_FLAG_LENGTH_AT_END;
} else {
/* We don't know the size. In this case, we prefer
* deflate (it has a clear end-of-data marker which
* makes length-at-end more reliable) and will
* enable Zip64 extensions unless we're told not to.
/* We don't know the size. Use the default
* compression unless specified otherwise.
* We enable Zip64 extensions unless we're told not to.
*/

#ifdef HAVE_ZLIB_H
if(zip->requested_compression == COMPRESSION_UNSPECIFIED){
zip->entry_compression = COMPRESSION_DEFLATE;
zip->entry_compression = zip->requested_compression;
if(zip->entry_compression == COMPRESSION_UNSPECIFIED){
zip->entry_compression = COMPRESSION_DEFAULT;
}
#endif

zip->entry_flags |= ZIP_ENTRY_FLAG_LENGTH_AT_END;
if ((zip->flags & ZIP_FLAG_AVOID_ZIP64) == 0) {
Expand Down

2 comments on commit 02cfa8a

@IAmAnubhavSaini
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change:

  • reduces information: 'it has a clear end-of-data marker which makes length-at-end more reliable'
  • changes deflate into default: COMPRESSION_DEFLATE is removed.
  • removes zlib header check.

If not malicious, I'd say on track to be.

zip->entry_compression = zip->requested_compression; and subsequent if conditions could be moved further apart to introduce bugs.

@proton-ab
Copy link

@proton-ab proton-ab commented on 02cfa8a Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit needs to be viewed as a part of larger PR (#1598) and its parent (de36667). Specifically, it would seem that the some changes from de36667 were reverted. Final diff can be viewed on https://github.com/libarchive/libarchive/pull/1598/files#diff-2f1ae3da987a7d1b3cf93b0fad39b902e73a411acc2444f9a68f54909bbd44e9

removes zlib header check.

Didn't exist prior to de36667

changes deflate into default: COMPRESSION_DEFLATE is removed.

Seems to mimic behavior prior to de36667 but clarifies comment (original comment specified that deflate is used, however code actually used DEFAULT)

Please sign in to comment.