]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
adjust formatting
authorMasalskaya, Anna <anna.masalskaya@intel.com>
Wed, 16 Sep 2020 13:50:21 +0000 (16:50 +0300)
committerMasalskaya, Anna <anna.masalskaya@intel.com>
Wed, 16 Sep 2020 13:50:21 +0000 (16:50 +0300)
libarchive/archive_read_support_format_zip.c

index e17e46f3ad7bfd396b0298f9192477774a2d0332..81b8f86329c24f34f60e523d81c545fdb29c594d 100644 (file)
@@ -900,20 +900,30 @@ process_extra(struct archive_read *a, struct archive_entry *entry,
 }
 
 /*
- * Auxiliary function to uncompress data chunk from zipx archive (zip with lzma compression).
+ * Auxiliary function to uncompress data chunk from zipx archive
+ * (zip with lzma compression).
  */
 static int
-zipx_lzma_uncompress_buffer(const char *compressed_buffer, size_t compressed_buffer_size,
-       char *uncompressed_buffer, size_t uncompressed_buffer_size)
+zipx_lzma_uncompress_buffer(const char *compressed_buffer,
+       size_t compressed_buffer_size,
+       char *uncompressed_buffer,
+       size_t uncompressed_buffer_size)
 {
        int status = ARCHIVE_FATAL;
-       size_t lzma_params_length = 5; // length of 'lzma properties data' in lzma compressed data segment (stream) inside zip archive
-       size_t lzma_params_offset = 4; // offset of 'lzma properties data' from the beginning of lzma stream
-       size_t lzma_params_end = lzma_params_offset + lzma_params_length; // end position of 'lzma properties data' in lzma stream
-       if (compressed_buffer == NULL || compressed_buffer_size < lzma_params_end || uncompressed_buffer == NULL)
+       // length of 'lzma properties data' in lzma compressed
+       // data segment (stream) inside zip archive
+       const size_t lzma_params_length = 5;
+       // offset of 'lzma properties data' from the beginning of lzma stream
+       const size_t lzma_params_offset = 4;
+       // end position of 'lzma properties data' in lzma stream
+       const size_t lzma_params_end = lzma_params_offset + lzma_params_length;
+       if (compressed_buffer == NULL ||
+                       compressed_buffer_size < lzma_params_end ||
+                       uncompressed_buffer == NULL)
                return status;
 
-       // prepare header for lzma_alone_decoder to replace zipx header (see comments in 'zipx_lzma_alone_init' for justification)
+       // prepare header for lzma_alone_decoder to replace zipx header
+       // (see comments in 'zipx_lzma_alone_init' for justification)
 #pragma pack(push)
 #pragma pack(1)
        struct _alone_header
@@ -923,18 +933,24 @@ zipx_lzma_uncompress_buffer(const char *compressed_buffer, size_t compressed_buf
        } alone_header;
 #pragma pack(pop)
        // copy 'lzma properties data' blob
-       memcpy(&alone_header.bytes[0], compressed_buffer + lzma_params_offset, lzma_params_length);
+       memcpy(&alone_header.bytes[0], compressed_buffer + lzma_params_offset,
+               lzma_params_length);
        alone_header.uncompressed_size = UINT64_MAX;
 
        // prepare new compressed buffer, see 'zipx_lzma_alone_init' for details
-       size_t lzma_alone_buffer_size = compressed_buffer_size - lzma_params_end + sizeof(alone_header);
-       unsigned char *lzma_alone_compressed_buffer = (unsigned char*) malloc(lzma_alone_buffer_size);
+       const size_t lzma_alone_buffer_size =
+               compressed_buffer_size - lzma_params_end + sizeof(alone_header);
+       unsigned char *lzma_alone_compressed_buffer =
+               (unsigned char*) malloc(lzma_alone_buffer_size);
        if (lzma_alone_compressed_buffer == NULL)
                return status;
        // copy lzma_alone header into new buffer
-       memcpy(lzma_alone_compressed_buffer, (void*) &alone_header, sizeof(alone_header));
+       memcpy(lzma_alone_compressed_buffer, (void*) &alone_header,
+               sizeof(alone_header));
        // copy compressed data into new buffer
-       memcpy(lzma_alone_compressed_buffer + sizeof(alone_header), compressed_buffer + lzma_params_end, compressed_buffer_size - lzma_params_end);
+       memcpy(lzma_alone_compressed_buffer + sizeof(alone_header),
+               compressed_buffer + lzma_params_end,
+               compressed_buffer_size - lzma_params_end);
 
        // create and fill in lzma_alone_decoder stream
        lzma_stream stream = LZMA_STREAM_INIT;
@@ -1230,23 +1246,30 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
                            "Truncated Zip file");
                        return ARCHIVE_FATAL;
                }
-
-               size_t linkname_full_length = linkname_length; // take into account compression if any
-               if (zip->entry->compression != 0) // symlink target string appeared to be compressed
+               // take into account link compression if any
+               size_t linkname_full_length = linkname_length;
+               if (zip->entry->compression != 0)
                {
+                       // symlink target string appeared to be compressed
                        int status = ARCHIVE_FATAL;
-                       char *uncompressed_buffer = (char*) malloc(zip_entry->uncompressed_size);
+                       char *uncompressed_buffer =
+                               (char*) malloc(zip_entry->uncompressed_size);
                        if (uncompressed_buffer == NULL)
                        {
-                               archive_set_error(&a->archive, ENOMEM, "No memory for lzma decompression");
+                               archive_set_error(&a->archive, ENOMEM,
+                                       "No memory for lzma decompression");
                                return status;
                        }
 
                        switch (zip->entry->compression)
                        {
 #if HAVE_LZMA_H && HAVE_LIBLZMA
-                               case 14: /* ZIPx LZMA compression. (see zip file format specification, section 4.4.5)*/
-                                       status = zipx_lzma_uncompress_buffer(p, linkname_length, uncompressed_buffer, (size_t)zip_entry->uncompressed_size);
+                               case 14: /* ZIPx LZMA compression. */
+                                       /*(see zip file format specification, section 4.4.5)*/
+                                       status = zipx_lzma_uncompress_buffer(p,
+                                               linkname_length,
+                                               uncompressed_buffer,
+                                               (size_t)zip_entry->uncompressed_size);
                                        break;
 #endif
                                default: /* Unsupported compression. */
@@ -1255,13 +1278,17 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
                        if (status == ARCHIVE_OK)
                        {
                                p = uncompressed_buffer;
-                               linkname_full_length = (size_t)zip_entry->uncompressed_size;
+                               linkname_full_length =
+                                       (size_t)zip_entry->uncompressed_size;
                        }
                        else
                        {
-                               archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
-                                       "Unsupported ZIP compression method during decompression of link entry (%d: %s)",
-                                       zip->entry->compression, compression_name(zip->entry->compression));
+                               archive_set_error(&a->archive,
+                                       ARCHIVE_ERRNO_FILE_FORMAT,
+                                       "Unsupported ZIP compression method "
+                                       "during decompression of link entry (%d: %s)",
+                                       zip->entry->compression,
+                                       compression_name(zip->entry->compression));
                                return ARCHIVE_FAILED;
                        }
                }