Rizin
unix-like reverse engineering framework and cli tools
zipint.h File Reference
#include "config.h"
#include "compat.h"
#include "zip.h"
#include <string.h>

Go to the source code of this file.

Classes

struct  zip_compression_algorithm
 
struct  _zip_err_info
 
struct  zip
 
struct  zip_file
 
struct  zip_dirent
 
struct  zip_cdir
 
struct  zip_extra_field
 
struct  zip_source
 
struct  zip_entry
 
struct  zip_string
 
struct  zip_buffer
 
struct  zip_filelist
 
struct  _zip_pkware_keys
 

Macros

#define CENTRAL_MAGIC   "PK\1\2"
 
#define LOCAL_MAGIC   "PK\3\4"
 
#define EOCD_MAGIC   "PK\5\6"
 
#define DATADES_MAGIC   "PK\7\10"
 
#define EOCD64LOC_MAGIC   "PK\6\7"
 
#define EOCD64_MAGIC   "PK\6\6"
 
#define CDENTRYSIZE   46u
 
#define LENTRYSIZE   30
 
#define MAXCOMLEN   65536
 
#define MAXEXTLEN   65536
 
#define EOCDLEN   22
 
#define EOCD64LOCLEN   20
 
#define EOCD64LEN   56
 
#define CDBUFSIZE   (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
 
#define BUFSIZE   8192
 
#define EFZIP64SIZE   28
 
#define EF_WINZIP_AES_SIZE   7
 
#define MAX_DATA_DESCRIPTOR_LENGTH   24
 
#define ZIP_CRYPTO_PKWARE_HEADERLEN   12
 
#define ZIP_CM_REPLACED_DEFAULT   (-2)
 
#define ZIP_CM_WINZIP_AES   99 /* Winzip AES encrypted */
 
#define WINZIP_AES_PASSWORD_VERIFY_LENGTH   2
 
#define WINZIP_AES_MAX_HEADER_LENGTH   (16 + WINZIP_AES_PASSWORD_VERIFY_LENGTH)
 
#define AES_BLOCK_SIZE   16
 
#define HMAC_LENGTH   10
 
#define SHA1_LENGTH   20
 
#define SALT_LENGTH(method)   ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
 
#define ZIP_CM_IS_DEFAULT(x)   ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT)
 
#define ZIP_CM_ACTUAL(x)   ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x)))
 
#define ZIP_EF_UTF_8_COMMENT   0x6375
 
#define ZIP_EF_UTF_8_NAME   0x7075
 
#define ZIP_EF_WINZIP_AES   0x9901
 
#define ZIP_EF_ZIP64   0x0001
 
#define ZIP_EF_IS_INTERNAL(id)   ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
 
#define ZIP_EXT_ATTRIB_DEFAULT   (0100666u << 16)
 
#define ZIP_EXT_ATTRIB_DEFAULT_DIR   (0040777u << 16)
 
#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK   0x0836
 
#define ZIP_MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define ZIP_MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define ZIP_CODEC_DECODE   0 /* decompress/decrypt (encode flag not set) */
 
#define ZIP_CODEC_ENCODE   1 /* compress/encrypt */
 
#define ZIP_DETAIL_ET_GLOBAL   0
 
#define ZIP_DETAIL_ET_ENTRY   1
 
#define MAX_DETAIL_INDEX   0x7fffff
 
#define MAKE_DETAIL_WITH_INDEX(error, index)   ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
 
#define GET_INDEX_FROM_DETAIL(error)   (((error) >> 8) & MAX_DETAIL_INDEX)
 
#define GET_ERROR_FROM_DETAIL(error)   ((error) & 0xff)
 
#define ADD_INDEX_TO_DETAIL(error, index)   MAKE_DETAIL_WITH_INDEX(GET_ERROR_FROM_DETAIL(error), (index))
 
#define ZIP_ER_DETAIL_NO_DETAIL   0 /* G no detail */
 
#define ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD   1 /* G central directory overlaps EOCD, or there is space between them */
 
#define ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID   2 /* G archive comment length incorrect */
 
#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID   3 /* G central directory length invalid */
 
#define ZIP_ER_DETAIL_CDIR_ENTRY_INVALID   4 /* E central header invalid */
 
#define ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT   5 /* G central directory count of entries is incorrect */
 
#define ZIP_ER_DETAIL_ENTRY_HEADER_MISMATCH   6 /* E local and central headers do not match */
 
#define ZIP_ER_DETAIL_EOCD_LENGTH_INVALID   7 /* G wrong EOCD length */
 
#define ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD   8 /* G EOCD64 overlaps EOCD, or there is space between them */
 
#define ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC   9 /* G EOCD64 magic incorrect */
 
#define ZIP_ER_DETAIL_EOCD64_MISMATCH   10 /* G EOCD64 and EOCD do not match */
 
#define ZIP_ER_DETAIL_CDIR_INVALID   11 /* G invalid value in central directory */
 
#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW   12 /* E variable size fields overflow header */
 
#define ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME   13 /* E invalid UTF-8 in filename */
 
#define ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT   13 /* E invalid UTF-8 in comment */
 
#define ZIP_ER_DETAIL_INVALID_ZIP64_EF   14 /* E invalid Zip64 extra field */
 
#define ZIP_ER_DETAIL_INVALID_WINZIPAES_EF   14 /* E invalid WinZip AES extra field */
 
#define ZIP_ER_DETAIL_EF_TRAILING_GARBAGE   15 /* E garbage at end of extra fields */
 
#define ZIP_ER_DETAIL_INVALID_EF_LENGTH   16 /* E extra field length is invalid */
 
#define ZIP_ER_DETAIL_INVALID_FILE_LENGTH   17 /* E file length in header doesn't match actual file length */
 
#define ZIP_GPBF_ENCRYPTED   0x0001u /* is encrypted */
 
#define ZIP_GPBF_DATA_DESCRIPTOR   0x0008u /* crc/size after file data */
 
#define ZIP_GPBF_STRONG_ENCRYPTION   0x0040u /* uses strong encryption */
 
#define ZIP_GPBF_ENCODING_UTF_8   0x0800u /* file name encoding is UTF-8 */
 
#define ZIP_EF_LOCAL   ZIP_FL_LOCAL /* include in local header */
 
#define ZIP_EF_CENTRAL   ZIP_FL_CENTRAL /* include in central directory */
 
#define ZIP_EF_BOTH   (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
 
#define ZIP_FL_FORCE_ZIP64   1024 /* force zip64 extra field (_zip_dirent_write) */
 
#define ZIP_FL_ENCODING_ALL   (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
 
#define ZIP_DIRENT_COMP_METHOD   0x0001u
 
#define ZIP_DIRENT_FILENAME   0x0002u
 
#define ZIP_DIRENT_COMMENT   0x0004u
 
#define ZIP_DIRENT_EXTRA_FIELD   0x0008u
 
#define ZIP_DIRENT_ATTRIBUTES   0x0010u
 
#define ZIP_DIRENT_LAST_MOD   0x0020u
 
#define ZIP_DIRENT_ENCRYPTION_METHOD   0x0040u
 
#define ZIP_DIRENT_PASSWORD   0x0080u
 
#define ZIP_DIRENT_ALL   ZIP_UINT32_MAX
 
#define ZIP_SOURCE_IS_OPEN_READING(src)   ((src)->open_count > 0)
 
#define ZIP_SOURCE_IS_OPEN_WRITING(src)   ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
 
#define ZIP_SOURCE_IS_LAYERED(src)   ((src)->src != NULL)
 
#define DEFINE_BYTE_ARRAY(buf, size)   zip_uint8_t buf[size]
 
#define byte_array_init(buf, size)   (1)
 
#define byte_array_fini(buf)   ((void)0)
 
#define ZIP_MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define ZIP_MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define ZIP_ENTRY_CHANGED(e, f)   ((e)->changes && ((e)->changes->changed & (f)))
 
#define ZIP_ENTRY_DATA_CHANGED(x)   ((x)->source != NULL)
 
#define ZIP_ENTRY_HAS_CHANGES(e)   (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
 
#define ZIP_IS_RDONLY(za)   ((za)->ch_flags & ZIP_AFL_RDONLY)
 
#define _zip_crypto_clear(b, l)   memset((b), 0, (l))
 

Typedefs

typedef zip_source_t *(* zip_encryption_implementation) (zip_t *, zip_source_t *, zip_uint16_t, int, const char *)
 
typedef enum zip_compression_status zip_compression_status_t
 
typedef struct zip_compression_algorithm zip_compression_algorithm_t
 
typedef zip_int64_t(* zip_source_layered_callback) (zip_source_t *, void *, void *, zip_uint64_t, enum zip_source_cmd)
 
typedef enum zip_encoding_type zip_encoding_type_t
 
typedef struct zip_cdir zip_cdir_t
 
typedef struct zip_dirent zip_dirent_t
 
typedef struct zip_entry zip_entry_t
 
typedef struct zip_extra_field zip_extra_field_t
 
typedef struct zip_string zip_string_t
 
typedef struct zip_buffer zip_buffer_t
 
typedef struct zip_hash zip_hash_t
 
typedef struct zip_progress zip_progress_t
 
typedef enum zip_source_write_state zip_source_write_state_t
 
typedef struct zip_filelist zip_filelist_t
 
typedef struct _zip_winzip_aes zip_winzip_aes_t
 
typedef struct _zip_pkware_keys zip_pkware_keys_t
 

Enumerations

enum  zip_compression_status { ZIP_COMPRESSION_OK , ZIP_COMPRESSION_END , ZIP_COMPRESSION_ERROR , ZIP_COMPRESSION_NEED_DATA }
 
enum  zip_les { ZIP_LES_NONE , ZIP_LES_UPPER , ZIP_LES_LOWER , ZIP_LES_INVAL }
 
enum  zip_encoding_type {
  ZIP_ENCODING_UNKNOWN , ZIP_ENCODING_ASCII , ZIP_ENCODING_UTF8_KNOWN , ZIP_ENCODING_UTF8_GUESSED ,
  ZIP_ENCODING_CP437 , ZIP_ENCODING_ERROR
}
 
enum  zip_source_write_state { ZIP_SOURCE_WRITE_CLOSED , ZIP_SOURCE_WRITE_OPEN , ZIP_SOURCE_WRITE_FAILED , ZIP_SOURCE_WRITE_REMOVED }
 

Functions

zip_encryption_implementation _zip_get_encryption_implementation (zip_uint16_t method, int operation)
 
zip_compression_algorithm_t_zip_get_compression_algorithm (zip_int32_t method, bool compress)
 
const zip_uint8_tzip_get_extra_field_by_id (zip_t *, int, int, zip_uint16_t, int, zip_uint16_t *)
 
zip_source_tzip_source_compress (zip_t *za, zip_source_t *src, zip_int32_t cm, int compression_flags)
 
zip_source_tzip_source_crc_create (zip_source_t *, int, zip_error_t *error)
 
zip_source_tzip_source_decompress (zip_t *za, zip_source_t *src, zip_int32_t cm)
 
zip_source_tzip_source_layered (zip_t *, zip_source_t *, zip_source_layered_callback, void *)
 
zip_source_tzip_source_layered_create (zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error)
 
zip_source_tzip_source_pkware_decode (zip_t *, zip_source_t *, zip_uint16_t, int, const char *)
 
zip_source_tzip_source_pkware_encode (zip_t *, zip_source_t *, zip_uint16_t, int, const char *)
 
int zip_source_remove (zip_source_t *)
 
zip_int64_t zip_source_supports (zip_source_t *src)
 
zip_source_tzip_source_winzip_aes_decode (zip_t *, zip_source_t *, zip_uint16_t, int, const char *)
 
zip_source_tzip_source_winzip_aes_encode (zip_t *, zip_source_t *, zip_uint16_t, int, const char *)
 
zip_source_tzip_source_buffer_with_attributes (zip_t *za, const void *data, zip_uint64_t len, int freep, zip_file_attributes_t *attributes)
 
zip_source_tzip_source_buffer_with_attributes_create (const void *data, zip_uint64_t len, int freep, zip_file_attributes_t *attributes, zip_error_t *error)
 
zip_int64_t _zip_add_entry (zip_t *)
 
zip_uint8_t_zip_buffer_data (zip_buffer_t *buffer)
 
bool _zip_buffer_eof (zip_buffer_t *buffer)
 
void _zip_buffer_free (zip_buffer_t *buffer)
 
zip_uint8_t_zip_buffer_get (zip_buffer_t *buffer, zip_uint64_t length)
 
zip_uint16_t _zip_buffer_get_16 (zip_buffer_t *buffer)
 
zip_uint32_t _zip_buffer_get_32 (zip_buffer_t *buffer)
 
zip_uint64_t _zip_buffer_get_64 (zip_buffer_t *buffer)
 
zip_uint8_t _zip_buffer_get_8 (zip_buffer_t *buffer)
 
zip_uint64_t _zip_buffer_left (zip_buffer_t *buffer)
 
zip_buffer_t_zip_buffer_new (zip_uint8_t *data, zip_uint64_t size)
 
zip_buffer_t_zip_buffer_new_from_source (zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error)
 
zip_uint64_t _zip_buffer_offset (zip_buffer_t *buffer)
 
bool _zip_buffer_ok (zip_buffer_t *buffer)
 
zip_uint8_t_zip_buffer_peek (zip_buffer_t *buffer, zip_uint64_t length)
 
int _zip_buffer_put (zip_buffer_t *buffer, const void *src, size_t length)
 
int _zip_buffer_put_16 (zip_buffer_t *buffer, zip_uint16_t i)
 
int _zip_buffer_put_32 (zip_buffer_t *buffer, zip_uint32_t i)
 
int _zip_buffer_put_64 (zip_buffer_t *buffer, zip_uint64_t i)
 
int _zip_buffer_put_8 (zip_buffer_t *buffer, zip_uint8_t i)
 
zip_uint64_t _zip_buffer_read (zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length)
 
int _zip_buffer_skip (zip_buffer_t *buffer, zip_uint64_t length)
 
int _zip_buffer_set_offset (zip_buffer_t *buffer, zip_uint64_t offset)
 
zip_uint64_t _zip_buffer_size (zip_buffer_t *buffer)
 
void _zip_cdir_free (zip_cdir_t *)
 
bool _zip_cdir_grow (zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error)
 
zip_cdir_t_zip_cdir_new (zip_uint64_t, zip_error_t *)
 
zip_int64_t _zip_cdir_write (zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors)
 
time_t _zip_d2u_time (zip_uint16_t, zip_uint16_t)
 
void _zip_deregister_source (zip_t *za, zip_source_t *src)
 
void _zip_dirent_apply_attributes (zip_dirent_t *, zip_file_attributes_t *, bool, zip_uint32_t)
 
zip_dirent_t_zip_dirent_clone (const zip_dirent_t *)
 
void _zip_dirent_free (zip_dirent_t *)
 
void _zip_dirent_finalize (zip_dirent_t *)
 
void _zip_dirent_init (zip_dirent_t *)
 
bool _zip_dirent_needs_zip64 (const zip_dirent_t *, zip_flags_t)
 
zip_dirent_t_zip_dirent_new (void)
 
zip_int64_t _zip_dirent_read (zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error)
 
void _zip_dirent_set_version_needed (zip_dirent_t *de, bool force_zip64)
 
zip_int32_t _zip_dirent_size (zip_source_t *src, zip_uint16_t, zip_error_t *)
 
int _zip_dirent_write (zip_t *za, zip_dirent_t *dirent, zip_flags_t flags)
 
zip_extra_field_t_zip_ef_clone (const zip_extra_field_t *, zip_error_t *)
 
zip_extra_field_t_zip_ef_delete_by_id (zip_extra_field_t *, zip_uint16_t, zip_uint16_t, zip_flags_t)
 
void _zip_ef_free (zip_extra_field_t *)
 
const zip_uint8_t_zip_ef_get_by_id (const zip_extra_field_t *, zip_uint16_t *, zip_uint16_t, zip_uint16_t, zip_flags_t, zip_error_t *)
 
zip_extra_field_t_zip_ef_merge (zip_extra_field_t *, zip_extra_field_t *)
 
zip_extra_field_t_zip_ef_new (zip_uint16_t, zip_uint16_t, const zip_uint8_t *, zip_flags_t)
 
bool _zip_ef_parse (const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_extra_field_t **, zip_error_t *)
 
zip_extra_field_t_zip_ef_remove_internal (zip_extra_field_t *)
 
zip_uint16_t _zip_ef_size (const zip_extra_field_t *, zip_flags_t)
 
int _zip_ef_write (zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags)
 
void _zip_entry_finalize (zip_entry_t *)
 
void _zip_entry_init (zip_entry_t *)
 
void _zip_error_clear (zip_error_t *)
 
void _zip_error_get (const zip_error_t *, int *, int *)
 
void _zip_error_copy (zip_error_t *dst, const zip_error_t *src)
 
void _zip_error_set_from_source (zip_error_t *, zip_source_t *)
 
const zip_uint8_t_zip_extract_extra_field_by_id (zip_error_t *, zip_uint16_t, int, const zip_uint8_t *, zip_uint16_t, zip_uint16_t *)
 
int _zip_file_extra_field_prepare_for_change (zip_t *, zip_uint64_t)
 
int _zip_file_fillbuf (void *, size_t, zip_file_t *)
 
zip_uint64_t _zip_file_get_end (const zip_t *za, zip_uint64_t index, zip_error_t *error)
 
zip_uint64_t _zip_file_get_offset (const zip_t *, zip_uint64_t, zip_error_t *)
 
zip_dirent_t_zip_get_dirent (zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *)
 
enum zip_encoding_type _zip_guess_encoding (zip_string_t *, enum zip_encoding_type)
 
zip_uint8_t_zip_cp437_to_utf8 (const zip_uint8_t *const, zip_uint32_t, zip_uint32_t *, zip_error_t *)
 
bool _zip_hash_add (zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error)
 
bool _zip_hash_delete (zip_hash_t *hash, const zip_uint8_t *key, zip_error_t *error)
 
void _zip_hash_free (zip_hash_t *hash)
 
zip_int64_t _zip_hash_lookup (zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error)
 
zip_hash_t_zip_hash_new (zip_error_t *error)
 
bool _zip_hash_reserve_capacity (zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error)
 
bool _zip_hash_revert (zip_hash_t *hash, zip_error_t *error)
 
int _zip_mkstempm (char *path, int mode, bool create_file)
 
zip_t_zip_open (zip_source_t *, unsigned int, zip_error_t *)
 
void _zip_progress_end (zip_progress_t *progress)
 
void _zip_progress_free (zip_progress_t *progress)
 
int _zip_progress_start (zip_progress_t *progress)
 
int _zip_progress_subrange (zip_progress_t *progress, double start, double end)
 
int _zip_progress_update (zip_progress_t *progress, double value)
 
ZIP_EXTERN bool zip_secure_random (zip_uint8_t *buffer, zip_uint16_t length)
 
zip_uint32_t zip_random_uint32 (void)
 
int _zip_read (zip_source_t *src, zip_uint8_t *data, zip_uint64_t length, zip_error_t *error)
 
int _zip_read_at_offset (zip_source_t *src, zip_uint64_t offset, unsigned char *b, size_t length, zip_error_t *error)
 
zip_uint8_t_zip_read_data (zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error)
 
int _zip_read_local_ef (zip_t *, zip_uint64_t)
 
zip_string_t_zip_read_string (zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t length, bool nulp, zip_error_t *error)
 
int _zip_register_source (zip_t *za, zip_source_t *src)
 
void _zip_set_open_error (int *zep, const zip_error_t *err, int ze)
 
bool zip_source_accept_empty (zip_source_t *src)
 
zip_int64_t _zip_source_call (zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command)
 
bool _zip_source_eof (zip_source_t *)
 
zip_source_t_zip_source_file_or_p (const char *, FILE *, zip_uint64_t, zip_int64_t, const zip_stat_t *, zip_error_t *error)
 
bool _zip_source_had_error (zip_source_t *)
 
void _zip_source_invalidate (zip_source_t *src)
 
zip_source_t_zip_source_new (zip_error_t *error)
 
int _zip_source_set_source_archive (zip_source_t *, zip_t *)
 
zip_source_t_zip_source_window_new (zip_source_t *src, zip_uint64_t start, zip_int64_t length, zip_stat_t *st, zip_file_attributes_t *attributes, zip_t *source_archive, zip_uint64_t source_index, zip_error_t *error)
 
zip_source_t_zip_source_zip_new (zip_t *, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_uint64_t, const char *, zip_error_t *error)
 
int _zip_stat_merge (zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error)
 
int _zip_string_equal (const zip_string_t *a, const zip_string_t *b)
 
void _zip_string_free (zip_string_t *string)
 
zip_uint32_t _zip_string_crc32 (const zip_string_t *string)
 
const zip_uint8_t_zip_string_get (zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error)
 
zip_uint16_t _zip_string_length (const zip_string_t *string)
 
zip_string_t_zip_string_new (const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error)
 
int _zip_string_write (zip_t *za, const zip_string_t *string)
 
bool _zip_winzip_aes_decrypt (zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length)
 
bool _zip_winzip_aes_encrypt (zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length)
 
bool _zip_winzip_aes_finish (zip_winzip_aes_t *ctx, zip_uint8_t *hmac)
 
void _zip_winzip_aes_free (zip_winzip_aes_t *ctx)
 
zip_winzip_aes_t_zip_winzip_aes_new (const zip_uint8_t *password, zip_uint64_t password_length, const zip_uint8_t *salt, zip_uint16_t key_size, zip_uint8_t *password_verify, zip_error_t *error)
 
void _zip_pkware_encrypt (zip_pkware_keys_t *keys, zip_uint8_t *out, const zip_uint8_t *in, zip_uint64_t len)
 
void _zip_pkware_decrypt (zip_pkware_keys_t *keys, zip_uint8_t *out, const zip_uint8_t *in, zip_uint64_t len)
 
zip_pkware_keys_t_zip_pkware_keys_new (zip_error_t *error)
 
void _zip_pkware_keys_free (zip_pkware_keys_t *keys)
 
void _zip_pkware_keys_reset (zip_pkware_keys_t *keys)
 
int _zip_changed (const zip_t *, zip_uint64_t *)
 
const char * _zip_get_name (zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *)
 
int _zip_local_header_read (zip_t *, int)
 
void * _zip_memdup (const void *, size_t, zip_error_t *)
 
zip_int64_t _zip_name_locate (zip_t *, const char *, zip_flags_t, zip_error_t *)
 
zip_t_zip_new (zip_error_t *)
 
zip_int64_t _zip_file_replace (zip_t *, zip_uint64_t, const char *, zip_source_t *, zip_flags_t)
 
int _zip_set_name (zip_t *, zip_uint64_t, const char *, zip_flags_t)
 
void _zip_u2d_time (time_t, zip_uint16_t *, zip_uint16_t *)
 
int _zip_unchange (zip_t *, zip_uint64_t, int)
 
void _zip_unchange_data (zip_entry_t *)
 
int _zip_write (zip_t *za, const void *data, zip_uint64_t length)
 

Variables

zip_compression_algorithm_t zip_algorithm_bzip2_compress
 
zip_compression_algorithm_t zip_algorithm_bzip2_decompress
 
zip_compression_algorithm_t zip_algorithm_deflate_compress
 
zip_compression_algorithm_t zip_algorithm_deflate_decompress
 
zip_compression_algorithm_t zip_algorithm_xz_compress
 
zip_compression_algorithm_t zip_algorithm_xz_decompress
 
zip_compression_algorithm_t zip_algorithm_zstd_compress
 
zip_compression_algorithm_t zip_algorithm_zstd_decompress
 
const struct _zip_err_info _zip_err_str []
 
const int _zip_err_str_count
 
const struct _zip_err_info _zip_err_details []
 
const int _zip_err_details_count
 

Macro Definition Documentation

◆ _zip_crypto_clear

#define _zip_crypto_clear (   b,
 
)    memset((b), 0, (l))

Definition at line 489 of file zipint.h.

◆ ADD_INDEX_TO_DETAIL

#define ADD_INDEX_TO_DETAIL (   error,
  index 
)    MAKE_DETAIL_WITH_INDEX(GET_ERROR_FROM_DETAIL(error), (index))

Definition at line 210 of file zipint.h.

◆ AES_BLOCK_SIZE

#define AES_BLOCK_SIZE   16

Definition at line 77 of file zipint.h.

◆ BUFSIZE

#define BUFSIZE   8192

Definition at line 65 of file zipint.h.

◆ byte_array_fini

#define byte_array_fini (   buf)    ((void)0)

Definition at line 440 of file zipint.h.

◆ byte_array_init

#define byte_array_init (   buf,
  size 
)    (1)

Definition at line 439 of file zipint.h.

◆ CDBUFSIZE

#define CDBUFSIZE   (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)

Definition at line 64 of file zipint.h.

◆ CDENTRYSIZE

#define CDENTRYSIZE   46u

Definition at line 57 of file zipint.h.

◆ CENTRAL_MAGIC

#define CENTRAL_MAGIC   "PK\1\2"

Definition at line 51 of file zipint.h.

◆ DATADES_MAGIC

#define DATADES_MAGIC   "PK\7\10"

Definition at line 54 of file zipint.h.

◆ DEFINE_BYTE_ARRAY

#define DEFINE_BYTE_ARRAY (   buf,
  size 
)    zip_uint8_t buf[size]

Definition at line 438 of file zipint.h.

◆ EF_WINZIP_AES_SIZE

#define EF_WINZIP_AES_SIZE   7

Definition at line 67 of file zipint.h.

◆ EFZIP64SIZE

#define EFZIP64SIZE   28

Definition at line 66 of file zipint.h.

◆ EOCD64_MAGIC

#define EOCD64_MAGIC   "PK\6\6"

Definition at line 56 of file zipint.h.

◆ EOCD64LEN

#define EOCD64LEN   56

Definition at line 63 of file zipint.h.

◆ EOCD64LOC_MAGIC

#define EOCD64LOC_MAGIC   "PK\6\7"

Definition at line 55 of file zipint.h.

◆ EOCD64LOCLEN

#define EOCD64LOCLEN   20

Definition at line 62 of file zipint.h.

◆ EOCD_MAGIC

#define EOCD_MAGIC   "PK\5\6"

Definition at line 53 of file zipint.h.

◆ EOCDLEN

#define EOCDLEN   22

Definition at line 61 of file zipint.h.

◆ GET_ERROR_FROM_DETAIL

#define GET_ERROR_FROM_DETAIL (   error)    ((error) & 0xff)

Definition at line 209 of file zipint.h.

◆ GET_INDEX_FROM_DETAIL

#define GET_INDEX_FROM_DETAIL (   error)    (((error) >> 8) & MAX_DETAIL_INDEX)

Definition at line 208 of file zipint.h.

◆ HMAC_LENGTH

#define HMAC_LENGTH   10

Definition at line 78 of file zipint.h.

◆ LENTRYSIZE

#define LENTRYSIZE   30

Definition at line 58 of file zipint.h.

◆ LOCAL_MAGIC

#define LOCAL_MAGIC   "PK\3\4"

Definition at line 52 of file zipint.h.

◆ MAKE_DETAIL_WITH_INDEX

#define MAKE_DETAIL_WITH_INDEX (   error,
  index 
)    ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))

Definition at line 207 of file zipint.h.

◆ MAX_DATA_DESCRIPTOR_LENGTH

#define MAX_DATA_DESCRIPTOR_LENGTH   24

Definition at line 68 of file zipint.h.

◆ MAX_DETAIL_INDEX

#define MAX_DETAIL_INDEX   0x7fffff

Definition at line 206 of file zipint.h.

◆ MAXCOMLEN

#define MAXCOMLEN   65536

Definition at line 59 of file zipint.h.

◆ MAXEXTLEN

#define MAXEXTLEN   65536

Definition at line 60 of file zipint.h.

◆ SALT_LENGTH

#define SALT_LENGTH (   method)    ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))

Definition at line 80 of file zipint.h.

◆ SHA1_LENGTH

#define SHA1_LENGTH   20

Definition at line 79 of file zipint.h.

◆ WINZIP_AES_MAX_HEADER_LENGTH

#define WINZIP_AES_MAX_HEADER_LENGTH   (16 + WINZIP_AES_PASSWORD_VERIFY_LENGTH)

Definition at line 76 of file zipint.h.

◆ WINZIP_AES_PASSWORD_VERIFY_LENGTH

#define WINZIP_AES_PASSWORD_VERIFY_LENGTH   2

Definition at line 75 of file zipint.h.

◆ ZIP_CM_ACTUAL

#define ZIP_CM_ACTUAL (   x)    ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x)))

Definition at line 83 of file zipint.h.

◆ ZIP_CM_IS_DEFAULT

#define ZIP_CM_IS_DEFAULT (   x)    ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT)

Definition at line 82 of file zipint.h.

◆ ZIP_CM_REPLACED_DEFAULT

#define ZIP_CM_REPLACED_DEFAULT   (-2)

Definition at line 72 of file zipint.h.

◆ ZIP_CM_WINZIP_AES

#define ZIP_CM_WINZIP_AES   99 /* Winzip AES encrypted */

Definition at line 73 of file zipint.h.

◆ ZIP_CODEC_DECODE

#define ZIP_CODEC_DECODE   0 /* decompress/decrypt (encode flag not set) */

Definition at line 107 of file zipint.h.

◆ ZIP_CODEC_ENCODE

#define ZIP_CODEC_ENCODE   1 /* compress/encrypt */

Definition at line 108 of file zipint.h.

◆ ZIP_CRYPTO_PKWARE_HEADERLEN

#define ZIP_CRYPTO_PKWARE_HEADERLEN   12

Definition at line 70 of file zipint.h.

◆ ZIP_DETAIL_ET_ENTRY

#define ZIP_DETAIL_ET_ENTRY   1

Definition at line 193 of file zipint.h.

◆ ZIP_DETAIL_ET_GLOBAL

#define ZIP_DETAIL_ET_GLOBAL   0

Definition at line 192 of file zipint.h.

◆ ZIP_DIRENT_ALL

#define ZIP_DIRENT_ALL   ZIP_UINT32_MAX

Definition at line 324 of file zipint.h.

◆ ZIP_DIRENT_ATTRIBUTES

#define ZIP_DIRENT_ATTRIBUTES   0x0010u

Definition at line 320 of file zipint.h.

◆ ZIP_DIRENT_COMMENT

#define ZIP_DIRENT_COMMENT   0x0004u

Definition at line 318 of file zipint.h.

◆ ZIP_DIRENT_COMP_METHOD

#define ZIP_DIRENT_COMP_METHOD   0x0001u

Definition at line 316 of file zipint.h.

◆ ZIP_DIRENT_ENCRYPTION_METHOD

#define ZIP_DIRENT_ENCRYPTION_METHOD   0x0040u

Definition at line 322 of file zipint.h.

◆ ZIP_DIRENT_EXTRA_FIELD

#define ZIP_DIRENT_EXTRA_FIELD   0x0008u

Definition at line 319 of file zipint.h.

◆ ZIP_DIRENT_FILENAME

#define ZIP_DIRENT_FILENAME   0x0002u

Definition at line 317 of file zipint.h.

◆ ZIP_DIRENT_LAST_MOD

#define ZIP_DIRENT_LAST_MOD   0x0020u

Definition at line 321 of file zipint.h.

◆ ZIP_DIRENT_PASSWORD

#define ZIP_DIRENT_PASSWORD   0x0080u

Definition at line 323 of file zipint.h.

◆ ZIP_EF_BOTH

#define ZIP_EF_BOTH   (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */

Definition at line 245 of file zipint.h.

◆ ZIP_EF_CENTRAL

#define ZIP_EF_CENTRAL   ZIP_FL_CENTRAL /* include in central directory */

Definition at line 244 of file zipint.h.

◆ ZIP_EF_IS_INTERNAL

#define ZIP_EF_IS_INTERNAL (   id)    ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)

Definition at line 90 of file zipint.h.

◆ ZIP_EF_LOCAL

#define ZIP_EF_LOCAL   ZIP_FL_LOCAL /* include in local header */

Definition at line 243 of file zipint.h.

◆ ZIP_EF_UTF_8_COMMENT

#define ZIP_EF_UTF_8_COMMENT   0x6375

Definition at line 85 of file zipint.h.

◆ ZIP_EF_UTF_8_NAME

#define ZIP_EF_UTF_8_NAME   0x7075

Definition at line 86 of file zipint.h.

◆ ZIP_EF_WINZIP_AES

#define ZIP_EF_WINZIP_AES   0x9901

Definition at line 87 of file zipint.h.

◆ ZIP_EF_ZIP64

#define ZIP_EF_ZIP64   0x0001

Definition at line 88 of file zipint.h.

◆ ZIP_ENTRY_CHANGED

#define ZIP_ENTRY_CHANGED (   e,
  f 
)    ((e)->changes && ((e)->changes->changed & (f)))

Definition at line 475 of file zipint.h.

◆ ZIP_ENTRY_DATA_CHANGED

#define ZIP_ENTRY_DATA_CHANGED (   x)    ((x)->source != NULL)

Definition at line 476 of file zipint.h.

◆ ZIP_ENTRY_HAS_CHANGES

#define ZIP_ENTRY_HAS_CHANGES (   e)    (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))

Definition at line 477 of file zipint.h.

◆ ZIP_ER_DETAIL_CDIR_ENTRY_INVALID

#define ZIP_ER_DETAIL_CDIR_ENTRY_INVALID   4 /* E central header invalid */

Definition at line 217 of file zipint.h.

◆ ZIP_ER_DETAIL_CDIR_INVALID

#define ZIP_ER_DETAIL_CDIR_INVALID   11 /* G invalid value in central directory */

Definition at line 224 of file zipint.h.

◆ ZIP_ER_DETAIL_CDIR_LENGTH_INVALID

#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID   3 /* G central directory length invalid */

Definition at line 216 of file zipint.h.

◆ ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD

#define ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD   1 /* G central directory overlaps EOCD, or there is space between them */

Definition at line 214 of file zipint.h.

◆ ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT

#define ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT   5 /* G central directory count of entries is incorrect */

Definition at line 218 of file zipint.h.

◆ ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID

#define ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID   2 /* G archive comment length incorrect */

Definition at line 215 of file zipint.h.

◆ ZIP_ER_DETAIL_EF_TRAILING_GARBAGE

#define ZIP_ER_DETAIL_EF_TRAILING_GARBAGE   15 /* E garbage at end of extra fields */

Definition at line 230 of file zipint.h.

◆ ZIP_ER_DETAIL_ENTRY_HEADER_MISMATCH

#define ZIP_ER_DETAIL_ENTRY_HEADER_MISMATCH   6 /* E local and central headers do not match */

Definition at line 219 of file zipint.h.

◆ ZIP_ER_DETAIL_EOCD64_MISMATCH

#define ZIP_ER_DETAIL_EOCD64_MISMATCH   10 /* G EOCD64 and EOCD do not match */

Definition at line 223 of file zipint.h.

◆ ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD

#define ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD   8 /* G EOCD64 overlaps EOCD, or there is space between them */

Definition at line 221 of file zipint.h.

◆ ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC

#define ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC   9 /* G EOCD64 magic incorrect */

Definition at line 222 of file zipint.h.

◆ ZIP_ER_DETAIL_EOCD_LENGTH_INVALID

#define ZIP_ER_DETAIL_EOCD_LENGTH_INVALID   7 /* G wrong EOCD length */

Definition at line 220 of file zipint.h.

◆ ZIP_ER_DETAIL_INVALID_EF_LENGTH

#define ZIP_ER_DETAIL_INVALID_EF_LENGTH   16 /* E extra field length is invalid */

Definition at line 231 of file zipint.h.

◆ ZIP_ER_DETAIL_INVALID_FILE_LENGTH

#define ZIP_ER_DETAIL_INVALID_FILE_LENGTH   17 /* E file length in header doesn't match actual file length */

Definition at line 232 of file zipint.h.

◆ ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT

#define ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT   13 /* E invalid UTF-8 in comment */

Definition at line 227 of file zipint.h.

◆ ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME

#define ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME   13 /* E invalid UTF-8 in filename */

Definition at line 226 of file zipint.h.

◆ ZIP_ER_DETAIL_INVALID_WINZIPAES_EF

#define ZIP_ER_DETAIL_INVALID_WINZIPAES_EF   14 /* E invalid WinZip AES extra field */

Definition at line 229 of file zipint.h.

◆ ZIP_ER_DETAIL_INVALID_ZIP64_EF

#define ZIP_ER_DETAIL_INVALID_ZIP64_EF   14 /* E invalid Zip64 extra field */

Definition at line 228 of file zipint.h.

◆ ZIP_ER_DETAIL_NO_DETAIL

#define ZIP_ER_DETAIL_NO_DETAIL   0 /* G no detail */

Definition at line 213 of file zipint.h.

◆ ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW

#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW   12 /* E variable size fields overflow header */

Definition at line 225 of file zipint.h.

◆ ZIP_EXT_ATTRIB_DEFAULT

#define ZIP_EXT_ATTRIB_DEFAULT   (0100666u << 16)

Definition at line 93 of file zipint.h.

◆ ZIP_EXT_ATTRIB_DEFAULT_DIR

#define ZIP_EXT_ATTRIB_DEFAULT_DIR   (0040777u << 16)

Definition at line 95 of file zipint.h.

◆ ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK

#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK   0x0836

Definition at line 97 of file zipint.h.

◆ ZIP_FL_ENCODING_ALL

#define ZIP_FL_ENCODING_ALL   (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)

Definition at line 249 of file zipint.h.

◆ ZIP_FL_FORCE_ZIP64

#define ZIP_FL_FORCE_ZIP64   1024 /* force zip64 extra field (_zip_dirent_write) */

Definition at line 247 of file zipint.h.

◆ ZIP_GPBF_DATA_DESCRIPTOR

#define ZIP_GPBF_DATA_DESCRIPTOR   0x0008u /* crc/size after file data */

Definition at line 237 of file zipint.h.

◆ ZIP_GPBF_ENCODING_UTF_8

#define ZIP_GPBF_ENCODING_UTF_8   0x0800u /* file name encoding is UTF-8 */

Definition at line 239 of file zipint.h.

◆ ZIP_GPBF_ENCRYPTED

#define ZIP_GPBF_ENCRYPTED   0x0001u /* is encrypted */

Definition at line 236 of file zipint.h.

◆ ZIP_GPBF_STRONG_ENCRYPTION

#define ZIP_GPBF_STRONG_ENCRYPTION   0x0040u /* uses strong encryption */

Definition at line 238 of file zipint.h.

◆ ZIP_IS_RDONLY

#define ZIP_IS_RDONLY (   za)    ((za)->ch_flags & ZIP_AFL_RDONLY)

Definition at line 479 of file zipint.h.

◆ ZIP_MAX [1/2]

#define ZIP_MAX (   a,
  b 
)    ((a) > (b) ? (a) : (b))

Definition at line 472 of file zipint.h.

◆ ZIP_MAX [2/2]

#define ZIP_MAX (   a,
  b 
)    ((a) > (b) ? (a) : (b))

Definition at line 472 of file zipint.h.

◆ ZIP_MIN [1/2]

#define ZIP_MIN (   a,
  b 
)    ((a) < (b) ? (a) : (b))

Definition at line 473 of file zipint.h.

◆ ZIP_MIN [2/2]

#define ZIP_MIN (   a,
  b 
)    ((a) < (b) ? (a) : (b))

Definition at line 473 of file zipint.h.

◆ ZIP_SOURCE_IS_LAYERED

#define ZIP_SOURCE_IS_LAYERED (   src)    ((src)->src != NULL)

Definition at line 404 of file zipint.h.

◆ ZIP_SOURCE_IS_OPEN_READING

#define ZIP_SOURCE_IS_OPEN_READING (   src)    ((src)->open_count > 0)

Definition at line 402 of file zipint.h.

◆ ZIP_SOURCE_IS_OPEN_WRITING

#define ZIP_SOURCE_IS_OPEN_WRITING (   src)    ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)

Definition at line 403 of file zipint.h.

Typedef Documentation

◆ zip_buffer_t

typedef struct zip_buffer zip_buffer_t

Definition at line 203 of file zipint.h.

◆ zip_cdir_t

typedef struct zip_cdir zip_cdir_t

Definition at line 203 of file zipint.h.

◆ zip_compression_algorithm_t

Definition at line 112 of file zipint.h.

◆ zip_compression_status_t

Definition at line 112 of file zipint.h.

◆ zip_dirent_t

typedef struct zip_dirent zip_dirent_t

Definition at line 203 of file zipint.h.

◆ zip_encoding_type_t

Definition at line 203 of file zipint.h.

◆ zip_encryption_implementation

typedef zip_source_t*(* zip_encryption_implementation) (zip_t *, zip_source_t *, zip_uint16_t, int, const char *)

Definition at line 110 of file zipint.h.

◆ zip_entry_t

typedef struct zip_entry zip_entry_t

Definition at line 203 of file zipint.h.

◆ zip_extra_field_t

Definition at line 203 of file zipint.h.

◆ zip_filelist_t

typedef struct zip_filelist zip_filelist_t

Definition at line 203 of file zipint.h.

◆ zip_hash_t

typedef struct zip_hash zip_hash_t

Definition at line 203 of file zipint.h.

◆ zip_pkware_keys_t

Definition at line 203 of file zipint.h.

◆ zip_progress_t

typedef struct zip_progress zip_progress_t

Definition at line 203 of file zipint.h.

◆ zip_source_layered_callback

typedef zip_int64_t(* zip_source_layered_callback) (zip_source_t *, void *, void *, zip_uint64_t, enum zip_source_cmd)

Definition at line 173 of file zipint.h.

◆ zip_source_write_state_t

Definition at line 203 of file zipint.h.

◆ zip_string_t

typedef struct zip_string zip_string_t

Definition at line 203 of file zipint.h.

◆ zip_winzip_aes_t

Definition at line 203 of file zipint.h.

Enumeration Type Documentation

◆ zip_compression_status

Enumerator
ZIP_COMPRESSION_OK 
ZIP_COMPRESSION_END 
ZIP_COMPRESSION_ERROR 
ZIP_COMPRESSION_NEED_DATA 

Definition at line 115 of file zipint.h.

115  {
120 };
@ ZIP_COMPRESSION_NEED_DATA
Definition: zipint.h:119
@ ZIP_COMPRESSION_ERROR
Definition: zipint.h:118
@ ZIP_COMPRESSION_END
Definition: zipint.h:117
@ ZIP_COMPRESSION_OK
Definition: zipint.h:116

◆ zip_encoding_type

Enumerator
ZIP_ENCODING_UNKNOWN 
ZIP_ENCODING_ASCII 
ZIP_ENCODING_UTF8_KNOWN 
ZIP_ENCODING_UTF8_GUESSED 
ZIP_ENCODING_CP437 
ZIP_ENCODING_ERROR 

Definition at line 253 of file zipint.h.

253  {
254  ZIP_ENCODING_UNKNOWN, /* not yet analyzed */
255  ZIP_ENCODING_ASCII, /* plain ASCII */
256  ZIP_ENCODING_UTF8_KNOWN, /* is UTF-8 */
257  ZIP_ENCODING_UTF8_GUESSED, /* possibly UTF-8 */
258  ZIP_ENCODING_CP437, /* Code Page 437 */
259  ZIP_ENCODING_ERROR /* should be UTF-8 but isn't */
260 };
@ ZIP_ENCODING_ERROR
Definition: zipint.h:259
@ ZIP_ENCODING_UTF8_GUESSED
Definition: zipint.h:257
@ ZIP_ENCODING_UTF8_KNOWN
Definition: zipint.h:256
@ ZIP_ENCODING_UNKNOWN
Definition: zipint.h:254
@ ZIP_ENCODING_CP437
Definition: zipint.h:258
@ ZIP_ENCODING_ASCII
Definition: zipint.h:255

◆ zip_les

enum zip_les
Enumerator
ZIP_LES_NONE 
ZIP_LES_UPPER 
ZIP_LES_LOWER 
ZIP_LES_INVAL 

Definition at line 190 of file zipint.h.

@ ZIP_LES_NONE
Definition: zipint.h:190
@ ZIP_LES_INVAL
Definition: zipint.h:190
@ ZIP_LES_UPPER
Definition: zipint.h:190
@ ZIP_LES_LOWER
Definition: zipint.h:190

◆ zip_source_write_state

Enumerator
ZIP_SOURCE_WRITE_CLOSED 
ZIP_SOURCE_WRITE_OPEN 
ZIP_SOURCE_WRITE_FAILED 
ZIP_SOURCE_WRITE_REMOVED 

Definition at line 375 of file zipint.h.

375  {
376  ZIP_SOURCE_WRITE_CLOSED, /* write is not in progress */
377  ZIP_SOURCE_WRITE_OPEN, /* write is in progress */
378  ZIP_SOURCE_WRITE_FAILED, /* commit failed, only rollback allowed */
379  ZIP_SOURCE_WRITE_REMOVED /* file was removed */
380 };
@ ZIP_SOURCE_WRITE_CLOSED
Definition: zipint.h:376
@ ZIP_SOURCE_WRITE_OPEN
Definition: zipint.h:377
@ ZIP_SOURCE_WRITE_FAILED
Definition: zipint.h:378
@ ZIP_SOURCE_WRITE_REMOVED
Definition: zipint.h:379

Function Documentation

◆ _zip_add_entry()

zip_int64_t _zip_add_entry ( zip_t za)

Definition at line 43 of file zip_add_entry.c.

43  {
45 
46  if (za->nentry + 1 >= za->nentry_alloc) {
47  zip_entry_t *rentries;
48  zip_uint64_t nalloc = za->nentry_alloc;
49  zip_uint64_t additional_entries = 2 * nalloc;
50  zip_uint64_t realloc_size;
51 
52  if (additional_entries < 16) {
53  additional_entries = 16;
54  }
55  else if (additional_entries > 1024) {
56  additional_entries = 1024;
57  }
58  /* neither + nor * overflows can happen: nentry_alloc * sizeof(struct zip_entry) < UINT64_MAX */
59  nalloc += additional_entries;
60  realloc_size = sizeof(struct zip_entry) * (size_t)nalloc;
61 
62  if (sizeof(struct zip_entry) * (size_t)za->nentry_alloc > realloc_size) {
64  return -1;
65  }
66  rentries = (zip_entry_t *)realloc(za->entry, sizeof(struct zip_entry) * (size_t)nalloc);
67  if (!rentries) {
69  return -1;
70  }
71  za->entry = rentries;
72  za->nentry_alloc = nalloc;
73  }
74 
75  idx = za->nentry++;
76 
78 
79  return (zip_int64_t)idx;
80 }
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_ER_MEMORY
Definition: zip.h:119
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
int idx
Definition: setup.py:197
int size_t
Definition: sftypes.h:40
Definition: zipint.h:408
zip_error_t error
Definition: zipint.h:281
zip_entry_t * entry
Definition: zipint.h:294
zip_uint64_t nentry_alloc
Definition: zipint.h:293
zip_uint64_t nentry
Definition: zipint.h:292
void _zip_entry_init(zip_entry_t *e)
Definition: zip_entry.c:46
uint64_t zip_uint64_t
Definition: zipconf.h:39
int64_t zip_int64_t
Definition: zipconf.h:38
zip_t * za
Definition: ziptool.c:79

References _zip_entry_init(), zip::entry, zip::error, setup::idx, zip::nentry, zip::nentry_alloc, realloc(), za, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_file_replace().

◆ _zip_buffer_data()

zip_uint8_t* _zip_buffer_data ( zip_buffer_t buffer)

Definition at line 40 of file zip_buffer.c.

40  {
41  return buffer->data;
42 }
Definition: buffer.h:15

Referenced by _zip_cdir_write(), _zip_ef_utf8(), _zip_find_central_dir(), _zip_read_cdir(), encrypt_header(), and write_data_descriptor().

◆ _zip_buffer_eof()

bool _zip_buffer_eof ( zip_buffer_t buffer)

Definition at line 60 of file zip_buffer.c.

60  {
61  return buffer->ok && buffer->offset == buffer->size;
62 }
zip_uint64_t offset
zip_uint64_t size

References buffer::offset, and buffer::size.

Referenced by _zip_dirent_read(), _zip_dirent_size(), _zip_ef_parse(), _zip_read_cdir(), _zip_read_local_ef(), pkware_encrypt(), and winzip_aes_encrypt().

◆ _zip_buffer_free()

void _zip_buffer_free ( zip_buffer_t buffer)

◆ _zip_buffer_get()

zip_uint8_t* _zip_buffer_get ( zip_buffer_t buffer,
zip_uint64_t  length 
)

Definition at line 66 of file zip_buffer.c.

66  {
67  zip_uint8_t *data;
68 
70 
71  if (data != NULL) {
72  buffer->offset += length;
73  }
74 
75  return data;
76 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
zip_uint8_t * _zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length)
Definition: zip_buffer.c:204
uint8_t zip_uint8_t
Definition: zipconf.h:33

References _zip_buffer_peek(), length, NULL, and buffer::offset.

Referenced by _zip_buffer_get_16(), _zip_buffer_get_32(), _zip_buffer_get_64(), _zip_buffer_get_8(), _zip_buffer_put(), _zip_buffer_put_16(), _zip_buffer_put_32(), _zip_buffer_put_64(), _zip_buffer_put_8(), _zip_buffer_read(), _zip_dirent_process_ef_utf_8(), _zip_dirent_process_winzip_aes(), _zip_dirent_read(), _zip_ef_parse(), _zip_find_central_dir(), _zip_read_cdir(), _zip_read_data(), _zip_read_eocd(), and _zip_read_eocd64().

◆ _zip_buffer_get_16()

zip_uint16_t _zip_buffer_get_16 ( zip_buffer_t buffer)

Definition at line 80 of file zip_buffer.c.

80  {
82 
83  if (data == NULL) {
84  return 0;
85  }
86 
87  return (zip_uint16_t)(data[0] + (data[1] << 8));
88 }
zip_uint8_t * _zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length)
Definition: zip_buffer.c:66
uint16_t zip_uint16_t
Definition: zipconf.h:35

References _zip_buffer_get(), and NULL.

Referenced by _zip_dirent_process_winzip_aes(), _zip_dirent_read(), _zip_dirent_size(), _zip_ef_parse(), _zip_read_cdir(), _zip_read_eocd(), _zip_read_eocd64(), and _zip_read_local_ef().

◆ _zip_buffer_get_32()

zip_uint32_t _zip_buffer_get_32 ( zip_buffer_t buffer)

Definition at line 92 of file zip_buffer.c.

92  {
94 
95  if (data == NULL) {
96  return 0;
97  }
98 
99  return ((((((zip_uint32_t)data[3] << 8) + data[2]) << 8) + data[1]) << 8) + data[0];
100 }
uint32_t zip_uint32_t
Definition: zipconf.h:37

References _zip_buffer_get(), and NULL.

Referenced by _zip_dirent_process_ef_utf_8(), _zip_dirent_read(), _zip_read_eocd(), and _zip_read_eocd64().

◆ _zip_buffer_get_64()

zip_uint64_t _zip_buffer_get_64 ( zip_buffer_t buffer)

Definition at line 104 of file zip_buffer.c.

104  {
105  zip_uint8_t *data = _zip_buffer_get(buffer, 8);
106 
107  if (data == NULL) {
108  return 0;
109  }
110 
111  return ((zip_uint64_t)data[7] << 56) + ((zip_uint64_t)data[6] << 48) + ((zip_uint64_t)data[5] << 40) + ((zip_uint64_t)data[4] << 32) + ((zip_uint64_t)data[3] << 24) + ((zip_uint64_t)data[2] << 16) + ((zip_uint64_t)data[1] << 8) + (zip_uint64_t)data[0];
112 }

References _zip_buffer_get(), and NULL.

Referenced by _zip_dirent_read(), and _zip_read_eocd64().

◆ _zip_buffer_get_8()

zip_uint8_t _zip_buffer_get_8 ( zip_buffer_t buffer)

Definition at line 116 of file zip_buffer.c.

116  {
117  zip_uint8_t *data = _zip_buffer_get(buffer, 1);
118 
119  if (data == NULL) {
120  return 0;
121  }
122 
123  return data[0];
124 }

References _zip_buffer_get(), and NULL.

Referenced by _zip_dirent_process_ef_utf_8(), and _zip_dirent_process_winzip_aes().

◆ _zip_buffer_left()

zip_uint64_t _zip_buffer_left ( zip_buffer_t buffer)

◆ _zip_buffer_new()

zip_buffer_t* _zip_buffer_new ( zip_uint8_t data,
zip_uint64_t  size 
)

Definition at line 146 of file zip_buffer.c.

146  {
147  bool free_data = (data == NULL);
149 
150  if (data == NULL) {
151  if ((data = (zip_uint8_t *)malloc(size)) == NULL) {
152  return NULL;
153  }
154  }
155 
156  if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) {
157  if (free_data) {
158  free(data);
159  }
160  return NULL;
161  }
162 
163  buffer->ok = true;
164  buffer->data = data;
165  buffer->size = size;
166  buffer->offset = 0;
167  buffer->free_data = free_data;
168 
169  return buffer;
170 }
struct buffer buffer
voidpf void uLong size
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123

References free(), malloc(), NULL, buffer::offset, and buffer::size.

Referenced by _zip_buffer_new_from_source(), _zip_cdir_write(), _zip_dirent_process_ef_utf_8(), _zip_dirent_process_winzip_aes(), _zip_dirent_read(), _zip_dirent_write(), _zip_ef_parse(), _zip_ef_utf8(), _zip_ef_write(), _zip_read_cdir(), encrypt_header(), input(), winzip_aes_encrypt(), and write_data_descriptor().

◆ _zip_buffer_new_from_source()

zip_buffer_t* _zip_buffer_new_from_source ( zip_source_t src,
zip_uint64_t  size,
zip_uint8_t buf,
zip_error_t error 
)

Definition at line 174 of file zip_buffer.c.

174  {
176 
177  if ((buffer = _zip_buffer_new(buf, size)) == NULL) {
179  return NULL;
180  }
181 
182  if (_zip_read(src, buffer->data, size, error) < 0) {
184  return NULL;
185  }
186 
187  return buffer;
188 }
lzma_index * src
Definition: index.h:567
voidpf void * buf
Definition: ioapi.h:138
void error(const char *msg)
Definition: untgz.c:593
zip_buffer_t * _zip_buffer_new(zip_uint8_t *data, zip_uint64_t size)
Definition: zip_buffer.c:146
void _zip_buffer_free(zip_buffer_t *buffer)
Definition: zip_buffer.c:46
int _zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error)
Definition: zip_io_util.c:40

References _zip_buffer_free(), _zip_buffer_new(), _zip_read(), error(), NULL, src, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_dirent_read(), _zip_dirent_size(), _zip_find_central_dir(), _zip_read_eocd64(), and _zip_read_local_ef().

◆ _zip_buffer_offset()

zip_uint64_t _zip_buffer_offset ( zip_buffer_t buffer)

Definition at line 192 of file zip_buffer.c.

192  {
193  return buffer->ok ? buffer->offset : 0;
194 }

References buffer::offset.

Referenced by _zip_cdir_write(), _zip_dirent_write(), _zip_ef_utf8(), _zip_read_cdir(), _zip_read_eocd(), _zip_read_eocd64(), and write_data_descriptor().

◆ _zip_buffer_ok()

bool _zip_buffer_ok ( zip_buffer_t buffer)

◆ _zip_buffer_peek()

zip_uint8_t* _zip_buffer_peek ( zip_buffer_t buffer,
zip_uint64_t  length 
)

Definition at line 204 of file zip_buffer.c.

204  {
205  zip_uint8_t *data;
206 
207  if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) {
208  buffer->ok = false;
209  return NULL;
210  }
211 
212  data = buffer->data + buffer->offset;
213  return data;
214 }
voidpf uLong offset
Definition: ioapi.h:144

References length, NULL, buffer::offset, and buffer::size.

Referenced by _zip_buffer_get().

◆ _zip_buffer_put()

int _zip_buffer_put ( zip_buffer_t buffer,
const void *  src,
size_t  length 
)

Definition at line 217 of file zip_buffer.c.

217  {
219 
220  if (dst == NULL) {
221  return -1;
222  }
223 
224  memcpy(dst, src, length);
225  return 0;
226 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
char * dst
Definition: lz4.h:724

References _zip_buffer_get(), dst, length, memcpy(), NULL, and src.

Referenced by _zip_cdir_write(), _zip_dirent_write(), _zip_ef_utf8(), and write_data_descriptor().

◆ _zip_buffer_put_16()

int _zip_buffer_put_16 ( zip_buffer_t buffer,
zip_uint16_t  i 
)

Definition at line 230 of file zip_buffer.c.

230  {
231  zip_uint8_t *data = _zip_buffer_get(buffer, 2);
232 
233  if (data == NULL) {
234  return -1;
235  }
236 
237  data[0] = (zip_uint8_t)(i & 0xff);
238  data[1] = (zip_uint8_t)((i >> 8) & 0xff);
239 
240  return 0;
241 }
lzma_index ** i
Definition: index.h:629

References _zip_buffer_get(), i, and NULL.

Referenced by _zip_cdir_write(), _zip_dirent_write(), and _zip_ef_write().

◆ _zip_buffer_put_32()

int _zip_buffer_put_32 ( zip_buffer_t buffer,
zip_uint32_t  i 
)

Definition at line 245 of file zip_buffer.c.

245  {
246  zip_uint8_t *data = _zip_buffer_get(buffer, 4);
247 
248  if (data == NULL) {
249  return -1;
250  }
251 
252  data[0] = (zip_uint8_t)(i & 0xff);
253  data[1] = (zip_uint8_t)((i >> 8) & 0xff);
254  data[2] = (zip_uint8_t)((i >> 16) & 0xff);
255  data[3] = (zip_uint8_t)((i >> 24) & 0xff);
256 
257  return 0;
258 }

References _zip_buffer_get(), i, and NULL.

Referenced by _zip_cdir_write(), _zip_dirent_write(), _zip_ef_utf8(), and write_data_descriptor().

◆ _zip_buffer_put_64()

int _zip_buffer_put_64 ( zip_buffer_t buffer,
zip_uint64_t  i 
)

Definition at line 262 of file zip_buffer.c.

262  {
263  zip_uint8_t *data = _zip_buffer_get(buffer, 8);
264 
265  if (data == NULL) {
266  return -1;
267  }
268 
269  data[0] = (zip_uint8_t)(i & 0xff);
270  data[1] = (zip_uint8_t)((i >> 8) & 0xff);
271  data[2] = (zip_uint8_t)((i >> 16) & 0xff);
272  data[3] = (zip_uint8_t)((i >> 24) & 0xff);
273  data[4] = (zip_uint8_t)((i >> 32) & 0xff);
274  data[5] = (zip_uint8_t)((i >> 40) & 0xff);
275  data[6] = (zip_uint8_t)((i >> 48) & 0xff);
276  data[7] = (zip_uint8_t)((i >> 56) & 0xff);
277 
278  return 0;
279 }

References _zip_buffer_get(), i, and NULL.

Referenced by _zip_cdir_write(), _zip_dirent_write(), input(), and write_data_descriptor().

◆ _zip_buffer_put_8()

int _zip_buffer_put_8 ( zip_buffer_t buffer,
zip_uint8_t  i 
)

Definition at line 283 of file zip_buffer.c.

283  {
284  zip_uint8_t *data = _zip_buffer_get(buffer, 1);
285 
286  if (data == NULL) {
287  return -1;
288  }
289 
290  data[0] = i;
291 
292  return 0;
293 }

References _zip_buffer_get(), i, and NULL.

Referenced by _zip_dirent_write(), and _zip_ef_utf8().

◆ _zip_buffer_read()

zip_uint64_t _zip_buffer_read ( zip_buffer_t buffer,
zip_uint8_t data,
zip_uint64_t  length 
)

Definition at line 134 of file zip_buffer.c.

134  {
135  if (_zip_buffer_left(buffer) < length) {
137  }
138 
140 
141  return length;
142 }
zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer)
Definition: zip_buffer.c:128

References _zip_buffer_get(), _zip_buffer_left(), length, and memcpy().

Referenced by pkware_encrypt(), and winzip_aes_encrypt().

◆ _zip_buffer_set_offset()

int _zip_buffer_set_offset ( zip_buffer_t buffer,
zip_uint64_t  offset 
)

Definition at line 297 of file zip_buffer.c.

297  {
298  if (offset > buffer->size) {
299  buffer->ok = false;
300  return -1;
301  }
302 
303  buffer->ok = true;
304  buffer->offset = offset;
305 
306  return 0;
307 }

References buffer::offset, and buffer::size.

Referenced by _zip_buffer_skip(), _zip_dirent_read(), _zip_ef_write(), _zip_find_central_dir(), _zip_read_cdir(), and _zip_read_eocd64().

◆ _zip_buffer_size()

zip_uint64_t _zip_buffer_size ( zip_buffer_t buffer)

Definition at line 322 of file zip_buffer.c.

322  {
323  return buffer->size;
324 }

References buffer::size.

Referenced by _zip_read_eocd64().

◆ _zip_buffer_skip()

int _zip_buffer_skip ( zip_buffer_t buffer,
zip_uint64_t  length 
)

Definition at line 311 of file zip_buffer.c.

311  {
313 
315  buffer->ok = false;
316  return -1;
317  }
319 }
int _zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset)
Definition: zip_buffer.c:297

References _zip_buffer_set_offset(), length, and buffer::offset.

Referenced by _zip_dirent_read().

◆ _zip_cdir_free()

void _zip_cdir_free ( zip_cdir_t cd)

Definition at line 49 of file zip_dirent.c.

49  {
51 
52  if (!cd)
53  return;
54 
55  for (i = 0; i < cd->nentry; i++)
56  _zip_entry_finalize(cd->entry + i);
57  free(cd->entry);
58  _zip_string_free(cd->comment);
59  free(cd);
60 }
static csh cd
Definition: asm_mips_cs.c:10
void _zip_entry_finalize(zip_entry_t *e)
Definition: zip_entry.c:38
void _zip_string_free(zip_string_t *s)
Definition: zip_string.c:69

References _zip_entry_finalize(), _zip_string_free(), cd, free(), and i.

Referenced by _zip_cdir_new(), _zip_find_central_dir(), and _zip_read_cdir().

◆ _zip_cdir_grow()

bool _zip_cdir_grow ( zip_cdir_t cd,
zip_uint64_t  additional_entries,
zip_error_t error 
)

Definition at line 88 of file zip_dirent.c.

88  {
89  zip_uint64_t i, new_alloc;
90  zip_entry_t *new_entry;
91 
92  if (additional_entries == 0) {
93  return true;
94  }
95 
96  new_alloc = cd->nentry_alloc + additional_entries;
97 
98  if (new_alloc < additional_entries || new_alloc > SIZE_MAX / sizeof(*(cd->entry))) {
100  return false;
101  }
102 
103  if ((new_entry = (zip_entry_t *)realloc(cd->entry, sizeof(*(cd->entry)) * (size_t)new_alloc)) == NULL) {
105  return false;
106  }
107 
108  cd->entry = new_entry;
109 
110  for (i = cd->nentry; i < new_alloc; i++) {
111  _zip_entry_init(cd->entry + i);
112  }
113 
114  cd->nentry = cd->nentry_alloc = new_alloc;
115 
116  return true;
117 }
#define SIZE_MAX

References _zip_entry_init(), cd, error(), i, NULL, realloc(), SIZE_MAX, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_cdir_new(), and _zip_read_cdir().

◆ _zip_cdir_new()

zip_cdir_t* _zip_cdir_new ( zip_uint64_t  nentry,
zip_error_t error 
)

Definition at line 64 of file zip_dirent.c.

64  {
65  zip_cdir_t *cd;
66 
67  if ((cd = (zip_cdir_t *)malloc(sizeof(*cd))) == NULL) {
69  return NULL;
70  }
71 
72  cd->entry = NULL;
73  cd->nentry = cd->nentry_alloc = 0;
74  cd->size = cd->offset = 0;
75  cd->comment = NULL;
76  cd->is_zip64 = false;
77 
78  if (!_zip_cdir_grow(cd, nentry, error)) {
80  return NULL;
81  }
82 
83  return cd;
84 }
void _zip_cdir_free(zip_cdir_t *cd)
Definition: zip_dirent.c:49
bool _zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error)
Definition: zip_dirent.c:88

References _zip_cdir_free(), _zip_cdir_grow(), cd, error(), malloc(), NULL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_read_eocd(), and _zip_read_eocd64().

◆ _zip_cdir_write()

zip_int64_t _zip_cdir_write ( zip_t za,
const zip_filelist_t filelist,
zip_uint64_t  survivors 
)

Definition at line 121 of file zip_dirent.c.

121  {
123  zip_string_t *comment;
127  zip_uint64_t i;
128  bool is_zip64;
129  int ret;
130 
131  if ((off = zip_source_tell_write(za->src)) < 0) {
133  return -1;
134  }
136 
137  is_zip64 = false;
138 
139  for (i = 0; i < survivors; i++) {
140  zip_entry_t *entry = za->entry + filelist[i].idx;
141 
142  if ((ret = _zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL)) < 0)
143  return -1;
144  if (ret)
145  is_zip64 = true;
146  }
147 
148  if ((off = zip_source_tell_write(za->src)) < 0) {
150  return -1;
151  }
153 
154  if (offset > ZIP_UINT32_MAX || survivors > ZIP_UINT16_MAX)
155  is_zip64 = true;
156 
157 
158  if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
160  return -1;
161  }
162 
163  if (is_zip64) {
170  _zip_buffer_put_64(buffer, survivors);
171  _zip_buffer_put_64(buffer, survivors);
178  }
179 
182  _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
183  _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
186 
188 
189  _zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0));
190 
191  if (!_zip_buffer_ok(buffer)) {
194  return -1;
195  }
196 
199  return -1;
200  }
201 
203 
204  if (comment) {
205  if (_zip_write(za, comment->raw, comment->length) < 0) {
206  return -1;
207  }
208  }
209 
210  return (zip_int64_t)size;
211 }
#define ZIP_ER_INTERNAL
Definition: zip.h:125
ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *_Nonnull)
#define ZIP_FL_CENTRAL
Definition: zip.h:86
int off
Definition: pal.c:13
Definition: zipcmp.c:77
zip_uint64_t idx
Definition: zipint.h:458
zip_uint8_t * raw
Definition: zipint.h:419
zip_uint16_t length
Definition: zipint.h:420
zip_string_t * comment_changes
Definition: zipint.h:289
zip_source_t * src
Definition: zipint.h:279
zip_string_t * comment_orig
Definition: zipint.h:288
bool comment_changed
Definition: zipint.h:290
zip_uint8_t * _zip_buffer_data(zip_buffer_t *buffer)
Definition: zip_buffer.c:40
int _zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i)
Definition: zip_buffer.c:230
bool _zip_buffer_ok(zip_buffer_t *buffer)
Definition: zip_buffer.c:198
int _zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i)
Definition: zip_buffer.c:262
int _zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i)
Definition: zip_buffer.c:245
zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer)
Definition: zip_buffer.c:192
int _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length)
Definition: zip_buffer.c:217
int _zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags)
Definition: zip_dirent.c:765
void _zip_error_set_from_source(zip_error_t *err, zip_source_t *src)
Definition: zip_error.c:135
int _zip_write(zip_t *za, const void *data, zip_uint64_t length)
Definition: zip_io_util.c:121
#define ZIP_UINT16_MAX
Definition: zipconf.h:47
#define ZIP_UINT32_MAX
Definition: zipconf.h:51
#define EOCD_MAGIC
Definition: zipint.h:53
#define EOCD64LEN
Definition: zipint.h:63
#define EOCDLEN
Definition: zipint.h:61
#define EOCD64_MAGIC
Definition: zipint.h:56
#define EOCD64LOCLEN
Definition: zipint.h:62
#define EOCD64LOC_MAGIC
Definition: zipint.h:55

References _zip_buffer_data(), _zip_buffer_free(), _zip_buffer_new(), _zip_buffer_offset(), _zip_buffer_ok(), _zip_buffer_put(), _zip_buffer_put_16(), _zip_buffer_put_32(), _zip_buffer_put_64(), _zip_dirent_write(), _zip_error_set_from_source(), _zip_write(), zip::comment_changed, zip::comment_changes, zip::comment_orig, zip::entry, EOCD64_MAGIC, EOCD64LEN, EOCD64LOC_MAGIC, EOCD64LOCLEN, EOCD_MAGIC, EOCDLEN, zip::error, i, zip_filelist::idx, zip_string::length, NULL, off, zip_string::raw, zip::src, za, ZIP_ER_INTERNAL, ZIP_ER_MEMORY, zip_error_set(), ZIP_FL_CENTRAL, zip_source_tell_write(), ZIP_UINT16_MAX, and ZIP_UINT32_MAX.

Referenced by write_cdir().

◆ _zip_changed()

int _zip_changed ( const zip_t za,
zip_uint64_t survivorsp 
)

Definition at line 655 of file zip_close.c.

655  {
656  int changed;
657  zip_uint64_t i, survivors;
658 
659  changed = 0;
660  survivors = 0;
661 
662  if (za->comment_changed || za->ch_flags != za->flags) {
663  changed = 1;
664  }
665 
666  for (i = 0; i < za->nentry; i++) {
667  if (ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
668  changed = 1;
669  }
670  if (!za->entry[i].deleted) {
671  survivors++;
672  }
673  }
674 
675  if (survivorsp) {
676  *survivorsp = survivors;
677  }
678 
679  return changed;
680 }
bool deleted
Definition: zipint.h:412
unsigned int flags
Definition: zipint.h:283
unsigned int ch_flags
Definition: zipint.h:284
#define ZIP_ENTRY_HAS_CHANGES(e)
Definition: zipint.h:477

References zip::ch_flags, zip::comment_changed, zip_entry::deleted, zip::entry, zip::flags, i, zip::nentry, za, and ZIP_ENTRY_HAS_CHANGES.

Referenced by zip_close(), and zip_set_archive_flag().

◆ _zip_cp437_to_utf8()

zip_uint8_t* _zip_cp437_to_utf8 ( const zip_uint8_t * const  _cp437buf,
zip_uint32_t  len,
zip_uint32_t utf8_lenp,
zip_error_t error 
)

Definition at line 198 of file zip_utf-8.c.

198  {
199  zip_uint8_t *cp437buf = (zip_uint8_t *)_cp437buf;
200  zip_uint8_t *utf8buf;
202 
203  if (len == 0) {
204  if (utf8_lenp)
205  *utf8_lenp = 0;
206  return NULL;
207  }
208 
209  buflen = 1;
210  for (i = 0; i < len; i++)
212 
213  if ((utf8buf = (zip_uint8_t *)malloc(buflen)) == NULL) {
215  return NULL;
216  }
217 
218  offset = 0;
219  for (i = 0; i < len; i++)
220  offset += _zip_unicode_to_utf8(_cp437_to_unicode[cp437buf[i]], utf8buf + offset);
221 
222  utf8buf[buflen - 1] = 0;
223  if (utf8_lenp)
224  *utf8_lenp = buflen - 1;
225  return utf8buf;
226 }
size_t len
Definition: 6502dis.c:15
ut64 buflen
Definition: core.c:76
static const zip_uint16_t _cp437_to_unicode[256]
Definition: zip_utf-8.c:40
static zip_uint32_t _zip_unicode_to_utf8(zip_uint32_t codepoint, zip_uint8_t *buf)
Definition: zip_utf-8.c:173
static zip_uint32_t _zip_unicode_to_utf8_len(zip_uint32_t codepoint)
Definition: zip_utf-8.c:161

References _cp437_to_unicode, _zip_unicode_to_utf8(), _zip_unicode_to_utf8_len(), buflen, error(), i, len, malloc(), NULL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_string_get().

◆ _zip_d2u_time()

time_t _zip_d2u_time ( zip_uint16_t  dtime,
zip_uint16_t  ddate 
)

Definition at line 1004 of file zip_dirent.c.

1004  {
1005  struct tm tm;
1006 
1007  memset(&tm, 0, sizeof(tm));
1008 
1009  /* let mktime decide if DST is in effect */
1010  tm.tm_isdst = -1;
1011 
1012  tm.tm_year = ((ddate >> 9) & 127) + 1980 - 1900;
1013  tm.tm_mon = ((ddate >> 5) & 15) - 1;
1014  tm.tm_mday = ddate & 31;
1015 
1016  tm.tm_hour = (dtime >> 11) & 31;
1017  tm.tm_min = (dtime >> 5) & 63;
1018  tm.tm_sec = (dtime << 1) & 62;
1019 
1020  return mktime(&tm);
1021 }
return memset(p, 0, total)

References memset().

Referenced by _zip_dirent_read(), and zip_file_set_dostime().

◆ _zip_deregister_source()

void _zip_deregister_source ( zip_t za,
zip_source_t src 
)

Definition at line 306 of file zip_source_window.c.

306  {
307  unsigned int i;
308 
309  for (i = 0; i < za->nopen_source; i++) {
310  if (za->open_source[i] == src) {
312  za->nopen_source--;
313  break;
314  }
315  }
316 }
zip_source_t ** open_source
Definition: zipint.h:298
unsigned int nopen_source
Definition: zipint.h:296

References i, zip::nopen_source, zip::open_source, src, and za.

Referenced by zip_source_free().

◆ _zip_dirent_apply_attributes()

void _zip_dirent_apply_attributes ( zip_dirent_t de,
zip_file_attributes_t attributes,
bool  force_zip64,
zip_uint32_t  changed 
)

Definition at line 1117 of file zip_dirent.c.

1117  {
1119 
1122  de->bitflags = (de->bitflags & ~mask) | (attributes->general_purpose_bit_flags & mask);
1123  }
1124  if (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) {
1125  de->int_attrib = (de->int_attrib & ~0x1) | (attributes->ascii ? 1 : 0);
1126  }
1127  /* manually set attributes are preferred over attributes provided by source */
1128  if ((changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES)) {
1129  de->ext_attrib = attributes->external_file_attributes;
1130  }
1131 
1132  if (de->comp_method == ZIP_CM_LZMA) {
1133  de->version_needed = 63;
1134  }
1136  de->version_needed = 51;
1137  }
1138  else if (de->comp_method == ZIP_CM_BZIP2) {
1139  de->version_needed = 46;
1140  }
1141  else if (force_zip64 || _zip_dirent_needs_zip64(de, 0)) {
1142  de->version_needed = 45;
1143  }
1144  else if (de->comp_method == ZIP_CM_DEFLATE || de->encryption_method == ZIP_EM_TRAD_PKWARE) {
1145  de->version_needed = 20;
1146  }
1147  else if ((length = _zip_string_length(de->filename)) > 0 && de->filename->raw[length - 1] == '/') {
1148  de->version_needed = 20;
1149  }
1150  else {
1151  de->version_needed = 10;
1152  }
1153 
1154  if (attributes->valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED) {
1155  de->version_needed = ZIP_MAX(de->version_needed, attributes->version_needed);
1156  }
1157 
1158  de->version_madeby = 63 | (de->version_madeby & 0xff00);
1159  if ((changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM)) {
1160  de->version_madeby = (de->version_madeby & 0xff) | (zip_uint16_t)(attributes->host_system << 8);
1161  }
1162 }
#define mask()
#define ZIP_FILE_ATTRIBUTES_ASCII
Definition: zip.h:330
#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM
Definition: zip.h:329
#define ZIP_EM_TRAD_PKWARE
Definition: zip.h:178
#define ZIP_EM_AES_256
Definition: zip.h:192
#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES
Definition: zip.h:332
#define ZIP_CM_BZIP2
Definition: zip.h:161
#define ZIP_CM_LZMA
Definition: zip.h:163
#define ZIP_EM_AES_192
Definition: zip.h:191
#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS
Definition: zip.h:333
#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED
Definition: zip.h:331
#define ZIP_CM_DEFLATE
Definition: zip.h:157
#define ZIP_EM_AES_128
Definition: zip.h:190
zip_uint16_t bitflags
Definition: zipint.h:335
zip_uint16_t int_attrib
Definition: zipint.h:345
zip_int32_t comp_method
Definition: zipint.h:336
zip_uint16_t version_needed
Definition: zipint.h:334
zip_uint32_t ext_attrib
Definition: zipint.h:346
zip_uint16_t encryption_method
Definition: zipint.h:350
zip_uint16_t version_madeby
Definition: zipint.h:333
zip_string_t * filename
Definition: zipint.h:341
zip_uint8_t host_system
Definition: zip.h:321
zip_uint16_t general_purpose_bit_mask
Definition: zip.h:326
zip_uint8_t ascii
Definition: zip.h:322
zip_uint16_t general_purpose_bit_flags
Definition: zip.h:325
zip_uint8_t version_needed
Definition: zip.h:323
zip_uint32_t external_file_attributes
Definition: zip.h:324
zip_uint64_t valid
Definition: zip.h:319
bool _zip_dirent_needs_zip64(const zip_dirent_t *de, zip_flags_t flags)
Definition: zip_dirent.c:296
zip_uint16_t _zip_string_length(const zip_string_t *s)
Definition: zip_string.c:112
#define ZIP_DIRENT_ATTRIBUTES
Definition: zipint.h:320
#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK
Definition: zipint.h:97
#define ZIP_MAX(a, b)
Definition: zipint.h:472

References _zip_dirent_needs_zip64(), _zip_string_length(), zip_file_attributes::ascii, zip_dirent::bitflags, zip_dirent::comp_method, zip_dirent::encryption_method, zip_dirent::ext_attrib, zip_file_attributes::external_file_attributes, zip_dirent::filename, zip_file_attributes::general_purpose_bit_flags, zip_file_attributes::general_purpose_bit_mask, zip_file_attributes::host_system, zip_dirent::int_attrib, length, mask, zip_string::raw, zip_file_attributes::valid, zip_dirent::version_madeby, zip_file_attributes::version_needed, zip_dirent::version_needed, ZIP_CM_BZIP2, ZIP_CM_DEFLATE, ZIP_CM_LZMA, ZIP_DIRENT_ATTRIBUTES, ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_EM_TRAD_PKWARE, ZIP_FILE_ATTRIBUTES_ASCII, ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES, ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS, ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK, ZIP_FILE_ATTRIBUTES_HOST_SYSTEM, ZIP_FILE_ATTRIBUTES_VERSION_NEEDED, and ZIP_MAX.

Referenced by add_data().

◆ _zip_dirent_clone()

zip_dirent_t* _zip_dirent_clone ( const zip_dirent_t sde)

Definition at line 215 of file zip_dirent.c.

215  {
216  zip_dirent_t *tde;
217 
218  if ((tde = (zip_dirent_t *)malloc(sizeof(*tde))) == NULL)
219  return NULL;
220 
221  if (sde)
222  memcpy(tde, sde, sizeof(*sde));
223  else
224  _zip_dirent_init(tde);
225 
226  tde->changed = 0;
227  tde->cloned = 1;
228 
229  return tde;
230 }
bool cloned
Definition: zipint.h:329
zip_uint32_t changed
Definition: zipint.h:327
void _zip_dirent_init(zip_dirent_t *de)
Definition: zip_dirent.c:268

References _zip_dirent_init(), zip_dirent::changed, zip_dirent::cloned, malloc(), memcpy(), and NULL.

Referenced by _zip_file_extra_field_prepare_for_change(), _zip_file_replace(), _zip_set_name(), zip_close(), zip_file_set_comment(), zip_file_set_encryption(), zip_file_set_external_attributes(), zip_file_set_mtime(), and zip_set_file_compression().

◆ _zip_dirent_finalize()

void _zip_dirent_finalize ( zip_dirent_t zde)

Definition at line 234 of file zip_dirent.c.

234  {
235  if (!zde->cloned || zde->changed & ZIP_DIRENT_FILENAME) {
237  zde->filename = NULL;
238  }
239  if (!zde->cloned || zde->changed & ZIP_DIRENT_EXTRA_FIELD) {
241  zde->extra_fields = NULL;
242  }
243  if (!zde->cloned || zde->changed & ZIP_DIRENT_COMMENT) {
245  zde->comment = NULL;
246  }
247  if (!zde->cloned || zde->changed & ZIP_DIRENT_PASSWORD) {
248  if (zde->password) {
249  _zip_crypto_clear(zde->password, strlen(zde->password));
250  }
251  free(zde->password);
252  zde->password = NULL;
253  }
254 }
char * password
Definition: zipint.h:351
zip_extra_field_t * extra_fields
Definition: zipint.h:342
zip_string_t * comment
Definition: zipint.h:343
void _zip_ef_free(zip_extra_field_t *ef)
#define ZIP_DIRENT_PASSWORD
Definition: zipint.h:323
#define ZIP_DIRENT_EXTRA_FIELD
Definition: zipint.h:319
#define ZIP_DIRENT_FILENAME
Definition: zipint.h:317
#define _zip_crypto_clear(b, l)
Definition: zipint.h:489
#define ZIP_DIRENT_COMMENT
Definition: zipint.h:318

References _zip_crypto_clear, _zip_ef_free(), _zip_string_free(), zip_dirent::changed, zip_dirent::cloned, zip_dirent::comment, zip_dirent::extra_fields, zip_dirent::filename, free(), NULL, zip_dirent::password, ZIP_DIRENT_COMMENT, ZIP_DIRENT_EXTRA_FIELD, ZIP_DIRENT_FILENAME, and ZIP_DIRENT_PASSWORD.

Referenced by _zip_checkcons(), and _zip_dirent_free().

◆ _zip_dirent_free()

void _zip_dirent_free ( zip_dirent_t zde)

Definition at line 258 of file zip_dirent.c.

258  {
259  if (zde == NULL)
260  return;
261 
263  free(zde);
264 }
void _zip_dirent_finalize(zip_dirent_t *zde)
Definition: zip_dirent.c:234

References _zip_dirent_finalize(), free(), and NULL.

Referenced by _zip_entry_finalize(), _zip_set_name(), _zip_unchange(), _zip_unchange_data(), zip_file_set_comment(), zip_file_set_encryption(), zip_file_set_external_attributes(), and zip_set_file_compression().

◆ _zip_dirent_init()

void _zip_dirent_init ( zip_dirent_t de)

Definition at line 268 of file zip_dirent.c.

268  {
269  de->changed = 0;
270  de->local_extra_fields_read = 0;
271  de->cloned = 0;
272 
273  de->crc_valid = true;
274  de->version_madeby = 63 | (ZIP_OPSYS_DEFAULT << 8);
275  de->version_needed = 10; /* 1.0 */
276  de->bitflags = 0;
278  de->last_mod = 0;
279  de->crc = 0;
280  de->comp_size = 0;
281  de->uncomp_size = 0;
282  de->filename = NULL;
283  de->extra_fields = NULL;
284  de->comment = NULL;
285  de->disk_number = 0;
286  de->int_attrib = 0;
288  de->offset = 0;
289  de->compression_level = 0;
291  de->password = NULL;
292 }
#define ZIP_EM_NONE
Definition: zip.h:177
#define ZIP_CM_DEFAULT
Definition: zip.h:148
#define ZIP_OPSYS_DEFAULT
Definition: zip.h:216
zip_uint32_t disk_number
Definition: zipint.h:344
bool local_extra_fields_read
Definition: zipint.h:328
time_t last_mod
Definition: zipint.h:337
zip_uint64_t uncomp_size
Definition: zipint.h:340
zip_uint32_t crc
Definition: zipint.h:338
zip_uint64_t offset
Definition: zipint.h:347
zip_uint64_t comp_size
Definition: zipint.h:339
bool crc_valid
Definition: zipint.h:331
zip_uint16_t compression_level
Definition: zipint.h:349
#define ZIP_EXT_ATTRIB_DEFAULT
Definition: zipint.h:93

References zip_dirent::bitflags, zip_dirent::changed, zip_dirent::cloned, zip_dirent::comment, zip_dirent::comp_method, zip_dirent::comp_size, zip_dirent::compression_level, zip_dirent::crc, zip_dirent::crc_valid, zip_dirent::disk_number, zip_dirent::encryption_method, zip_dirent::ext_attrib, zip_dirent::extra_fields, zip_dirent::filename, zip_dirent::int_attrib, zip_dirent::last_mod, zip_dirent::local_extra_fields_read, NULL, zip_dirent::offset, zip_dirent::password, zip_dirent::uncomp_size, zip_dirent::version_madeby, zip_dirent::version_needed, ZIP_CM_DEFAULT, ZIP_EM_NONE, ZIP_EXT_ATTRIB_DEFAULT, and ZIP_OPSYS_DEFAULT.

Referenced by _zip_checkcons(), _zip_dirent_clone(), _zip_dirent_new(), and _zip_dirent_read().

◆ _zip_dirent_needs_zip64()

bool _zip_dirent_needs_zip64 ( const zip_dirent_t de,
zip_flags_t  flags 
)

Definition at line 296 of file zip_dirent.c.

296  {
298  return true;
299 
300  return false;
301 }
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References zip_dirent::comp_size, flags, zip_dirent::offset, zip_dirent::uncomp_size, ZIP_FL_CENTRAL, and ZIP_UINT32_MAX.

Referenced by _zip_dirent_apply_attributes(), _zip_dirent_write(), _zip_file_get_end(), and zip_close().

◆ _zip_dirent_new()

zip_dirent_t* _zip_dirent_new ( void  )

Definition at line 305 of file zip_dirent.c.

305  {
306  zip_dirent_t *de;
307 
308  if ((de = (zip_dirent_t *)malloc(sizeof(*de))) == NULL)
309  return NULL;
310 
311  _zip_dirent_init(de);
312  return de;
313 }

References _zip_dirent_init(), malloc(), and NULL.

Referenced by _zip_read_cdir().

◆ _zip_dirent_read()

zip_int64_t _zip_dirent_read ( zip_dirent_t zde,
zip_source_t src,
zip_buffer_t buffer,
bool  local,
zip_error_t error 
)

Definition at line 327 of file zip_dirent.c.

327  {
329  zip_uint16_t dostime, dosdate;
330  zip_uint32_t size, variable_size;
331  zip_uint16_t filename_len, comment_len, ef_len;
332 
333  bool from_buffer = (buffer != NULL);
334 
336 
337  if (buffer) {
338  if (_zip_buffer_left(buffer) < size) {
340  return -1;
341  }
342  }
343  else {
345  return -1;
346  }
347  }
348 
349  if (memcmp(_zip_buffer_get(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
351  if (!from_buffer) {
353  }
354  return -1;
355  }
356 
357  /* convert buffercontents to zip_dirent */
358 
359  _zip_dirent_init(zde);
360  if (!local)
362  else
363  zde->version_madeby = 0;
367 
368  /* convert to time_t */
369  dostime = _zip_buffer_get_16(buffer);
370  dosdate = _zip_buffer_get_16(buffer);
371  zde->last_mod = _zip_d2u_time(dostime, dosdate);
372 
373  zde->crc = _zip_buffer_get_32(buffer);
376 
377  filename_len = _zip_buffer_get_16(buffer);
378  ef_len = _zip_buffer_get_16(buffer);
379 
380  if (local) {
381  comment_len = 0;
382  zde->disk_number = 0;
383  zde->int_attrib = 0;
384  zde->ext_attrib = 0;
385  zde->offset = 0;
386  }
387  else {
388  comment_len = _zip_buffer_get_16(buffer);
393  }
394 
395  if (!_zip_buffer_ok(buffer)) {
397  if (!from_buffer) {
399  }
400  return -1;
401  }
402 
403  if (zde->bitflags & ZIP_GPBF_ENCRYPTED) {
405  /* TODO */
407  }
408  else {
410  }
411  }
412  else {
414  }
415 
416  zde->filename = NULL;
417  zde->extra_fields = NULL;
418  zde->comment = NULL;
419 
420  variable_size = (zip_uint32_t)filename_len + (zip_uint32_t)ef_len + (zip_uint32_t)comment_len;
421 
422  if (from_buffer) {
423  if (_zip_buffer_left(buffer) < variable_size) {
425  return -1;
426  }
427  }
428  else {
430 
431  if ((buffer = _zip_buffer_new_from_source(src, variable_size, NULL, error)) == NULL) {
432  return -1;
433  }
434  }
435 
436  if (filename_len) {
437  zde->filename = _zip_read_string(buffer, src, filename_len, 1, error);
438  if (!zde->filename) {
441  }
442  if (!from_buffer) {
444  }
445  return -1;
446  }
447 
448  if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
451  if (!from_buffer) {
453  }
454  return -1;
455  }
456  }
457  }
458 
459  if (ef_len) {
460  zip_uint8_t *ef = _zip_read_data(buffer, src, ef_len, 0, error);
461 
462  if (ef == NULL) {
463  if (!from_buffer) {
465  }
466  return -1;
467  }
468  if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, &zde->extra_fields, error)) {
469  free(ef);
470  if (!from_buffer) {
472  }
473  return -1;
474  }
475  free(ef);
476  if (local)
477  zde->local_extra_fields_read = 1;
478  }
479 
480  if (comment_len) {
481  zde->comment = _zip_read_string(buffer, src, comment_len, 0, error);
482  if (!zde->comment) {
483  if (!from_buffer) {
485  }
486  return -1;
487  }
488  if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
491  if (!from_buffer) {
493  }
494  return -1;
495  }
496  }
497  }
498 
501 
502  /* Zip64 */
503 
504  if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
505  zip_uint16_t got_len;
506  zip_buffer_t *ef_buffer;
508  /* TODO: if got_len == 0 && !ZIP64_EOCD: no error, 0xffffffff is valid value */
509  if (ef == NULL) {
510  if (!from_buffer) {
512  }
513  return -1;
514  }
515 
516  if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
518  if (!from_buffer) {
520  }
521  return -1;
522  }
523 
524  if (zde->uncomp_size == ZIP_UINT32_MAX) {
525  zde->uncomp_size = _zip_buffer_get_64(ef_buffer);
526  }
527  else if (local) {
528  /* From appnote.txt: This entry in the Local header MUST
529  include BOTH original and compressed file size fields. */
530  (void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
531  }
532  if (zde->comp_size == ZIP_UINT32_MAX) {
533  zde->comp_size = _zip_buffer_get_64(ef_buffer);
534  }
535  if (!local) {
536  if (zde->offset == ZIP_UINT32_MAX) {
537  zde->offset = _zip_buffer_get_64(ef_buffer);
538  }
539  if (zde->disk_number == ZIP_UINT16_MAX) {
540  zde->disk_number = _zip_buffer_get_32(ef_buffer);
541  }
542  }
543 
544  if (!_zip_buffer_eof(ef_buffer)) {
545  /* accept additional fields if values match */
546  bool ok = true;
547  switch (got_len) {
548  case 28:
549  _zip_buffer_set_offset(ef_buffer, 24);
550  if (zde->disk_number != _zip_buffer_get_32(ef_buffer)) {
551  ok = false;
552  }
553  /* fallthrough */
554  case 24:
555  _zip_buffer_set_offset(ef_buffer, 0);
556  if ((zde->uncomp_size != _zip_buffer_get_64(ef_buffer)) || (zde->comp_size != _zip_buffer_get_64(ef_buffer)) || (zde->offset != _zip_buffer_get_64(ef_buffer))) {
557  ok = false;
558  }
559  break;
560 
561  default:
562  ok = false;
563  }
564  if (!ok) {
566  _zip_buffer_free(ef_buffer);
567  if (!from_buffer) {
569  }
570  return -1;
571  }
572  }
573  _zip_buffer_free(ef_buffer);
574  }
575 
576  if (!_zip_buffer_ok(buffer)) {
578  if (!from_buffer) {
580  }
581  return -1;
582  }
583  if (!from_buffer) {
585  }
586 
587  /* zip_source_seek / zip_source_tell don't support values > ZIP_INT64_MAX */
588  if (zde->offset > ZIP_INT64_MAX) {
590  return -1;
591  }
592 
594  return -1;
595  }
596 
598 
599  return (zip_int64_t)size + (zip_int64_t)variable_size;
600 }
#define local
Definition: blast.c:36
#define ZIP_ER_SEEK
Definition: zip.h:109
#define ZIP_EM_UNKNOWN
Definition: zip.h:193
ZIP_EXTERN int zip_error_code_zip(const zip_error_t *_Nonnull)
Definition: zip_error.c:46
#define ZIP_ER_EOF
Definition: zip.h:122
#define ZIP_ER_NOZIP
Definition: zip.h:124
#define ZIP_ER_INCONS
Definition: zip.h:126
@ ok
Definition: lz4.c:1706
#define EFBIG
Definition: sftypes.h:137
Definition: zipcmp.c:69
zip_uint32_t _zip_buffer_get_32(zip_buffer_t *buffer)
Definition: zip_buffer.c:92
zip_buffer_t * _zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error)
Definition: zip_buffer.c:174
zip_uint16_t _zip_buffer_get_16(zip_buffer_t *buffer)
Definition: zip_buffer.c:80
int _zip_buffer_skip(zip_buffer_t *buffer, zip_uint64_t length)
Definition: zip_buffer.c:311
bool _zip_buffer_eof(zip_buffer_t *buffer)
Definition: zip_buffer.c:60
zip_uint64_t _zip_buffer_get_64(zip_buffer_t *buffer)
Definition: zip_buffer.c:104
static bool _zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error)
Definition: zip_dirent.c:639
static zip_string_t * _zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str)
Definition: zip_dirent.c:604
time_t _zip_d2u_time(zip_uint16_t dtime, zip_uint16_t ddate)
Definition: zip_dirent.c:1004
bool _zip_ef_parse(const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags, zip_extra_field_t **ef_head_p, zip_error_t *error)
zip_extra_field_t * _zip_ef_remove_internal(zip_extra_field_t *ef)
const zip_uint8_t * _zip_ef_get_by_id(const zip_extra_field_t *ef, zip_uint16_t *lenp, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags, zip_error_t *error)
zip_uint8_t * _zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error)
Definition: zip_io_util.c:63
zip_string_t * _zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t len, bool nulp, zip_error_t *error)
Definition: zip_io_util.c:107
zip_encoding_type_t _zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding)
Definition: zip_utf-8.c:100
#define ZIP_INT64_MAX
Definition: zipconf.h:54
#define LENTRYSIZE
Definition: zipint.h:58
#define ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT
Definition: zipint.h:227
#define ZIP_EF_CENTRAL
Definition: zipint.h:244
#define CDENTRYSIZE
Definition: zipint.h:57
#define CENTRAL_MAGIC
Definition: zipint.h:51
#define ZIP_EF_LOCAL
Definition: zipint.h:243
#define ZIP_ER_DETAIL_INVALID_ZIP64_EF
Definition: zipint.h:228
#define ZIP_EF_UTF_8_NAME
Definition: zipint.h:86
#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW
Definition: zipint.h:225
#define ZIP_GPBF_ENCODING_UTF_8
Definition: zipint.h:239
#define ZIP_GPBF_STRONG_ENCRYPTION
Definition: zipint.h:238
#define ZIP_EF_ZIP64
Definition: zipint.h:88
#define ZIP_EF_UTF_8_COMMENT
Definition: zipint.h:85
#define ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME
Definition: zipint.h:226
#define LOCAL_MAGIC
Definition: zipint.h:52
#define ZIP_GPBF_ENCRYPTED
Definition: zipint.h:236

References _zip_buffer_eof(), _zip_buffer_free(), _zip_buffer_get(), _zip_buffer_get_16(), _zip_buffer_get_32(), _zip_buffer_get_64(), _zip_buffer_left(), _zip_buffer_new(), _zip_buffer_new_from_source(), _zip_buffer_ok(), _zip_buffer_set_offset(), _zip_buffer_skip(), _zip_d2u_time(), _zip_dirent_init(), _zip_dirent_process_ef_utf_8(), _zip_dirent_process_winzip_aes(), _zip_ef_get_by_id(), _zip_ef_parse(), _zip_ef_remove_internal(), _zip_guess_encoding(), _zip_read_data(), _zip_read_string(), zip_dirent::bitflags, CDENTRYSIZE, CENTRAL_MAGIC, zip_dirent::comment, zip_dirent::comp_method, zip_dirent::comp_size, zip_dirent::crc, zip_dirent::disk_number, EFBIG, zip_dirent::encryption_method, error(), zip_dirent::ext_attrib, zip_dirent::extra_fields, zip_dirent::filename, free(), zip_dirent::int_attrib, zip_dirent::last_mod, LENTRYSIZE, local, zip_dirent::local_extra_fields_read, LOCAL_MAGIC, NULL, zip_dirent::offset, ok, src, zip_dirent::uncomp_size, zip_dirent::version_madeby, zip_dirent::version_needed, ZIP_EF_CENTRAL, ZIP_EF_LOCAL, ZIP_EF_UTF_8_COMMENT, ZIP_EF_UTF_8_NAME, ZIP_EF_ZIP64, ZIP_EM_NONE, ZIP_EM_TRAD_PKWARE, ZIP_EM_UNKNOWN, ZIP_ENCODING_ERROR, ZIP_ENCODING_UTF8_KNOWN, ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT, ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME, ZIP_ER_DETAIL_INVALID_ZIP64_EF, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW, ZIP_ER_EOF, ZIP_ER_INCONS, ZIP_ER_INTERNAL, ZIP_ER_MEMORY, ZIP_ER_NOZIP, ZIP_ER_SEEK, zip_error_code_zip(), zip_error_set(), ZIP_GPBF_ENCODING_UTF_8, ZIP_GPBF_ENCRYPTED, ZIP_GPBF_STRONG_ENCRYPTION, ZIP_INT64_MAX, ZIP_UINT16_MAX, and ZIP_UINT32_MAX.

Referenced by _zip_checkcons(), and _zip_read_cdir().

◆ _zip_dirent_set_version_needed()

void _zip_dirent_set_version_needed ( zip_dirent_t de,
bool  force_zip64 
)

◆ _zip_dirent_size()

zip_int32_t _zip_dirent_size ( zip_source_t src,
zip_uint16_t  flags,
zip_error_t error 
)

Definition at line 721 of file zip_dirent.c.

721  {
723  bool local = (flags & ZIP_EF_LOCAL) != 0;
724  int i;
725  zip_uint8_t b[6];
727 
729 
730  if (zip_source_seek(src, local ? 26 : 28, SEEK_CUR) < 0) {
732  return -1;
733  }
734 
735  if ((buffer = _zip_buffer_new_from_source(src, local ? 4 : 6, b, error)) == NULL) {
736  return -1;
737  }
738 
739  for (i = 0; i < (local ? 2 : 3); i++) {
741  }
742 
743  if (!_zip_buffer_eof(buffer)) {
746  return -1;
747  }
748 
750  return size;
751 }
ZIP_EXTERN int zip_source_seek(zip_source_t *_Nonnull, zip_int64_t, int)
#define b(i)
Definition: sha256.c:42
#define SEEK_CUR
Definition: zip.c:80
int32_t zip_int32_t
Definition: zipconf.h:36

References _zip_buffer_eof(), _zip_buffer_free(), _zip_buffer_get_16(), _zip_buffer_new_from_source(), _zip_error_set_from_source(), b, CDENTRYSIZE, error(), flags, i, LENTRYSIZE, local, NULL, SEEK_CUR, src, ZIP_EF_LOCAL, ZIP_ER_INTERNAL, zip_error_set(), and zip_source_seek().

Referenced by _zip_file_get_offset().

◆ _zip_dirent_write()

int _zip_dirent_write ( zip_t za,
zip_dirent_t dirent,
zip_flags_t  flags 
)

Definition at line 765 of file zip_dirent.c.

765  {
766  zip_uint16_t dostime, dosdate;
767  zip_encoding_type_t com_enc, name_enc;
769  zip_extra_field_t *ef64;
770  zip_uint32_t ef_total_size;
771  bool is_zip64;
772  bool is_really_zip64;
773  bool is_winzip_aes;
776 
777  ef = NULL;
778 
779  name_enc = _zip_guess_encoding(de->filename, ZIP_ENCODING_UNKNOWN);
780  com_enc = _zip_guess_encoding(de->comment, ZIP_ENCODING_UNKNOWN);
781 
782  if ((name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_ASCII) || (name_enc == ZIP_ENCODING_ASCII && com_enc == ZIP_ENCODING_UTF8_KNOWN) || (name_enc == ZIP_ENCODING_UTF8_KNOWN && com_enc == ZIP_ENCODING_UTF8_KNOWN))
783  de->bitflags |= ZIP_GPBF_ENCODING_UTF_8;
784  else {
785  de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCODING_UTF_8;
786  if (name_enc == ZIP_ENCODING_UTF8_KNOWN) {
787  ef = _zip_ef_utf8(ZIP_EF_UTF_8_NAME, de->filename, &za->error);
788  if (ef == NULL)
789  return -1;
790  }
791  if ((flags & ZIP_FL_LOCAL) == 0 && com_enc == ZIP_ENCODING_UTF8_KNOWN) {
793  if (ef2 == NULL) {
794  _zip_ef_free(ef);
795  return -1;
796  }
797  ef2->next = ef;
798  ef = ef2;
799  }
800  }
801 
802  if (de->encryption_method == ZIP_EM_NONE) {
803  de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCRYPTED;
804  }
805  else {
806  de->bitflags |= (zip_uint16_t)ZIP_GPBF_ENCRYPTED;
807  }
808 
809  is_really_zip64 = _zip_dirent_needs_zip64(de, flags);
810  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
811  is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
812 
813  if (is_zip64) {
814  zip_uint8_t ef_zip64[EFZIP64SIZE];
815  zip_buffer_t *ef_buffer = _zip_buffer_new(ef_zip64, sizeof(ef_zip64));
816  if (ef_buffer == NULL) {
818  _zip_ef_free(ef);
819  return -1;
820  }
821 
822  if (flags & ZIP_FL_LOCAL) {
823  if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
824  _zip_buffer_put_64(ef_buffer, de->uncomp_size);
825  _zip_buffer_put_64(ef_buffer, de->comp_size);
826  }
827  }
828  else {
829  if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
830  if (de->uncomp_size >= ZIP_UINT32_MAX) {
831  _zip_buffer_put_64(ef_buffer, de->uncomp_size);
832  }
833  if (de->comp_size >= ZIP_UINT32_MAX) {
834  _zip_buffer_put_64(ef_buffer, de->comp_size);
835  }
836  if (de->offset >= ZIP_UINT32_MAX) {
837  _zip_buffer_put_64(ef_buffer, de->offset);
838  }
839  }
840  }
841 
842  if (!_zip_buffer_ok(ef_buffer)) {
844  _zip_buffer_free(ef_buffer);
845  _zip_ef_free(ef);
846  return -1;
847  }
848 
849  ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
850  _zip_buffer_free(ef_buffer);
851  ef64->next = ef;
852  ef = ef64;
853  }
854 
855  if (is_winzip_aes) {
857  zip_buffer_t *ef_buffer = _zip_buffer_new(data, sizeof(data));
858  zip_extra_field_t *ef_winzip;
859 
860  if (ef_buffer == NULL) {
862  _zip_ef_free(ef);
863  return -1;
864  }
865 
866  _zip_buffer_put_16(ef_buffer, 2);
867  _zip_buffer_put(ef_buffer, "AE", 2);
868  _zip_buffer_put_8(ef_buffer, (zip_uint8_t)(de->encryption_method & 0xff));
869  _zip_buffer_put_16(ef_buffer, (zip_uint16_t)de->comp_method);
870 
871  if (!_zip_buffer_ok(ef_buffer)) {
873  _zip_buffer_free(ef_buffer);
874  _zip_ef_free(ef);
875  return -1;
876  }
877 
879  _zip_buffer_free(ef_buffer);
880  ef_winzip->next = ef;
881  ef = ef_winzip;
882  }
883 
884  if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
886  _zip_ef_free(ef);
887  return -1;
888  }
889 
891 
892  if ((flags & ZIP_FL_LOCAL) == 0) {
893  _zip_buffer_put_16(buffer, de->version_madeby);
894  }
895  _zip_buffer_put_16(buffer, ZIP_MAX(is_really_zip64 ? 45 : 0, de->version_needed));
896  _zip_buffer_put_16(buffer, de->bitflags);
897  if (is_winzip_aes) {
899  }
900  else {
901  _zip_buffer_put_16(buffer, (zip_uint16_t)de->comp_method);
902  }
903 
904  _zip_u2d_time(de->last_mod, &dostime, &dosdate);
905  _zip_buffer_put_16(buffer, dostime);
906  _zip_buffer_put_16(buffer, dosdate);
907 
908  if (is_winzip_aes && de->uncomp_size < 20) {
910  }
911  else {
912  _zip_buffer_put_32(buffer, de->crc);
913  }
914 
915  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
916  /* In local headers, if a ZIP64 EF is written, it MUST contain
917  * both compressed and uncompressed sizes (even if one of the
918  * two is smaller than 0xFFFFFFFF); on the other hand, those
919  * may only appear when the corresponding standard entry is
920  * 0xFFFFFFFF. (appnote.txt 4.5.3) */
923  }
924  else {
925  if (de->comp_size < ZIP_UINT32_MAX) {
926  _zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size);
927  }
928  else {
930  }
931  if (de->uncomp_size < ZIP_UINT32_MAX) {
932  _zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size);
933  }
934  else {
936  }
937  }
938 
940  /* TODO: check for overflow */
941  ef_total_size = (zip_uint32_t)_zip_ef_size(de->extra_fields, flags) + (zip_uint32_t)_zip_ef_size(ef, ZIP_EF_BOTH);
942  _zip_buffer_put_16(buffer, (zip_uint16_t)ef_total_size);
943 
944  if ((flags & ZIP_FL_LOCAL) == 0) {
946  _zip_buffer_put_16(buffer, (zip_uint16_t)de->disk_number);
947  _zip_buffer_put_16(buffer, de->int_attrib);
948  _zip_buffer_put_32(buffer, de->ext_attrib);
949  if (de->offset < ZIP_UINT32_MAX)
951  else
953  }
954 
955  if (!_zip_buffer_ok(buffer)) {
958  _zip_ef_free(ef);
959  return -1;
960  }
961 
962  if (_zip_write(za, buf, _zip_buffer_offset(buffer)) < 0) {
964  _zip_ef_free(ef);
965  return -1;
966  }
967 
969 
970  if (de->filename) {
971  if (_zip_string_write(za, de->filename) < 0) {
972  _zip_ef_free(ef);
973  return -1;
974  }
975  }
976 
977  if (ef) {
978  if (_zip_ef_write(za, ef, ZIP_EF_BOTH) < 0) {
979  _zip_ef_free(ef);
980  return -1;
981  }
982  }
983  _zip_ef_free(ef);
984  if (de->extra_fields) {
985  if (_zip_ef_write(za, de->extra_fields, flags) < 0) {
986  return -1;
987  }
988  }
989 
990  if ((flags & ZIP_FL_LOCAL) == 0) {
991  if (de->comment) {
992  if (_zip_string_write(za, de->comment) < 0) {
993  return -1;
994  }
995  }
996  }
997 
998 
999  return is_zip64;
1000 }
#define ef(frag,...)
#define ZIP_FL_LOCAL
Definition: zip.h:85
zip_extra_field_t * next
Definition: zipint.h:368
int _zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i)
Definition: zip_buffer.c:283
void _zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate)
Definition: zip_dirent.c:1090
static zip_extra_field_t * _zip_ef_utf8(zip_uint16_t, zip_string_t *, zip_error_t *)
Definition: zip_dirent.c:1025
zip_uint16_t _zip_ef_size(const zip_extra_field_t *ef, zip_flags_t flags)
zip_extra_field_t * _zip_ef_new(zip_uint16_t id, zip_uint16_t size, const zip_uint8_t *data, zip_flags_t flags)
int _zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags)
int _zip_string_write(zip_t *za, const zip_string_t *s)
Definition: zip_string.c:173
#define ZIP_EF_BOTH
Definition: zipint.h:245
#define ZIP_EF_WINZIP_AES
Definition: zipint.h:87
#define ZIP_FL_FORCE_ZIP64
Definition: zipint.h:247
#define EFZIP64SIZE
Definition: zipint.h:66
enum zip_encoding_type zip_encoding_type_t
Definition: zipint.h:262
#define EF_WINZIP_AES_SIZE
Definition: zipint.h:67
#define ZIP_CM_WINZIP_AES
Definition: zipint.h:73

References _zip_buffer_free(), _zip_buffer_new(), _zip_buffer_offset(), _zip_buffer_ok(), _zip_buffer_put(), _zip_buffer_put_16(), _zip_buffer_put_32(), _zip_buffer_put_64(), _zip_buffer_put_8(), _zip_dirent_needs_zip64(), _zip_ef_free(), _zip_ef_new(), _zip_ef_size(), _zip_ef_utf8(), _zip_ef_write(), _zip_guess_encoding(), _zip_string_length(), _zip_string_write(), _zip_u2d_time(), _zip_write(), zip_dirent::bitflags, CDENTRYSIZE, CENTRAL_MAGIC, zip_dirent::comment, zip_dirent::comp_method, zip_dirent::comp_size, zip_dirent::crc, zip_dirent::disk_number, ef, EF_WINZIP_AES_SIZE, EFZIP64SIZE, zip_dirent::encryption_method, zip::error, zip_dirent::ext_attrib, zip_dirent::extra_fields, zip_dirent::filename, flags, zip_dirent::int_attrib, zip_dirent::last_mod, LOCAL_MAGIC, zip_extra_field::next, NULL, zip_dirent::offset, zip_dirent::uncomp_size, zip_dirent::version_madeby, zip_dirent::version_needed, za, ZIP_CM_WINZIP_AES, ZIP_EF_BOTH, ZIP_EF_UTF_8_COMMENT, ZIP_EF_UTF_8_NAME, ZIP_EF_WINZIP_AES, ZIP_EF_ZIP64, ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_EM_NONE, ZIP_ENCODING_ASCII, ZIP_ENCODING_UNKNOWN, ZIP_ENCODING_UTF8_KNOWN, ZIP_ER_INTERNAL, ZIP_ER_MEMORY, zip_error_set(), ZIP_FL_FORCE_ZIP64, ZIP_FL_LOCAL, ZIP_GPBF_ENCODING_UTF_8, ZIP_GPBF_ENCRYPTED, ZIP_MAX, and ZIP_UINT32_MAX.

Referenced by _zip_cdir_write(), add_data(), and zip_close().

◆ _zip_ef_clone()

zip_extra_field_t* _zip_ef_clone ( const zip_extra_field_t ef,
zip_error_t error 
)

Definition at line 41 of file zip_extra_field.c.

41  {
42  zip_extra_field_t *head, *prev, *def;
43 
44  head = prev = NULL;
45 
46  while (ef) {
47  if ((def = _zip_ef_new(ef->id, ef->size, ef->data, ef->flags)) == NULL) {
50  return NULL;
51  }
52 
53  if (head == NULL)
54  head = def;
55  if (prev)
56  prev->next = def;
57  prev = def;
58 
59  ef = ef->next;
60  }
61 
62  return head;
63 }
zip_uint16_t size
Definition: zipcmp.c:73
zip_uint16_t id
Definition: zipcmp.c:72
const zip_uint8_t * data
Definition: zipcmp.c:74
zip_uint16_t flags
Definition: zipcmp.c:71
int def(FILE *source, FILE *dest, int level)
Definition: zpipe.c:36

References _zip_ef_free(), _zip_ef_new(), ef::data, def(), error(), ef::flags, test-lz4-versions::head, ef::id, zip_extra_field::next, NULL, ef::size, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_file_extra_field_prepare_for_change().

◆ _zip_ef_delete_by_id()

zip_extra_field_t* _zip_ef_delete_by_id ( zip_extra_field_t ef,
zip_uint16_t  id,
zip_uint16_t  id_idx,
zip_flags_t  flags 
)

Definition at line 67 of file zip_extra_field.c.

67  {
68  zip_extra_field_t *head, *prev;
69  int i;
70 
71  i = 0;
72  head = ef;
73  prev = NULL;
74  for (; ef; ef = (prev ? prev->next : head)) {
75  if ((ef->flags & flags & ZIP_EF_BOTH) && ((ef->id == id) || (id == ZIP_EXTRA_FIELD_ALL))) {
76  if (id_idx == ZIP_EXTRA_FIELD_ALL || i == id_idx) {
77  ef->flags &= ~(flags & ZIP_EF_BOTH);
78  if ((ef->flags & ZIP_EF_BOTH) == 0) {
79  if (prev)
80  prev->next = ef->next;
81  else
82  head = ef->next;
83  ef->next = NULL;
85 
86  if (id_idx == ZIP_EXTRA_FIELD_ALL)
87  continue;
88  }
89  }
90 
91  i++;
92  if (i > id_idx)
93  break;
94  }
95  prev = ef;
96  }
97 
98  return head;
99 }
#define ZIP_EXTRA_FIELD_ALL
Definition: zip.h:99
int id
Definition: op.c:540

References _zip_ef_free(), ef, flags, ef::flags, test-lz4-versions::head, i, id, ef::id, zip_extra_field::next, NULL, ZIP_EF_BOTH, and ZIP_EXTRA_FIELD_ALL.

Referenced by zip_file_extra_field_delete(), and zip_file_extra_field_delete_by_id().

◆ _zip_ef_free()

void _zip_ef_free ( zip_extra_field_t ef)

Definition at line 103 of file zip_extra_field.c.

103  {
104  zip_extra_field_t *ef2;
105 
106  while (ef) {
107  ef2 = ef->next;
108  free(ef->data);
109  free(ef);
110  ef = ef2;
111  }
112 }

References ef::data, and free().

Referenced by _zip_dirent_finalize(), _zip_dirent_write(), _zip_ef_clone(), _zip_ef_delete_by_id(), _zip_ef_merge(), _zip_ef_parse(), _zip_ef_remove_internal(), and zip_file_extra_field_set().

◆ _zip_ef_get_by_id()

const zip_uint8_t* _zip_ef_get_by_id ( const zip_extra_field_t ef,
zip_uint16_t lenp,
zip_uint16_t  id,
zip_uint16_t  id_idx,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 116 of file zip_extra_field.c.

116  {
117  static const zip_uint8_t empty[1] = {'\0'};
118 
119  int i;
120 
121  i = 0;
122  for (; ef; ef = ef->next) {
123  if (ef->id == id && (ef->flags & flags & ZIP_EF_BOTH)) {
124  if (i < id_idx) {
125  i++;
126  continue;
127  }
128 
129  if (lenp)
130  *lenp = ef->size;
131  if (ef->size > 0)
132  return ef->data;
133  else
134  return empty;
135  }
136  }
137 
139  return NULL;
140 }
#define ZIP_ER_NOENT
Definition: zip.h:114

References ef::data, ef, error(), flags, ef::flags, i, ef::id, NULL, ef::size, ZIP_EF_BOTH, ZIP_ER_NOENT, and zip_error_set().

Referenced by _zip_dirent_process_ef_utf_8(), _zip_dirent_process_winzip_aes(), _zip_dirent_read(), and zip_file_extra_field_get_by_id().

◆ _zip_ef_merge()

zip_extra_field_t* _zip_ef_merge ( zip_extra_field_t to,
zip_extra_field_t from 
)

Definition at line 144 of file zip_extra_field.c.

144  {
145  zip_extra_field_t *ef2, *tt, *tail;
146  int duplicate;
147 
148  if (to == NULL)
149  return from;
150 
151  for (tail = to; tail->next; tail = tail->next)
152  ;
153 
154  for (; from; from = ef2) {
155  ef2 = from->next;
156 
157  duplicate = 0;
158  for (tt = to; tt; tt = tt->next) {
159  if (tt->id == from->id && tt->size == from->size && (tt->size == 0 || memcmp(tt->data, from->data, tt->size) == 0)) {
160  tt->flags |= (from->flags & ZIP_EF_BOTH);
161  duplicate = 1;
162  break;
163  }
164  }
165 
166  from->next = NULL;
167  if (duplicate)
169  else
170  tail = tail->next = from;
171  }
172 
173  return to;
174 }
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
zip_uint8_t * data
Definition: zipint.h:372
zip_uint16_t size
Definition: zipint.h:371
zip_flags_t flags
Definition: zipint.h:369
zip_uint16_t id
Definition: zipint.h:370

References _zip_ef_free(), zip_extra_field::data, zip_extra_field::flags, from, zip_extra_field::id, zip_extra_field::next, NULL, zip_extra_field::size, to, and ZIP_EF_BOTH.

Referenced by _zip_checkcons(), and _zip_read_local_ef().

◆ _zip_ef_new()

zip_extra_field_t* _zip_ef_new ( zip_uint16_t  id,
zip_uint16_t  size,
const zip_uint8_t data,
zip_flags_t  flags 
)

Definition at line 178 of file zip_extra_field.c.

178  {
180 
181  if ((ef = (zip_extra_field_t *)malloc(sizeof(*ef))) == NULL)
182  return NULL;
183 
184  ef->next = NULL;
185  ef->flags = flags;
186  ef->id = id;
187  ef->size = size;
188  if (size > 0) {
189  if ((ef->data = (zip_uint8_t *)_zip_memdup(data, size, NULL)) == NULL) {
190  free(ef);
191  return NULL;
192  }
193  }
194  else
195  ef->data = NULL;
196 
197  return ef;
198 }
void * _zip_memdup(const void *mem, size_t len, zip_error_t *error)
Definition: zip_memdup.c:41

References _zip_memdup(), ef::data, ef, flags, ef::flags, free(), id, ef::id, malloc(), NULL, and ef::size.

Referenced by _zip_dirent_write(), _zip_ef_clone(), _zip_ef_parse(), _zip_ef_utf8(), and zip_file_extra_field_set().

◆ _zip_ef_parse()

bool _zip_ef_parse ( const zip_uint8_t data,
zip_uint16_t  len,
zip_flags_t  flags,
zip_extra_field_t **  ef_head_p,
zip_error_t error 
)

Definition at line 202 of file zip_extra_field.c.

202  {
204  zip_extra_field_t *ef, *ef2, *ef_head;
205 
206  if ((buffer = _zip_buffer_new((zip_uint8_t *)data, len)) == NULL) {
208  return false;
209  }
210 
211  ef_head = ef = NULL;
212 
213  while (_zip_buffer_ok(buffer) && _zip_buffer_left(buffer) >= 4) {
214  zip_uint16_t fid, flen;
215  zip_uint8_t *ef_data;
216 
217  fid = _zip_buffer_get_16(buffer);
218  flen = _zip_buffer_get_16(buffer);
219  ef_data = _zip_buffer_get(buffer, flen);
220 
221  if (ef_data == NULL) {
224  _zip_ef_free(ef_head);
225  return false;
226  }
227 
228  if ((ef2 = _zip_ef_new(fid, flen, ef_data, flags)) == NULL) {
231  _zip_ef_free(ef_head);
232  return false;
233  }
234 
235  if (ef_head) {
236  ef->next = ef2;
237  ef = ef2;
238  }
239  else
240  ef_head = ef = ef2;
241  }
242 
243  if (!_zip_buffer_eof(buffer)) {
244  /* Android APK files align stored file data with padding in extra fields; ignore. */
245  /* see https://android.googlesource.com/platform/build/+/master/tools/zipalign/ZipAlign.cpp */
246  size_t glen = _zip_buffer_left(buffer);
247  zip_uint8_t *garbage;
248  garbage = _zip_buffer_get(buffer, glen);
249  if (glen >= 4 || garbage == NULL || memcmp(garbage, "\0\0\0", glen) != 0) {
252  _zip_ef_free(ef_head);
253  return false;
254  }
255  }
256 
258 
259  if (ef_head_p) {
260  *ef_head_p = ef_head;
261  }
262  else {
263  _zip_ef_free(ef_head);
264  }
265 
266  return true;
267 }
#define ZIP_ER_DETAIL_INVALID_EF_LENGTH
Definition: zipint.h:231
#define ZIP_ER_DETAIL_EF_TRAILING_GARBAGE
Definition: zipint.h:230

References _zip_buffer_eof(), _zip_buffer_free(), _zip_buffer_get(), _zip_buffer_get_16(), _zip_buffer_left(), _zip_buffer_new(), _zip_buffer_ok(), _zip_ef_free(), _zip_ef_new(), ef, error(), flags, len, NULL, ZIP_ER_DETAIL_EF_TRAILING_GARBAGE, ZIP_ER_DETAIL_INVALID_EF_LENGTH, ZIP_ER_INCONS, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_dirent_read(), and _zip_read_local_ef().

◆ _zip_ef_remove_internal()

zip_extra_field_t* _zip_ef_remove_internal ( zip_extra_field_t ef)

Definition at line 271 of file zip_extra_field.c.

271  {
272  zip_extra_field_t *ef_head;
273  zip_extra_field_t *prev, *next;
274 
275  ef_head = ef;
276  prev = NULL;
277 
278  while (ef) {
279  if (ZIP_EF_IS_INTERNAL(ef->id)) {
280  next = ef->next;
281  if (ef_head == ef)
282  ef_head = next;
283  ef->next = NULL;
284  _zip_ef_free(ef);
285  if (prev)
286  prev->next = next;
287  ef = next;
288  }
289  else {
290  prev = ef;
291  ef = ef->next;
292  }
293  }
294 
295  return ef_head;
296 }
#define ZIP_EF_IS_INTERNAL(id)
Definition: zipint.h:90

References _zip_ef_free(), ef, ef::id, zip_extra_field::next, NULL, and ZIP_EF_IS_INTERNAL.

Referenced by _zip_dirent_read(), and _zip_read_local_ef().

◆ _zip_ef_size()

zip_uint16_t _zip_ef_size ( const zip_extra_field_t ef,
zip_flags_t  flags 
)

Definition at line 300 of file zip_extra_field.c.

300  {
302 
303  size = 0;
304  for (; ef; ef = ef->next) {
305  if (ef->flags & flags & ZIP_EF_BOTH)
306  size = (zip_uint16_t)(size + 4 + ef->size);
307  }
308 
309  return size;
310 }

References ef, flags, ef::flags, ef::size, and ZIP_EF_BOTH.

Referenced by _zip_dirent_write(), and zip_file_extra_field_set().

◆ _zip_ef_write()

int _zip_ef_write ( zip_t za,
const zip_extra_field_t ef,
zip_flags_t  flags 
)

Definition at line 314 of file zip_extra_field.c.

314  {
315  zip_uint8_t b[4];
316  zip_buffer_t *buffer = _zip_buffer_new(b, sizeof(b));
317 
318  if (buffer == NULL) {
319  return -1;
320  }
321 
322  for (; ef; ef = ef->next) {
323  if (ef->flags & flags & ZIP_EF_BOTH) {
327  if (!_zip_buffer_ok(buffer)) {
330  return -1;
331  }
332  if (_zip_write(za, b, 4) < 0) {
334  return -1;
335  }
336  if (ef->size > 0) {
337  if (_zip_write(za, ef->data, ef->size) < 0) {
339  return -1;
340  }
341  }
342  }
343  }
344 
346  return 0;
347 }

References _zip_buffer_free(), _zip_buffer_new(), _zip_buffer_ok(), _zip_buffer_put_16(), _zip_buffer_set_offset(), _zip_write(), b, ef::data, ef, zip::error, flags, ef::flags, ef::id, NULL, ef::size, za, ZIP_EF_BOTH, ZIP_ER_INTERNAL, and zip_error_set().

Referenced by _zip_dirent_write().

◆ _zip_entry_finalize()

void _zip_entry_finalize ( zip_entry_t e)

Definition at line 38 of file zip_entry.c.

38  {
40  _zip_dirent_free(e->orig);
41  _zip_dirent_free(e->changes);
42 }
#define e(frag)
void _zip_dirent_free(zip_dirent_t *zde)
Definition: zip_dirent.c:258
void _zip_unchange_data(zip_entry_t *ze)

References _zip_dirent_free(), _zip_unchange_data(), and e.

Referenced by _zip_cdir_free(), _zip_file_replace(), and zip_discard().

◆ _zip_entry_init()

void _zip_entry_init ( zip_entry_t e)

Definition at line 46 of file zip_entry.c.

46  {
47  e->orig = NULL;
48  e->changes = NULL;
49  e->source = NULL;
50  e->deleted = 0;
51 }

References e, and NULL.

Referenced by _zip_add_entry(), and _zip_cdir_grow().

◆ _zip_error_clear()

void _zip_error_clear ( zip_error_t err)

Definition at line 92 of file zip_error.c.

92  {
93  if (err == NULL)
94  return;
95 
96  err->zip_err = ZIP_ER_OK;
97  err->sys_err = 0;
98 }
static bool err
Definition: armass.c:435
#define ZIP_ER_OK
Definition: zip.h:105

References err, NULL, and ZIP_ER_OK.

Referenced by _zip_name_locate(), zip_error_clear(), zip_file_error_clear(), and zip_source_open().

◆ _zip_error_copy()

void _zip_error_copy ( zip_error_t dst,
const zip_error_t src 
)

Definition at line 102 of file zip_error.c.

102  {
103  if (dst == NULL) {
104  return;
105  }
106 
107  dst->zip_err = src->zip_err;
108  dst->sys_err = src->sys_err;
109 }

References dst, NULL, and src.

Referenced by _zip_error_set_from_source(), _zip_file_exists(), _zip_find_central_dir(), _zip_open(), and zip_source_file_common_new().

◆ _zip_error_get()

void _zip_error_get ( const zip_error_t err,
int zep,
int sep 
)

Definition at line 113 of file zip_error.c.

113  {
114  if (zep)
115  *zep = err->zip_err;
116  if (sep) {
118  *sep = err->sys_err;
119  else
120  *sep = 0;
121  }
122 }
#define ZIP_ET_NONE
Definition: zip.h:141
ZIP_EXTERN int zip_error_system_type(const zip_error_t *error)
Definition: zip_error.c:83

References err, zip_error_system_type(), and ZIP_ET_NONE.

Referenced by zip_error_get(), and zip_file_error_get().

◆ _zip_error_set_from_source()

◆ _zip_extract_extra_field_by_id()

const zip_uint8_t* _zip_extract_extra_field_by_id ( zip_error_t ,
zip_uint16_t  ,
int  ,
const zip_uint8_t ,
zip_uint16_t  ,
zip_uint16_t  
)

◆ _zip_file_extra_field_prepare_for_change()

int _zip_file_extra_field_prepare_for_change ( zip_t za,
zip_uint64_t  idx 
)

Definition at line 323 of file zip_extra_field_api.c.

323  {
324  zip_entry_t *e;
325 
326  if (idx >= za->nentry) {
328  return -1;
329  }
330 
331  e = za->entry + idx;
332 
333  if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD))
334  return 0;
335 
336  if (e->orig) {
337  if (_zip_read_local_ef(za, idx) < 0)
338  return -1;
339  }
340 
341  if (e->changes == NULL) {
342  if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
344  return -1;
345  }
346  }
347 
348  if (e->orig && e->orig->extra_fields) {
349  if ((e->changes->extra_fields = _zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL)
350  return -1;
351  }
352  e->changes->changed |= ZIP_DIRENT_EXTRA_FIELD;
353 
354  return 0;
355 }
#define ZIP_ER_INVAL
Definition: zip.h:123
zip_dirent_t * _zip_dirent_clone(const zip_dirent_t *sde)
Definition: zip_dirent.c:215
int _zip_read_local_ef(zip_t *za, zip_uint64_t idx)
zip_extra_field_t * _zip_ef_clone(const zip_extra_field_t *ef, zip_error_t *error)

References _zip_dirent_clone(), _zip_ef_clone(), _zip_read_local_ef(), e, zip::entry, zip::error, setup::idx, zip::nentry, NULL, za, ZIP_DIRENT_EXTRA_FIELD, ZIP_ER_INVAL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by zip_file_extra_field_delete(), zip_file_extra_field_delete_by_id(), and zip_file_extra_field_set().

◆ _zip_file_fillbuf()

int _zip_file_fillbuf ( void *  ,
size_t  ,
zip_file_t  
)

◆ _zip_file_get_end()

zip_uint64_t _zip_file_get_end ( const zip_t za,
zip_uint64_t  index,
zip_error_t error 
)

Definition at line 77 of file zip_file_get_offset.c.

77  {
80 
81  if ((offset = _zip_file_get_offset(za, index, error)) == 0) {
82  return 0;
83  }
84 
85  entry = za->entry[index].orig;
86 
87  if (offset + entry->comp_size < offset || offset + entry->comp_size > ZIP_INT64_MAX) {
89  return 0;
90  }
91  offset += entry->comp_size;
92 
93  if (entry->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
94  zip_uint8_t buf[4];
97  return 0;
98  }
99  if (zip_source_read(za->src, buf, 4) != 4) {
101  return 0;
102  }
103  if (memcmp(buf, DATADES_MAGIC, 4) == 0) {
104  offset += 4;
105  }
106  offset += 12;
107  if (_zip_dirent_needs_zip64(entry, 0)) {
108  offset += 8;
109  }
110  if (offset > ZIP_INT64_MAX) {
112  return 0;
113  }
114  }
115 
116  return offset;
117 }
ZIP_EXTERN zip_int64_t zip_source_read(zip_source_t *_Nonnull, void *_Nonnull, zip_uint64_t)
zip_dirent_t * orig
Definition: zipint.h:409
#define SEEK_SET
Definition: zip.c:88
zip_uint64_t _zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error)
#define DATADES_MAGIC
Definition: zipint.h:54
#define ZIP_GPBF_DATA_DESCRIPTOR
Definition: zipint.h:237

References _zip_dirent_needs_zip64(), _zip_error_set_from_source(), _zip_file_get_offset(), DATADES_MAGIC, EFBIG, zip::entry, error(), zip_entry::orig, SEEK_SET, zip::src, za, ZIP_ER_SEEK, zip_error_set(), ZIP_GPBF_DATA_DESCRIPTOR, ZIP_INT64_MAX, zip_source_read(), and zip_source_seek().

Referenced by zip_close().

◆ _zip_file_get_offset()

zip_uint64_t _zip_file_get_offset ( const zip_t za,
zip_uint64_t  idx,
zip_error_t error 
)

Definition at line 48 of file zip_file_get_offset.c.

48  {
51 
52  if (za->entry[idx].orig == NULL) {
54  return 0;
55  }
56 
58 
61  return 0;
62  }
63 
64  /* TODO: cache? */
65  if ((size = _zip_dirent_size(za->src, ZIP_EF_LOCAL, error)) < 0)
66  return 0;
67 
70  return 0;
71  }
72 
73  return offset + (zip_uint32_t)size;
74 }
zip_int32_t _zip_dirent_size(zip_source_t *src, zip_uint16_t flags, zip_error_t *error)
Definition: zip_dirent.c:721

References _zip_dirent_size(), _zip_error_set_from_source(), EFBIG, zip::entry, error(), setup::idx, NULL, zip_dirent::offset, zip_entry::orig, SEEK_SET, zip::src, za, ZIP_EF_LOCAL, ZIP_ER_INTERNAL, ZIP_ER_SEEK, zip_error_set(), ZIP_INT64_MAX, and zip_source_seek().

Referenced by _zip_file_get_end(), window_read(), and zip_close().

◆ _zip_file_replace()

zip_int64_t _zip_file_replace ( zip_t za,
zip_uint64_t  idx,
const char *  name,
zip_source_t source,
zip_flags_t  flags 
)

Definition at line 55 of file zip_file_replace.c.

55  {
56  zip_uint64_t za_nentry_prev;
57 
58  if (ZIP_IS_RDONLY(za)) {
60  return -1;
61  }
62 
63  za_nentry_prev = za->nentry;
64  if (idx == ZIP_UINT64_MAX) {
65  zip_int64_t i = -1;
66 
67  if (flags & ZIP_FL_OVERWRITE)
69 
70  if (i == -1) {
71  /* create and use new entry, used by zip_add */
72  if ((i = _zip_add_entry(za)) < 0)
73  return -1;
74  }
75  idx = (zip_uint64_t)i;
76  }
77 
78  if (name && _zip_set_name(za, idx, name, flags) != 0) {
79  if (za->nentry != za_nentry_prev) {
81  za->nentry = za_nentry_prev;
82  }
83  return -1;
84  }
85 
86  /* does not change any name related data, so we can do it here;
87  * needed for a double add of the same file name */
89 
90  if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || (za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) {
91  if (za->entry[idx].changes == NULL) {
94  return -1;
95  }
96  }
97 
100  }
101 
102  za->entry[idx].source = source;
103 
104  return (zip_int64_t)idx;
105 }
#define ZIP_FL_OVERWRITE
Definition: zip.h:90
#define ZIP_ER_RDONLY
Definition: zip.h:130
const char * source
Definition: lz4.h:699
Definition: z80asm.h:102
zip_source_t * source
Definition: zipint.h:411
zip_dirent_t * changes
Definition: zipint.h:410
zip_int64_t _zip_add_entry(zip_t *za)
Definition: zip_add_entry.c:43
zip_int64_t _zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error)
int _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags)
Definition: zip_set_name.c:42
#define ZIP_UINT64_MAX
Definition: zipconf.h:55
#define ZIP_IS_RDONLY(za)
Definition: zipint.h:479
#define ZIP_CM_REPLACED_DEFAULT
Definition: zipint.h:72
#define ZIP_DIRENT_COMP_METHOD
Definition: zipint.h:316

References _zip_add_entry(), _zip_dirent_clone(), _zip_entry_finalize(), _zip_name_locate(), _zip_set_name(), _zip_unchange_data(), zip_dirent::changed, zip_entry::changes, zip_dirent::comp_method, zip::entry, zip::error, flags, i, setup::idx, zip::nentry, NULL, zip_entry::orig, zip_entry::source, source, za, ZIP_CM_REPLACED_DEFAULT, ZIP_DIRENT_COMP_METHOD, ZIP_ER_MEMORY, ZIP_ER_RDONLY, zip_error_set(), ZIP_FL_OVERWRITE, ZIP_IS_RDONLY, and ZIP_UINT64_MAX.

Referenced by zip_dir_add(), zip_file_add(), and zip_file_replace().

◆ _zip_get_compression_algorithm()

zip_compression_algorithm_t* _zip_get_compression_algorithm ( zip_int32_t  method,
bool  compress 
)

Definition at line 93 of file zip_source_compress.c.

93  {
94  size_t i;
95  zip_uint16_t real_method = ZIP_CM_ACTUAL(method);
96 
97  for (i = 0; i < implementations_size; i++) {
98  if (implementations[i].method == real_method) {
99  if (compress) {
100  return implementations[i].compress;
101  }
102  else {
103  return implementations[i].decompress;
104  }
105  }
106  }
107 
108  return NULL;
109 }
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:68
zip_compression_algorithm_t * compress
zip_compression_algorithm_t * decompress
static struct implementation implementations[]
static size_t implementations_size
#define ZIP_CM_ACTUAL(x)
Definition: zipint.h:83

References implementation::compress, compress(), implementation::decompress, i, implementations, implementations_size, context::method, NULL, and ZIP_CM_ACTUAL.

Referenced by add_data(), compression_source_new(), and zip_compression_method_supported().

◆ _zip_get_dirent()

zip_dirent_t* _zip_get_dirent ( zip_t za,
zip_uint64_t  idx,
zip_flags_t  flags,
zip_error_t error 
)

◆ _zip_get_encryption_implementation()

zip_encryption_implementation _zip_get_encryption_implementation ( zip_uint16_t  method,
int  operation 
)

Definition at line 39 of file zip_get_encryption_implementation.c.

39  {
40  switch (em) {
41  case ZIP_EM_TRAD_PKWARE:
43 
44 #if defined(HAVE_CRYPTO)
45  case ZIP_EM_AES_128:
46  case ZIP_EM_AES_192:
47  case ZIP_EM_AES_256:
49 #endif
50 
51  default:
52  return NULL;
53  }
54 }
zip_source_t * zip_source_pkware_decode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password)
zip_source_t * zip_source_pkware_encode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password)
zip_source_t * zip_source_winzip_aes_decode(zip_t *za, zip_source_t *src, zip_uint16_t encryption_method, int flags, const char *password)
zip_source_t * zip_source_winzip_aes_encode(zip_t *za, zip_source_t *src, zip_uint16_t encryption_method, int flags, const char *password)
#define ZIP_CODEC_DECODE
Definition: zipint.h:107

References NULL, ZIP_CODEC_DECODE, ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_EM_TRAD_PKWARE, zip_source_pkware_decode(), zip_source_pkware_encode(), zip_source_winzip_aes_decode(), and zip_source_winzip_aes_encode().

Referenced by _zip_source_zip_new(), add_data(), zip_encryption_method_supported(), and zip_file_set_encryption().

◆ _zip_get_name()

const char* _zip_get_name ( zip_t za,
zip_uint64_t  idx,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 47 of file zip_get_name.c.

47  {
48  zip_dirent_t *de;
49  const zip_uint8_t *str;
50 
51  if ((de = _zip_get_dirent(za, idx, flags, error)) == NULL)
52  return NULL;
53 
54  if ((str = _zip_string_get(de->filename, NULL, flags, error)) == NULL)
55  return NULL;
56 
57  return (const char *)str;
58 }
zip_dirent_t * _zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
Definition: zip_dirent.c:1064
const zip_uint8_t * _zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error)
Definition: zip_string.c:80

References _zip_get_dirent(), _zip_string_get(), error(), zip_dirent::filename, flags, setup::idx, NULL, cmd_descs_generate::str, and za.

Referenced by _zip_name_locate(), _zip_unchange(), zip_delete(), and zip_get_name().

◆ _zip_guess_encoding()

enum zip_encoding_type _zip_guess_encoding ( zip_string_t ,
enum  zip_encoding_type 
)

◆ _zip_hash_add()

bool _zip_hash_add ( zip_hash_t hash,
const zip_uint8_t name,
zip_uint64_t  index,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 205 of file zip_hash.c.

205  {
206  zip_uint32_t hash_value, table_index;
208 
209  if (hash == NULL || name == NULL || index > ZIP_INT64_MAX) {
211  return false;
212  }
213 
214  if (hash->table_size == 0) {
215  if (!hash_resize(hash, HASH_MIN_SIZE, error)) {
216  return false;
217  }
218  }
219 
220  hash_value = hash_string(name);
221  table_index = hash_value % hash->table_size;
222 
223  for (entry = hash->table[table_index]; entry != NULL; entry = entry->next) {
224  if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
225  if (((flags & ZIP_FL_UNCHANGED) && entry->orig_index != -1) || entry->current_index != -1) {
227  return false;
228  }
229  else {
230  break;
231  }
232  }
233  }
234 
235  if (entry == NULL) {
236  if ((entry = (zip_hash_entry_t *)malloc(sizeof(zip_hash_entry_t))) == NULL) {
238  return false;
239  }
240  entry->name = name;
241  entry->next = hash->table[table_index];
242  hash->table[table_index] = entry;
243  entry->hash_value = hash_value;
244  entry->orig_index = -1;
245  hash->nentries++;
246  if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
247  if (!hash_resize(hash, hash->table_size * 2, error)) {
248  return false;
249  }
250  }
251  }
252 
253  if (flags & ZIP_FL_UNCHANGED) {
254  entry->orig_index = (zip_int64_t)index;
255  }
256  entry->current_index = (zip_int64_t)index;
257 
258  return true;
259 }
#define ZIP_ER_EXISTS
Definition: zip.h:115
const char * name
Definition: op.c:541
char * name
Definition: zipcmp.c:78
Definition: zip_hash.c:50
zip_hash_entry_t ** table
Definition: zip_hash.c:62
zip_uint32_t table_size
Definition: zip_hash.c:60
zip_uint64_t nentries
Definition: zip_hash.c:61
static zip_uint32_t hash_string(const zip_uint8_t *name)
Definition: zip_hash.c:79
#define HASH_MAX_FILL
Definition: zip_hash.c:43
#define HASH_MIN_SIZE
Definition: zip_hash.c:47
static bool hash_resize(zip_hash_t *hash, zip_uint32_t new_size, zip_error_t *error)
Definition: zip_hash.c:97
#define HASH_MAX_SIZE
Definition: zip_hash.c:48

References error(), flags, HASH_MAX_FILL, HASH_MAX_SIZE, HASH_MIN_SIZE, hash_resize(), hash_string(), malloc(), name, entry::name, zip_hash::nentries, NULL, zip_hash::table, zip_hash::table_size, ZIP_ER_EXISTS, ZIP_ER_INVAL, ZIP_ER_MEMORY, zip_error_set(), ZIP_FL_UNCHANGED, and ZIP_INT64_MAX.

Referenced by _zip_open(), _zip_set_name(), and _zip_unchange().

◆ _zip_hash_delete()

bool _zip_hash_delete ( zip_hash_t hash,
const zip_uint8_t key,
zip_error_t error 
)

Definition at line 264 of file zip_hash.c.

264  {
265  zip_uint32_t hash_value, index;
266  zip_hash_entry_t *entry, *previous;
267 
268  if (hash == NULL || name == NULL) {
270  return false;
271  }
272 
273  if (hash->nentries > 0) {
274  hash_value = hash_string(name);
275  index = hash_value % hash->table_size;
276  previous = NULL;
277  entry = hash->table[index];
278  while (entry) {
279  if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
280  if (entry->orig_index == -1) {
281  if (previous) {
282  previous->next = entry->next;
283  }
284  else {
285  hash->table[index] = entry->next;
286  }
287  free(entry);
288  hash->nentries--;
289  if (hash->nentries < hash->table_size * HASH_MIN_FILL && hash->table_size > HASH_MIN_SIZE) {
290  if (!hash_resize(hash, hash->table_size / 2, error)) {
291  return false;
292  }
293  }
294  }
295  else {
296  entry->current_index = -1;
297  }
298  return true;
299  }
300  previous = entry;
301  entry = entry->next;
302  }
303  }
304 
306  return false;
307 }
struct zip_hash_entry * next
Definition: zip_hash.c:54
#define HASH_MIN_FILL
Definition: zip_hash.c:44

References error(), free(), HASH_MIN_FILL, HASH_MIN_SIZE, hash_resize(), hash_string(), entry::name, zip_hash::nentries, zip_hash_entry::next, NULL, zip_hash::table, zip_hash::table_size, ZIP_ER_INVAL, ZIP_ER_NOENT, and zip_error_set().

Referenced by _zip_set_name(), _zip_unchange(), and zip_delete().

◆ _zip_hash_free()

void _zip_hash_free ( zip_hash_t hash)

Definition at line 184 of file zip_hash.c.

184  {
185  zip_uint32_t i;
186 
187  if (hash == NULL) {
188  return;
189  }
190 
191  if (hash->table != NULL) {
192  for (i = 0; i < hash->table_size; i++) {
193  if (hash->table[i] != NULL) {
194  free_list(hash->table[i]);
195  }
196  }
197  free(hash->table);
198  }
199  free(hash);
200 }
static void free_list(zip_hash_entry_t *entry)
Definition: zip_hash.c:68

References free(), free_list(), i, NULL, zip_hash::table, and zip_hash::table_size.

Referenced by zip_discard().

◆ _zip_hash_lookup()

zip_int64_t _zip_hash_lookup ( zip_hash_t hash,
const zip_uint8_t name,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 312 of file zip_hash.c.

312  {
313  zip_uint32_t hash_value, index;
315 
316  if (hash == NULL || name == NULL) {
318  return -1;
319  }
320 
321  if (hash->nentries > 0) {
322  hash_value = hash_string(name);
323  index = hash_value % hash->table_size;
324  for (entry = hash->table[index]; entry != NULL; entry = entry->next) {
325  if (strcmp((const char *)name, (const char *)entry->name) == 0) {
326  if (flags & ZIP_FL_UNCHANGED) {
327  if (entry->orig_index != -1) {
328  return entry->orig_index;
329  }
330  }
331  else {
332  if (entry->current_index != -1) {
333  return entry->current_index;
334  }
335  }
336  break;
337  }
338  }
339  }
340 
342  return -1;
343 }

References error(), flags, hash_string(), entry::name, zip_hash::nentries, NULL, zip_hash::table, zip_hash::table_size, ZIP_ER_INVAL, ZIP_ER_NOENT, zip_error_set(), and ZIP_FL_UNCHANGED.

Referenced by _zip_name_locate().

◆ _zip_hash_new()

zip_hash_t* _zip_hash_new ( zip_error_t error)

Definition at line 167 of file zip_hash.c.

167  {
168  zip_hash_t *hash;
169 
170  if ((hash = (zip_hash_t *)malloc(sizeof(zip_hash_t))) == NULL) {
172  return NULL;
173  }
174 
175  hash->table_size = 0;
176  hash->nentries = 0;
177  hash->table = NULL;
178 
179  return hash;
180 }

References error(), malloc(), zip_hash::nentries, NULL, zip_hash::table, zip_hash::table_size, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_new().

◆ _zip_hash_reserve_capacity()

bool _zip_hash_reserve_capacity ( zip_hash_t hash,
zip_uint64_t  capacity,
zip_error_t error 
)

Definition at line 347 of file zip_hash.c.

347  {
348  zip_uint32_t new_size;
349 
350  if (capacity == 0) {
351  return true;
352  }
353 
354  new_size = size_for_capacity(capacity);
355 
356  if (new_size <= hash->table_size) {
357  return true;
358  }
359 
360  if (!hash_resize(hash, new_size, error)) {
361  return false;
362  }
363 
364  return true;
365 }
static zip_uint32_t size_for_capacity(zip_uint64_t capacity)
Definition: zip_hash.c:136

References error(), hash_resize(), and size_for_capacity().

Referenced by _zip_open().

◆ _zip_hash_revert()

bool _zip_hash_revert ( zip_hash_t hash,
zip_error_t error 
)

Definition at line 369 of file zip_hash.c.

369  {
370  zip_uint32_t i;
371  zip_hash_entry_t *entry, *previous;
372 
373  for (i = 0; i < hash->table_size; i++) {
374  previous = NULL;
375  entry = hash->table[i];
376  while (entry) {
377  if (entry->orig_index == -1) {
379  if (previous) {
380  previous->next = entry->next;
381  }
382  else {
383  hash->table[i] = entry->next;
384  }
385  p = entry;
386  entry = entry->next;
387  /* previous does not change */
388  free(p);
389  hash->nentries--;
390  }
391  else {
392  entry->current_index = entry->orig_index;
393  previous = entry;
394  entry = entry->next;
395  }
396  }
397  }
398 
399  if (hash->nentries < hash->table_size * HASH_MIN_FILL && hash->table_size > HASH_MIN_SIZE) {
400  zip_uint32_t new_size = hash->table_size / 2;
401  while (hash->nentries < new_size * HASH_MIN_FILL && new_size > HASH_MIN_SIZE) {
402  new_size /= 2;
403  }
404  if (!hash_resize(hash, new_size, error)) {
405  return false;
406  }
407  }
408 
409  return true;
410 }
void * p
Definition: libc.cpp:67

References error(), free(), HASH_MIN_FILL, HASH_MIN_SIZE, hash_resize(), i, zip_hash::nentries, zip_hash_entry::next, NULL, p, zip_hash::table, and zip_hash::table_size.

Referenced by zip_unchange_all().

◆ _zip_local_header_read()

int _zip_local_header_read ( zip_t ,
int   
)

◆ _zip_memdup()

void* _zip_memdup ( const void *  mem,
size_t  len,
zip_error_t error 
)

Definition at line 41 of file zip_memdup.c.

41  {
42  void *ret;
43 
44  if (len == 0)
45  return NULL;
46 
47  ret = malloc(len);
48  if (!ret) {
50  return NULL;
51  }
52 
53  memcpy(ret, mem, len);
54 
55  return ret;
56 }
void * mem
Definition: libc.cpp:91

References error(), len, malloc(), mem, memcpy(), NULL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_ef_new().

◆ _zip_mkstempm()

int _zip_mkstempm ( char *  path,
int  mode,
bool  create_file 
)

◆ _zip_name_locate()

zip_int64_t _zip_name_locate ( zip_t za,
const char *  fname,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 50 of file zip_name_locate.c.

50  {
51  int (*cmp)(const char *, const char *);
53  const char *fn, *p;
55 
56  if (za == NULL)
57  return -1;
58 
59  if (fname == NULL) {
61  return -1;
62  }
63 
64  if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
65  if ((str = _zip_string_new((const zip_uint8_t *)fname, strlen(fname), flags, error)) == NULL) {
66  return -1;
67  }
68  if ((fname = (const char *)_zip_string_get(str, NULL, 0, error)) == NULL) {
70  return -1;
71  }
72  }
73 
75  /* can't use hash table */
76  cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
77 
78  for (i = 0; i < za->nentry; i++) {
80 
81  /* newly added (partially filled) entry or error */
82  if (fn == NULL)
83  continue;
84 
85  if (flags & ZIP_FL_NODIR) {
86  p = strrchr(fn, '/');
87  if (p)
88  fn = p + 1;
89  }
90 
91  if (cmp(fname, fn) == 0) {
94  return (zip_int64_t)i;
95  }
96  }
97 
100  return -1;
101  }
102  else {
105  return ret;
106  }
107 }
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
#define ZIP_FL_NODIR
Definition: zip.h:77
#define ZIP_FL_ENC_STRICT
Definition: zip.h:84
#define ZIP_FL_ENC_RAW
Definition: zip.h:83
#define ZIP_FL_ENC_UTF_8
Definition: zip.h:88
#define ZIP_FL_NOCASE
Definition: zip.h:76
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
static int
Definition: sfsocketcall.h:114
zip_hash_t * names
Definition: zipint.h:300
void _zip_error_clear(zip_error_t *err)
Definition: zip_error.c:92
const char * _zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
Definition: zip_get_name.c:47
zip_int64_t _zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error)
Definition: zip_hash.c:312
zip_string_t * _zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error)
Definition: zip_string.c:121

References _zip_error_clear(), _zip_get_name(), _zip_hash_lookup(), _zip_string_free(), _zip_string_get(), _zip_string_new(), cmp(), error(), flags, fn, create_tags_rz::fname, i, int, zip::names, zip::nentry, NULL, p, cmd_descs_generate::str, za, ZIP_ER_INVAL, ZIP_ER_NOENT, zip_error_set(), ZIP_FL_ENC_RAW, ZIP_FL_ENC_STRICT, ZIP_FL_ENC_UTF_8, ZIP_FL_NOCASE, and ZIP_FL_NODIR.

Referenced by _zip_file_replace(), _zip_set_name(), _zip_unchange(), and zip_name_locate().

◆ _zip_new()

zip_t* _zip_new ( zip_error_t error)

Definition at line 45 of file zip_new.c.

45  {
46  zip_t *za;
47 
48  za = (zip_t *)malloc(sizeof(struct zip));
49  if (!za) {
51  return NULL;
52  }
53 
54  if ((za->names = _zip_hash_new(error)) == NULL) {
55  free(za);
56  return NULL;
57  }
58 
59  za->src = NULL;
60  za->open_flags = 0;
62  za->flags = za->ch_flags = 0;
65  za->comment_changed = 0;
66  za->nentry = za->nentry_alloc = 0;
67  za->entry = NULL;
69  za->open_source = NULL;
70  za->progress = NULL;
71 
72  return za;
73 }
ZIP_EXTERN void zip_error_init(zip_error_t *_Nonnull)
Definition: zip_error.c:59
Definition: zipint.h:278
unsigned int open_flags
Definition: zipint.h:280
unsigned int nopen_source_alloc
Definition: zipint.h:297
char * default_password
Definition: zipint.h:286
zip_progress_t * progress
Definition: zipint.h:302
zip_hash_t * _zip_hash_new(zip_error_t *error)
Definition: zip_hash.c:167

References _zip_hash_new(), zip::ch_flags, zip::comment_changed, zip::comment_changes, zip::comment_orig, zip::default_password, zip::entry, zip::error, error(), zip::flags, free(), malloc(), zip::names, zip::nentry, zip::nentry_alloc, zip::nopen_source, zip::nopen_source_alloc, NULL, zip::open_flags, zip::open_source, zip::progress, zip::src, za, ZIP_ER_MEMORY, zip_error_init(), and zip_error_set().

Referenced by _zip_allocate_new().

◆ _zip_open()

zip_t* _zip_open ( zip_source_t src,
unsigned int  flags,
zip_error_t error 
)

Definition at line 146 of file zip_open.c.

146  {
147  zip_t *za;
148  zip_cdir_t *cdir;
149  struct zip_stat st;
151 
152  zip_stat_init(&st);
153  if (zip_source_stat(src, &st) < 0) {
155  return NULL;
156  }
157  if ((st.valid & ZIP_STAT_SIZE) == 0) {
159  return NULL;
160  }
161  len = st.size;
162 
163 
164  if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
165  return NULL;
166  }
167 
168  /* treat empty files as empty archives */
169  if (len == 0 && zip_source_accept_empty(src)) {
170  return za;
171  }
172 
173  if ((cdir = _zip_find_central_dir(za, len)) == NULL) {
175  /* keep src so discard does not get rid of it */
177  zip_discard(za);
178  return NULL;
179  }
180 
181  za->entry = cdir->entry;
182  za->nentry = cdir->nentry;
183  za->nentry_alloc = cdir->nentry_alloc;
184  za->comment_orig = cdir->comment;
185 
186  free(cdir);
187 
189 
190  for (idx = 0; idx < za->nentry; idx++) {
192  if (name == NULL) {
193  /* keep src so discard does not get rid of it */
195  zip_discard(za);
196  return NULL;
197  }
198 
199  if (_zip_hash_add(za->names, name, idx, ZIP_FL_UNCHANGED, &za->error) == false) {
200  if (za->error.zip_err != ZIP_ER_EXISTS || (flags & ZIP_CHECKCONS)) {
202  /* keep src so discard does not get rid of it */
204  zip_discard(za);
205  return NULL;
206  }
207  }
208  }
209 
210  za->ch_flags = za->flags;
211 
212  return za;
213 }
#define ZIP_CHECKCONS
Definition: zip.h:69
#define ZIP_STAT_SIZE
Definition: zip.h:292
ZIP_EXTERN void zip_stat_init(zip_stat_t *_Nonnull)
Definition: zip_stat_init.c:40
ZIP_EXTERN int zip_source_stat(zip_source_t *_Nonnull, zip_stat_t *_Nonnull)
ZIP_EXTERN void zip_discard(zip_t *_Nonnull)
Definition: zip_discard.c:45
ZIP_EXTERN void zip_source_keep(zip_source_t *_Nonnull)
#define EOPNOTSUPP
Definition: sftypes.h:155
zip_string_t * comment
Definition: zipint.h:363
zip_entry_t * entry
Definition: zipint.h:357
zip_uint64_t nentry
Definition: zipint.h:358
zip_uint64_t nentry_alloc
Definition: zipint.h:359
int zip_err
Definition: zip.h:285
Definition: zip.h:300
bool _zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error)
Definition: zip_hash.c:347
bool _zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error)
Definition: zip_hash.c:205
static zip_t * _zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error)
Definition: zip_open.c:504
static zip_cdir_t * _zip_find_central_dir(zip_t *za, zip_uint64_t len)
Definition: zip_open.c:543
bool zip_source_accept_empty(zip_source_t *src)

References _zip_allocate_new(), _zip_error_copy(), _zip_error_set_from_source(), _zip_find_central_dir(), _zip_hash_add(), _zip_hash_reserve_capacity(), _zip_string_get(), zip::ch_flags, zip_cdir::comment, zip::comment_orig, zip::entry, zip_cdir::entry, EOPNOTSUPP, zip::error, error(), zip_dirent::filename, flags, zip::flags, free(), setup::idx, len, zip::names, zip::nentry, zip_cdir::nentry, zip::nentry_alloc, zip_cdir::nentry_alloc, NULL, zip_entry::orig, zip_stat::size, src, zip_stat::valid, za, ZIP_CHECKCONS, zip_discard(), ZIP_ER_EXISTS, ZIP_ER_SEEK, zip_error::zip_err, zip_error_set(), ZIP_FL_UNCHANGED, zip_source_accept_empty(), zip_source_keep(), zip_source_stat(), zip_stat_init(), and ZIP_STAT_SIZE.

Referenced by zip_open_from_source().

◆ _zip_pkware_decrypt()

void _zip_pkware_decrypt ( zip_pkware_keys_t keys,
zip_uint8_t out,
const zip_uint8_t in,
zip_uint64_t  len 
)

Definition at line 95 of file zip_pkware.c.

95  {
97  zip_uint8_t b;
99 
100  for (i = 0; i < len; i++) {
101  b = in[i];
102 
103  /* during initialization, we're only interested in key updates */
104  if (out != NULL) {
105  tmp = crypt_byte(keys);
106  b ^= tmp;
107  out[i] = b;
108  }
109 
110  update_keys(keys, b);
111  }
112 }
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static struct @218 keys[]
static zip_uint8_t crypt_byte(zip_pkware_keys_t *keys)
Definition: zip_pkware.c:55
static void update_keys(zip_pkware_keys_t *keys, zip_uint8_t b)
Definition: zip_pkware.c:46

References b, crypt_byte(), i, in, keys, len, NULL, out, autogen_x86imm::tmp, and update_keys().

Referenced by decrypt_header(), and pkware_decrypt().

◆ _zip_pkware_encrypt()

void _zip_pkware_encrypt ( zip_pkware_keys_t keys,
zip_uint8_t out,
const zip_uint8_t in,
zip_uint64_t  len 
)

Definition at line 72 of file zip_pkware.c.

72  {
74  zip_uint8_t b;
76 
77  for (i = 0; i < len; i++) {
78  b = in[i];
79 
80  if (out != NULL) {
81  tmp = crypt_byte(keys);
82  update_keys(keys, b);
83  b ^= tmp;
84  out[i] = b;
85  }
86  else {
87  /* during initialization, we're only interested in key updates */
88  update_keys(keys, b);
89  }
90  }
91 }

References b, crypt_byte(), i, in, keys, len, NULL, out, autogen_x86imm::tmp, and update_keys().

Referenced by encrypt_header(), and pkware_encrypt().

◆ _zip_pkware_keys_free()

void _zip_pkware_keys_free ( zip_pkware_keys_t keys)

◆ _zip_pkware_keys_new()

zip_pkware_keys_t* _zip_pkware_keys_new ( zip_error_t error)

◆ _zip_pkware_keys_reset()

void _zip_pkware_keys_reset ( zip_pkware_keys_t keys)

Definition at line 64 of file zip_pkware.c.

64  {
65  keys->key[0] = PKWARE_KEY0;
66  keys->key[1] = PKWARE_KEY1;
67  keys->key[2] = PKWARE_KEY2;
68 }
#define PKWARE_KEY0
Definition: zip_pkware.c:40
#define PKWARE_KEY1
Definition: zip_pkware.c:41
#define PKWARE_KEY2
Definition: zip_pkware.c:42

References keys, PKWARE_KEY0, PKWARE_KEY1, and PKWARE_KEY2.

Referenced by pkware_decrypt(), and pkware_encrypt().

◆ _zip_progress_end()

void _zip_progress_end ( zip_progress_t progress)

Definition at line 68 of file zip_progress.c.

68  {
69  _zip_progress_update(progress, 1.0);
70 }
int _zip_progress_update(zip_progress_t *progress, double sub_current)
Definition: zip_progress.c:184

References _zip_progress_update().

Referenced by zip_close().

◆ _zip_progress_free()

void _zip_progress_free ( zip_progress_t progress)

Definition at line 74 of file zip_progress.c.

74  {
75  if (progress == NULL) {
76  return;
77  }
78 
81 
82  free(progress);
83 }
static void _zip_progress_free_progress_callback(zip_progress_t *progress)
Definition: zip_progress.c:110
static void _zip_progress_free_cancel_callback(zip_progress_t *progress)
Definition: zip_progress.c:121

References _zip_progress_free_cancel_callback(), _zip_progress_free_progress_callback(), free(), and NULL.

Referenced by zip_discard(), zip_register_cancel_callback_with_state(), and zip_register_progress_callback_with_state().

◆ _zip_progress_start()

int _zip_progress_start ( zip_progress_t progress)

Definition at line 151 of file zip_progress.c.

151  {
152  if (progress == NULL) {
153  return 0;
154  }
155 
156  if (progress->callback_progress != NULL) {
157  progress->last_update = 0.0;
158  progress->callback_progress(progress->za, 0.0, progress->ud_progress);
159  }
160 
161  if (progress->callback_cancel != NULL) {
162  if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
163  return -1;
164  }
165  }
166 
167  return 0;
168 }
double last_update
Definition: zip_progress.c:55
void * ud_progress
Definition: zip_progress.c:46
zip_progress_callback callback_progress
Definition: zip_progress.c:44
zip_cancel_callback callback_cancel
Definition: zip_progress.c:48
void * ud_cancel
Definition: zip_progress.c:50
zip_t * za
Definition: zip_progress.c:42

References zip_progress::callback_cancel, zip_progress::callback_progress, zip_progress::last_update, NULL, zip_progress::ud_cancel, zip_progress::ud_progress, and zip_progress::za.

Referenced by zip_close().

◆ _zip_progress_subrange()

int _zip_progress_subrange ( zip_progress_t progress,
double  start,
double  end 
)

Definition at line 172 of file zip_progress.c.

172  {
173  if (progress == NULL) {
174  return 0;
175  }
176 
177  progress->start = start;
178  progress->end = end;
179 
180  return _zip_progress_update(progress, 0.0);
181 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
double start
Definition: zip_progress.c:57

References _zip_progress_update(), test_evm::end, zip_progress::end, NULL, start, and zip_progress::start.

Referenced by zip_close().

◆ _zip_progress_update()

int _zip_progress_update ( zip_progress_t progress,
double  value 
)

Definition at line 184 of file zip_progress.c.

184  {
185  double current;
186 
187  if (progress == NULL) {
188  return 0;
189  }
190 
191  if (progress->callback_progress != NULL) {
192  current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
193 
194  if (current - progress->last_update > progress->precision) {
195  progress->callback_progress(progress->za, current, progress->ud_progress);
196  progress->last_update = current;
197  }
198  }
199 
200  if (progress->callback_cancel != NULL) {
201  if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
202  return -1;
203  }
204  }
205 
206  return 0;
207 }
double precision
Definition: zip_progress.c:52
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
#define ZIP_MIN(a, b)
Definition: zipint.h:473

References zip_progress::callback_cancel, zip_progress::callback_progress, zip_progress::end, if(), zip_progress::last_update, NULL, zip_progress::precision, zip_progress::start, zip_progress::ud_cancel, zip_progress::ud_progress, zip_progress::za, ZIP_MAX, and ZIP_MIN.

Referenced by _zip_progress_end(), _zip_progress_subrange(), copy_data(), and copy_source().

◆ _zip_read()

int _zip_read ( zip_source_t src,
zip_uint8_t data,
zip_uint64_t  length,
zip_error_t error 
)

Definition at line 40 of file zip_io_util.c.

40  {
41  zip_int64_t n;
42 
43  if (length > ZIP_INT64_MAX) {
45  return -1;
46  }
47 
48  if ((n = zip_source_read(src, b, length)) < 0) {
50  return -1;
51  }
52 
53  if (n < (zip_int64_t)length) {
55  return -1;
56  }
57 
58  return 0;
59 }
int n
Definition: mipsasm.c:19

References _zip_error_set_from_source(), b, error(), length, n, src, ZIP_ER_EOF, ZIP_ER_INTERNAL, zip_error_set(), ZIP_INT64_MAX, and zip_source_read().

Referenced by _zip_buffer_new_from_source(), _zip_read_data(), and copy_data().

◆ _zip_read_at_offset()

int _zip_read_at_offset ( zip_source_t src,
zip_uint64_t  offset,
unsigned char *  b,
size_t  length,
zip_error_t error 
)

◆ _zip_read_data()

zip_uint8_t* _zip_read_data ( zip_buffer_t buffer,
zip_source_t src,
size_t  length,
bool  nulp,
zip_error_t error 
)

Definition at line 63 of file zip_io_util.c.

63  {
64  zip_uint8_t *r;
65 
66  if (length == 0 && !nulp) {
67  return NULL;
68  }
69 
70  r = (zip_uint8_t *)malloc(length + (nulp ? 1 : 0));
71  if (!r) {
73  return NULL;
74  }
75 
76  if (buffer) {
78 
79  if (data == NULL) {
81  free(r);
82  return NULL;
83  }
84  memcpy(r, data, length);
85  }
86  else {
87  if (_zip_read(src, r, length, error) < 0) {
88  free(r);
89  return NULL;
90  }
91  }
92 
93  if (nulp) {
94  zip_uint8_t *o;
95  /* replace any in-string NUL characters with spaces */
96  r[length] = 0;
97  for (o = r; o < r + length; o++)
98  if (*o == '\0')
99  *o = ' ';
100  }
101 
102  return r;
103 }
#define r
Definition: crypto_rc6.c:12

References _zip_buffer_get(), _zip_read(), error(), free(), length, malloc(), memcpy(), NULL, r, src, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_dirent_read(), _zip_read_local_ef(), and _zip_read_string().

◆ _zip_read_local_ef()

int _zip_read_local_ef ( zip_t za,
zip_uint64_t  idx 
)

Definition at line 351 of file zip_extra_field.c.

351  {
352  zip_entry_t *e;
353  unsigned char b[4];
355  zip_uint16_t fname_len, ef_len;
356 
357  if (idx >= za->nentry) {
359  return -1;
360  }
361 
362  e = za->entry + idx;
363 
364  if (e->orig == NULL || e->orig->local_extra_fields_read)
365  return 0;
366 
367  if (e->orig->offset + 26 > ZIP_INT64_MAX) {
369  return -1;
370  }
371 
372  if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) {
374  return -1;
375  }
376 
377  if ((buffer = _zip_buffer_new_from_source(za->src, sizeof(b), b, &za->error)) == NULL) {
378  return -1;
379  }
380 
381  fname_len = _zip_buffer_get_16(buffer);
382  ef_len = _zip_buffer_get_16(buffer);
383 
384  if (!_zip_buffer_eof(buffer)) {
387  return -1;
388  }
389 
391 
392  if (ef_len > 0) {
394  zip_uint8_t *ef_raw;
395 
396  if (zip_source_seek(za->src, fname_len, SEEK_CUR) < 0) {
397  zip_error_set(&za->error, ZIP_ER_SEEK, errno);
398  return -1;
399  }
400 
401  ef_raw = _zip_read_data(NULL, za->src, ef_len, 0, &za->error);
402 
403  if (ef_raw == NULL)
404  return -1;
405 
406  if (!_zip_ef_parse(ef_raw, ef_len, ZIP_EF_LOCAL, &ef, &za->error)) {
407  free(ef_raw);
408  return -1;
409  }
410  free(ef_raw);
411 
412  if (ef) {
414  e->orig->extra_fields = _zip_ef_merge(e->orig->extra_fields, ef);
415  }
416  }
417 
418  e->orig->local_extra_fields_read = 1;
419 
420  if (e->changes && e->changes->local_extra_fields_read == 0) {
421  e->changes->extra_fields = e->orig->extra_fields;
422  e->changes->local_extra_fields_read = 1;
423  }
424 
425  return 0;
426 }
zip_extra_field_t * _zip_ef_merge(zip_extra_field_t *to, zip_extra_field_t *from)

References _zip_buffer_eof(), _zip_buffer_free(), _zip_buffer_get_16(), _zip_buffer_new_from_source(), _zip_ef_merge(), _zip_ef_parse(), _zip_ef_remove_internal(), _zip_error_set_from_source(), _zip_read_data(), b, e, ef, EFBIG, zip::entry, zip::error, free(), setup::idx, zip::nentry, NULL, SEEK_CUR, SEEK_SET, zip::src, za, ZIP_EF_LOCAL, ZIP_ER_INTERNAL, ZIP_ER_INVAL, ZIP_ER_SEEK, zip_error_set(), ZIP_INT64_MAX, and zip_source_seek().

Referenced by _zip_file_extra_field_prepare_for_change(), zip_close(), zip_file_extra_field_get(), zip_file_extra_field_get_by_id(), zip_file_extra_fields_count(), and zip_file_extra_fields_count_by_id().

◆ _zip_read_string()

zip_string_t* _zip_read_string ( zip_buffer_t buffer,
zip_source_t src,
zip_uint16_t  length,
bool  nulp,
zip_error_t error 
)

Definition at line 107 of file zip_io_util.c.

107  {
108  zip_uint8_t *raw;
109  zip_string_t *s;
110 
111  if ((raw = _zip_read_data(buffer, src, len, nulp, error)) == NULL)
112  return NULL;
113 
115  free(raw);
116  return s;
117 }
#define ZIP_FL_ENC_GUESS
Definition: zip.h:82
static RzSocket * s
Definition: rtr.c:28

References _zip_read_data(), _zip_string_new(), error(), free(), len, NULL, s, src, and ZIP_FL_ENC_GUESS.

Referenced by _zip_dirent_read().

◆ _zip_register_source()

int _zip_register_source ( zip_t za,
zip_source_t src 
)

Definition at line 320 of file zip_source_window.c.

320  {
321  zip_source_t **open_source;
322 
323  if (za->nopen_source + 1 >= za->nopen_source_alloc) {
324  unsigned int n;
325  n = za->nopen_source_alloc + 10;
326  open_source = (zip_source_t **)realloc(za->open_source, n * sizeof(zip_source_t *));
327  if (open_source == NULL) {
329  return -1;
330  }
332  za->open_source = open_source;
333  }
334 
336 
337  return 0;
338 }

References zip::error, n, zip::nopen_source, zip::nopen_source_alloc, NULL, zip::open_source, realloc(), src, za, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_source_set_source_archive().

◆ _zip_set_name()

int _zip_set_name ( zip_t za,
zip_uint64_t  idx,
const char *  name,
zip_flags_t  flags 
)

Definition at line 42 of file zip_set_name.c.

42  {
43  zip_entry_t *e;
45  bool same_as_orig;
46  zip_int64_t i;
47  const zip_uint8_t *old_name, *new_name;
48  zip_string_t *old_str;
49 
50  if (idx >= za->nentry) {
52  return -1;
53  }
54 
55  if (ZIP_IS_RDONLY(za)) {
57  return -1;
58  }
59 
60  if (name && name[0] != '\0') {
61  /* TODO: check for string too long */
62  if ((str = _zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL)
63  return -1;
65  str->encoding = ZIP_ENCODING_UTF8_KNOWN;
66  }
67  else
68  str = NULL;
69 
70  /* TODO: encoding flags needed for CP437? */
71  if ((i = _zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) {
74  return -1;
75  }
76 
77  /* no effective name change */
78  if (i >= 0 && (zip_uint64_t)i == idx) {
80  return 0;
81  }
82 
83  e = za->entry + idx;
84 
85  if (e->orig)
86  same_as_orig = _zip_string_equal(e->orig->filename, str);
87  else
88  same_as_orig = false;
89 
90  if (!same_as_orig && e->changes == NULL) {
91  if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
94  return -1;
95  }
96  }
97 
98  if ((new_name = _zip_string_get(same_as_orig ? e->orig->filename : str, NULL, 0, &za->error)) == NULL) {
100  return -1;
101  }
102 
103  if (e->changes) {
104  old_str = e->changes->filename;
105  }
106  else if (e->orig) {
107  old_str = e->orig->filename;
108  }
109  else {
110  old_str = NULL;
111  }
112 
113  if (old_str) {
114  if ((old_name = _zip_string_get(old_str, NULL, 0, &za->error)) == NULL) {
116  return -1;
117  }
118  }
119  else {
120  old_name = NULL;
121  }
122 
123  if (_zip_hash_add(za->names, new_name, idx, 0, &za->error) == false) {
125  return -1;
126  }
127  if (old_name) {
128  _zip_hash_delete(za->names, old_name, NULL);
129  }
130 
131  if (same_as_orig) {
132  if (e->changes) {
133  if (e->changes->changed & ZIP_DIRENT_FILENAME) {
134  _zip_string_free(e->changes->filename);
135  e->changes->changed &= ~ZIP_DIRENT_FILENAME;
136  if (e->changes->changed == 0) {
137  _zip_dirent_free(e->changes);
138  e->changes = NULL;
139  }
140  else {
141  /* TODO: what if not cloned? can that happen? */
142  e->changes->filename = e->orig->filename;
143  }
144  }
145  }
147  }
148  else {
149  if (e->changes->changed & ZIP_DIRENT_FILENAME) {
150  _zip_string_free(e->changes->filename);
151  }
152  e->changes->changed |= ZIP_DIRENT_FILENAME;
153  e->changes->filename = str;
154  }
155 
156  return 0;
157 }
bool _zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *name, zip_error_t *error)
Definition: zip_hash.c:264
int _zip_string_equal(const zip_string_t *a, const zip_string_t *b)
Definition: zip_string.c:55
#define ZIP_FL_ENCODING_ALL
Definition: zipint.h:249

References _zip_dirent_clone(), _zip_dirent_free(), _zip_guess_encoding(), _zip_hash_add(), _zip_hash_delete(), _zip_name_locate(), _zip_string_equal(), _zip_string_free(), _zip_string_get(), _zip_string_new(), e, zip::entry, zip::error, flags, i, setup::idx, zip::names, zip::nentry, NULL, cmd_descs_generate::str, za, ZIP_DIRENT_FILENAME, ZIP_ENCODING_UNKNOWN, ZIP_ENCODING_UTF8_GUESSED, ZIP_ENCODING_UTF8_KNOWN, ZIP_ER_EXISTS, ZIP_ER_INVAL, ZIP_ER_MEMORY, ZIP_ER_RDONLY, zip_error_set(), ZIP_FL_ENC_GUESS, ZIP_FL_ENCODING_ALL, and ZIP_IS_RDONLY.

Referenced by _zip_file_replace(), and zip_file_rename().

◆ _zip_set_open_error()

void _zip_set_open_error ( int zep,
const zip_error_t err,
int  ze 
)

Definition at line 217 of file zip_open.c.

217  {
218  if (err) {
219  ze = zip_error_code_zip(err);
220  switch (zip_error_system_type(err)) {
221  case ZIP_ET_SYS:
222  case ZIP_ET_LIBZIP:
223  errno = zip_error_code_system(err);
224  break;
225 
226  default:
227  break;
228  }
229  }
230 
231  if (zep)
232  *zep = ze;
233 }
ZIP_EXTERN int zip_error_code_system(const zip_error_t *_Nonnull)
Definition: zip_error.c:40
#define ZIP_ET_LIBZIP
Definition: zip.h:144
#define ZIP_ET_SYS
Definition: zip.h:142
ZIP_EXTERN int zip_error_system_type(const zip_error_t *_Nonnull)
Definition: zip_error.c:83

References err, zip_error_code_system(), zip_error_code_zip(), zip_error_system_type(), ZIP_ET_LIBZIP, and ZIP_ET_SYS.

Referenced by zip_fdopen(), and zip_open().

◆ _zip_source_call()

zip_int64_t _zip_source_call ( zip_source_t src,
void *  data,
zip_uint64_t  length,
zip_source_cmd_t  command 
)

Definition at line 39 of file zip_source_call.c.

39  {
40  zip_int64_t ret;
41 
42  if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) {
43  zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
44  return -1;
45  }
46 
47  if (src->src == NULL) {
48  ret = src->cb.f(src->ud, data, length, command);
49  }
50  else {
51  ret = src->cb.l(src->src, src->ud, data, length, command);
52  }
53 
54  if (ret < 0) {
56  int e[2];
57 
58  if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) {
59  zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
60  }
61  else {
62  zip_error_set(&src->error, e[0], e[1]);
63  }
64  }
65  }
66 
67  return ret;
68 }
#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd)
Definition: zip.h:243
@ ZIP_SOURCE_SUPPORTS
Definition: zip.h:234
@ ZIP_SOURCE_ERROR
Definition: zip.h:224
#define ZIP_ER_OPNOTSUPP
Definition: zip.h:133
const char * command
Definition: main.c:7
zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command)

References command, e, length, NULL, src, ZIP_ER_INTERNAL, ZIP_ER_OPNOTSUPP, zip_error_set(), ZIP_SOURCE_ERROR, ZIP_SOURCE_MAKE_COMMAND_BITMASK, and ZIP_SOURCE_SUPPORTS.

Referenced by zip_source_accept_empty(), zip_source_begin_write(), zip_source_begin_write_cloning(), zip_source_close(), zip_source_commit_write(), zip_source_free(), zip_source_get_file_attributes(), zip_source_open(), zip_source_read(), zip_source_remove(), zip_source_rollback_write(), zip_source_seek(), zip_source_seek_write(), zip_source_stat(), zip_source_tell(), zip_source_tell_write(), and zip_source_write().

◆ _zip_source_eof()

bool _zip_source_eof ( zip_source_t src)

Definition at line 94 of file zip_source_read.c.

94  {
95  return src->eof;
96 }

References src.

Referenced by zip_source_read().

◆ _zip_source_file_or_p()

zip_source_t* _zip_source_file_or_p ( const char *  ,
FILE *  ,
zip_uint64_t  ,
zip_int64_t  ,
const zip_stat_t ,
zip_error_t error 
)

◆ _zip_source_had_error()

bool _zip_source_had_error ( zip_source_t src)

Definition at line 44 of file zip_source_error.c.

44  {
46 }
zip_error_t * zip_source_error(zip_source_t *src)

References src, ZIP_ER_OK, zip_error::zip_err, and zip_source_error().

◆ _zip_source_invalidate()

void _zip_source_invalidate ( zip_source_t src)

Definition at line 129 of file zip_source_window.c.

129  {
130  src->source_closed = 1;
131 
132  if (zip_error_code_zip(&src->error) == ZIP_ER_OK) {
133  zip_error_set(&src->error, ZIP_ER_ZIPCLOSED, 0);
134  }
135 }
#define ZIP_ER_ZIPCLOSED
Definition: zip.h:113

References src, ZIP_ER_OK, ZIP_ER_ZIPCLOSED, zip_error_code_zip(), and zip_error_set().

Referenced by zip_discard().

◆ _zip_source_new()

zip_source_t* _zip_source_new ( zip_error_t error)

Definition at line 76 of file zip_source_function.c.

76  {
78 
79  if ((src = (zip_source_t *)malloc(sizeof(*src))) == NULL) {
81  return NULL;
82  }
83 
84  src->src = NULL;
85  src->cb.f = NULL;
86  src->ud = NULL;
87  src->open_count = 0;
88  src->write_state = ZIP_SOURCE_WRITE_CLOSED;
89  src->source_closed = false;
90  src->source_archive = NULL;
91  src->refcount = 1;
92  zip_error_init(&src->error);
93  src->eof = false;
94  src->had_read_error = false;
95  src->bytes_read = 0;
96 
97  return src;
98 }

References error(), malloc(), NULL, src, ZIP_ER_MEMORY, zip_error_init(), zip_error_set(), and ZIP_SOURCE_WRITE_CLOSED.

Referenced by zip_source_function_create(), and zip_source_layered_create().

◆ _zip_source_set_source_archive()

int _zip_source_set_source_archive ( zip_source_t src,
zip_t za 
)

Definition at line 121 of file zip_source_window.c.

121  {
122  src->source_archive = za;
123  return _zip_register_source(za, src);
124 }
int _zip_register_source(zip_t *za, zip_source_t *src)

References _zip_register_source(), src, and za.

Referenced by _zip_source_zip_new().

◆ _zip_source_window_new()

zip_source_t* _zip_source_window_new ( zip_source_t src,
zip_uint64_t  start,
zip_int64_t  length,
zip_stat_t st,
zip_file_attributes_t attributes,
zip_t source_archive,
zip_uint64_t  source_index,
zip_error_t error 
)

Definition at line 68 of file zip_source_window.c.

68  {
69  struct window *ctx;
70 
71  if (src == NULL || length < -1 || (source_archive == NULL && source_index != 0)) {
73  return NULL;
74  }
75 
76  if (length >= 0) {
77  if (start + (zip_uint64_t)length < start) {
79  return NULL;
80  }
81  }
82 
83  if ((ctx = (struct window *)malloc(sizeof(*ctx))) == NULL) {
85  return NULL;
86  }
87 
88  ctx->start = start;
89  if (length == -1) {
90  ctx->end_valid = false;
91  }
92  else {
93  ctx->end = start + (zip_uint64_t)length;
94  ctx->end_valid = true;
95  }
96  zip_stat_init(&ctx->stat);
97  if (attributes != NULL) {
98  memcpy(&ctx->attributes, attributes, sizeof(ctx->attributes));
99  }
100  else {
101  zip_file_attributes_init(&ctx->attributes);
102  }
103  ctx->source_archive = source_archive;
104  ctx->source_index = source_index;
107  ctx->needs_seek = (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) ? true : false;
108 
109  if (st) {
110  if (_zip_stat_merge(&ctx->stat, st, error) < 0) {
111  free(ctx);
112  return NULL;
113  }
114  }
115 
117 }
#define ZIP_SOURCE_SUPPORTS_SEEKABLE
Definition: zip.h:256
ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *_Nonnull)
@ ZIP_SOURCE_GET_FILE_ATTRIBUTES
Definition: zip.h:239
@ ZIP_SOURCE_SEEK
Definition: zip.h:226
@ ZIP_SOURCE_TELL
Definition: zip.h:227
ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t,...)
zip_error_t * error
zip_t * source_archive
zip_uint64_t source_index
zip_file_attributes_t attributes
zip_source_t * zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error)
zip_int64_t zip_source_supports(zip_source_t *src)
static zip_int64_t window_read(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t)
int _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error)
Definition: zip_stat_init.c:54

References _zip_stat_merge(), window::attributes, ctx::error, error(), free(), length, malloc(), memcpy(), NULL, window::source_archive, window::source_index, src, start, window_read(), ZIP_ER_INVAL, ZIP_ER_MEMORY, zip_error_init(), zip_error_set(), zip_file_attributes_init(), ZIP_SOURCE_GET_FILE_ATTRIBUTES, zip_source_layered_create(), zip_source_make_command_bitmap(), ZIP_SOURCE_MAKE_COMMAND_BITMASK, ZIP_SOURCE_SEEK, ZIP_SOURCE_SUPPORTS, zip_source_supports(), ZIP_SOURCE_SUPPORTS_SEEKABLE, ZIP_SOURCE_TELL, and zip_stat_init().

Referenced by _zip_source_zip_new(), add_data(), and zip_source_window_create().

◆ _zip_source_zip_new()

zip_source_t* _zip_source_zip_new ( zip_t srcza,
zip_uint64_t  srcidx,
zip_flags_t  flags,
zip_uint64_t  start,
zip_uint64_t  len,
const char *  password,
zip_error_t error 
)

Definition at line 41 of file zip_source_zip_new.c.

41  {
42  zip_source_t *src, *s2;
43  zip_stat_t st;
44  zip_file_attributes_t attributes;
45  zip_dirent_t *de;
46  bool partial_data, needs_crc, needs_decrypt, needs_decompress;
47 
48  if (srcza == NULL || srcidx >= srcza->nentry || len > ZIP_INT64_MAX) {
50  return NULL;
51  }
52 
53  if ((flags & ZIP_FL_UNCHANGED) == 0 && (ZIP_ENTRY_DATA_CHANGED(srcza->entry + srcidx) || srcza->entry[srcidx].deleted)) {
55  return NULL;
56  }
57 
58  if (zip_stat_index(srcza, srcidx, flags | ZIP_FL_UNCHANGED, &st) < 0) {
60  return NULL;
61  }
62 
63  if (flags & ZIP_FL_ENCRYPTED) {
65  }
66 
67  if ((start > 0 || len > 0) && (flags & ZIP_FL_COMPRESSED)) {
69  return NULL;
70  }
71 
72  /* overflow or past end of file */
73  if ((start > 0 || len > 0) && (start + len < start || start + len > st.size)) {
75  return NULL;
76  }
77 
78  if (len == 0) {
79  len = st.size - start;
80  }
81 
82  partial_data = len < st.size;
83  needs_decrypt = ((flags & ZIP_FL_ENCRYPTED) == 0) && (st.encryption_method != ZIP_EM_NONE);
84  needs_decompress = ((flags & ZIP_FL_COMPRESSED) == 0) && (st.comp_method != ZIP_CM_STORE);
85  /* when reading the whole file, check for CRC errors */
86  needs_crc = ((flags & ZIP_FL_COMPRESSED) == 0 || st.comp_method == ZIP_CM_STORE) && !partial_data;
87 
88  if (needs_decrypt) {
89  if (password == NULL) {
90  password = srcza->default_password;
91  }
92  if (password == NULL) {
94  return NULL;
95  }
96  }
97 
98  if ((de = _zip_get_dirent(srcza, srcidx, flags, error)) == NULL) {
99  return NULL;
100  }
101  _zip_file_attributes_from_dirent(&attributes, de);
102 
103  if (st.comp_size == 0) {
104  return zip_source_buffer_with_attributes_create(NULL, 0, 0, &attributes, error);
105  }
106 
107  if (partial_data && !needs_decrypt && !needs_decompress) {
108  struct zip_stat st2;
109 
110  st2.size = len;
111  st2.comp_size = len;
112  st2.comp_method = ZIP_CM_STORE;
113  st2.mtime = st.mtime;
115 
116  if ((src = _zip_source_window_new(srcza->src, start, (zip_int64_t)len, &st2, &attributes, srcza, srcidx, error)) == NULL) {
117  return NULL;
118  }
119  }
120  else {
121  if (st.comp_size > ZIP_INT64_MAX) {
123  return NULL;
124  }
125  if ((src = _zip_source_window_new(srcza->src, 0, (zip_int64_t)st.comp_size, &st, &attributes, srcza, srcidx, error)) == NULL) {
126  return NULL;
127  }
128  }
129 
130  if (_zip_source_set_source_archive(src, srcza) < 0) {
132  return NULL;
133  }
134 
135  /* creating a layered source calls zip_keep() on the lower layer, so we free it */
136 
137  if (needs_decrypt) {
139 
142  return NULL;
143  }
144 
145  s2 = enc_impl(srcza, src, st.encryption_method, 0, password);
147  if (s2 == NULL) {
148  return NULL;
149  }
150  src = s2;
151  }
152  if (needs_decompress) {
153  s2 = zip_source_decompress(srcza, src, st.comp_method);
155  if (s2 == NULL) {
156  return NULL;
157  }
158  src = s2;
159  }
160  if (needs_crc) {
163  if (s2 == NULL) {
164  return NULL;
165  }
166  src = s2;
167  }
168 
169  if (partial_data && (needs_decrypt || needs_decompress)) {
172  if (s2 == NULL) {
173  return NULL;
174  }
175  src = s2;
176  }
177 
178  return src;
179 }
#define ZIP_CM_STORE
Definition: zip.h:149
#define ZIP_ER_CHANGED
Definition: zip.h:120
#define ZIP_ER_NOPASSWD
Definition: zip.h:131
#define ZIP_FL_COMPRESSED
Definition: zip.h:78
#define ZIP_STAT_COMP_METHOD
Definition: zip.h:296
#define ZIP_ER_ENCRNOTSUPP
Definition: zip.h:129
#define ZIP_FL_ENCRYPTED
Definition: zip.h:81
#define ZIP_STAT_COMP_SIZE
Definition: zip.h:293
#define ZIP_STAT_MTIME
Definition: zip.h:294
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable)
ZIP_EXTERN int zip_stat_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_stat_t *_Nonnull)
ZIP_EXTERN zip_source_t *_Nullable zip_source_window_create(zip_source_t *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable)
time_t mtime
Definition: zip.h:306
zip_uint16_t encryption_method
Definition: zip.h:309
zip_uint16_t comp_method
Definition: zip.h:308
zip_uint64_t comp_size
Definition: zip.h:305
zip_uint64_t size
Definition: zip.h:304
zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t em, int operation)
zip_source_t * zip_source_buffer_with_attributes_create(const void *data, zip_uint64_t len, int freep, zip_file_attributes_t *attributes, zip_error_t *error)
zip_source_t * zip_source_decompress(zip_t *za, zip_source_t *src, zip_int32_t method)
zip_source_t * zip_source_crc_create(zip_source_t *src, int validate, zip_error_t *error)
int _zip_source_set_source_archive(zip_source_t *src, zip_t *za)
zip_source_t * _zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_int64_t length, zip_stat_t *st, zip_file_attributes_t *attributes, zip_t *source_archive, zip_uint64_t source_index, zip_error_t *error)
static void _zip_file_attributes_from_dirent(zip_file_attributes_t *attributes, zip_dirent_t *de)
zip_source_t *(* zip_encryption_implementation)(zip_t *, zip_source_t *, zip_uint16_t, int, const char *)
Definition: zipint.h:110
#define ZIP_ENTRY_DATA_CHANGED(x)
Definition: zipint.h:476

References _zip_file_attributes_from_dirent(), _zip_get_dirent(), _zip_get_encryption_implementation(), _zip_source_set_source_archive(), _zip_source_window_new(), zip_stat::comp_method, zip_stat::comp_size, zip::default_password, zip_entry::deleted, zip_stat::encryption_method, zip::entry, error(), flags, len, zip_stat::mtime, zip::nentry, NULL, s2, zip_stat::size, zip::src, src, start, zip_stat::valid, ZIP_CM_STORE, ZIP_CODEC_DECODE, ZIP_EM_NONE, ZIP_ENTRY_DATA_CHANGED, ZIP_ER_CHANGED, ZIP_ER_ENCRNOTSUPP, ZIP_ER_INTERNAL, ZIP_ER_INVAL, ZIP_ER_NOPASSWD, zip_error_set(), ZIP_FL_COMPRESSED, ZIP_FL_ENCRYPTED, ZIP_FL_UNCHANGED, ZIP_INT64_MAX, zip_source_buffer_with_attributes_create(), zip_source_crc_create(), zip_source_decompress(), zip_source_free(), zip_source_window_create(), ZIP_STAT_COMP_METHOD, ZIP_STAT_COMP_SIZE, zip_stat_index(), ZIP_STAT_MTIME, and ZIP_STAT_SIZE.

Referenced by zip_close(), zip_fopen_index_encrypted(), and zip_source_zip_create().

◆ _zip_stat_merge()

int _zip_stat_merge ( zip_stat_t dst,
const zip_stat_t src,
zip_error_t error 
)

Definition at line 54 of file zip_stat_init.c.

54  {
55  /* name is not merged, since zip_stat_t doesn't own it, and src may not be valid as long as dst */
56  if (src->valid & ZIP_STAT_INDEX) {
57  dst->index = src->index;
58  }
59  if (src->valid & ZIP_STAT_SIZE) {
60  dst->size = src->size;
61  }
62  if (src->valid & ZIP_STAT_COMP_SIZE) {
63  dst->comp_size = src->comp_size;
64  }
65  if (src->valid & ZIP_STAT_MTIME) {
66  dst->mtime = src->mtime;
67  }
68  if (src->valid & ZIP_STAT_CRC) {
69  dst->crc = src->crc;
70  }
71  if (src->valid & ZIP_STAT_COMP_METHOD) {
72  dst->comp_method = src->comp_method;
73  }
74  if (src->valid & ZIP_STAT_ENCRYPTION_METHOD) {
75  dst->encryption_method = src->encryption_method;
76  }
77  if (src->valid & ZIP_STAT_FLAGS) {
78  dst->flags = src->flags;
79  }
80  dst->valid |= src->valid;
81 
82  return 0;
83 }
#define ZIP_STAT_ENCRYPTION_METHOD
Definition: zip.h:297
#define ZIP_STAT_INDEX
Definition: zip.h:291
#define ZIP_STAT_CRC
Definition: zip.h:295
#define ZIP_STAT_FLAGS
Definition: zip.h:298

References dst, src, ZIP_STAT_COMP_METHOD, ZIP_STAT_COMP_SIZE, ZIP_STAT_CRC, ZIP_STAT_ENCRYPTION_METHOD, ZIP_STAT_FLAGS, ZIP_STAT_INDEX, ZIP_STAT_MTIME, and ZIP_STAT_SIZE.

Referenced by _zip_source_window_new(), and window_read().

◆ _zip_string_crc32()

zip_uint32_t _zip_string_crc32 ( const zip_string_t string)

Definition at line 42 of file zip_string.c.

42  {
43  zip_uint32_t crc;
44 
45  crc = (zip_uint32_t)crc32(0L, Z_NULL, 0);
46 
47  if (s != NULL)
48  crc = (zip_uint32_t)crc32(crc, s->raw, s->length);
49 
50  return crc;
51 }
#define L
Definition: zip_err_str.c:7
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:1063
#define Z_NULL
Definition: zlib.h:212

References crc32(), L, NULL, s, and Z_NULL.

Referenced by _zip_dirent_process_ef_utf_8(), and _zip_ef_utf8().

◆ _zip_string_equal()

int _zip_string_equal ( const zip_string_t a,
const zip_string_t b 
)

Definition at line 55 of file zip_string.c.

55  {
56  if (a == NULL || b == NULL)
57  return a == b;
58 
59  if (a->length != b->length)
60  return 0;
61 
62  /* TODO: encoding */
63 
64  return (memcmp(a->raw, b->raw, a->length) == 0);
65 }
#define a(i)
Definition: sha256.c:41

References a, b, and NULL.

Referenced by _zip_headercomp(), _zip_set_name(), zip_file_set_comment(), and zip_set_archive_comment().

◆ _zip_string_free()

void _zip_string_free ( zip_string_t string)

Definition at line 69 of file zip_string.c.

69  {
70  if (s == NULL)
71  return;
72 
73  free(s->raw);
74  free(s->converted);
75  free(s);
76 }

References free(), NULL, and s.

Referenced by _zip_cdir_free(), _zip_dirent_finalize(), _zip_dirent_process_ef_utf_8(), _zip_name_locate(), _zip_set_name(), _zip_string_new(), zip_discard(), zip_file_set_comment(), zip_set_archive_comment(), and zip_unchange_archive().

◆ _zip_string_get()

const zip_uint8_t* _zip_string_get ( zip_string_t string,
zip_uint32_t lenp,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 80 of file zip_string.c.

80  {
81  static const zip_uint8_t empty[1] = "";
82 
83  if (string == NULL) {
84  if (lenp)
85  *lenp = 0;
86  return empty;
87  }
88 
89  if ((flags & ZIP_FL_ENC_RAW) == 0) {
90  /* start guessing */
91  if (string->encoding == ZIP_ENCODING_UNKNOWN)
93 
94  if (((flags & ZIP_FL_ENC_STRICT) && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN) || (string->encoding == ZIP_ENCODING_CP437)) {
95  if (string->converted == NULL) {
96  if ((string->converted = _zip_cp437_to_utf8(string->raw, string->length, &string->converted_length, error)) == NULL)
97  return NULL;
98  }
99  if (lenp)
100  *lenp = string->converted_length;
101  return string->converted;
102  }
103  }
104 
105  if (lenp)
106  *lenp = string->length;
107  return string->raw;
108 }
enum zip_encoding_type encoding
Definition: zipint.h:421
zip_uint32_t converted_length
Definition: zipint.h:423
zip_uint8_t * converted
Definition: zipint.h:422
zip_uint8_t * _zip_cp437_to_utf8(const zip_uint8_t *const _cp437buf, zip_uint32_t len, zip_uint32_t *utf8_lenp, zip_error_t *error)
Definition: zip_utf-8.c:198

References _zip_cp437_to_utf8(), _zip_guess_encoding(), zip_string::converted, zip_string::converted_length, zip_string::encoding, error(), flags, zip_string::length, NULL, zip_string::raw, ZIP_ENCODING_ASCII, ZIP_ENCODING_CP437, ZIP_ENCODING_UNKNOWN, ZIP_ENCODING_UTF8_KNOWN, ZIP_FL_ENC_RAW, and ZIP_FL_ENC_STRICT.

Referenced by _zip_ef_utf8(), _zip_get_name(), _zip_name_locate(), _zip_open(), _zip_set_name(), zip_file_get_comment(), and zip_get_archive_comment().

◆ _zip_string_length()

zip_uint16_t _zip_string_length ( const zip_string_t string)

Definition at line 112 of file zip_string.c.

112  {
113  if (s == NULL)
114  return 0;
115 
116  return s->length;
117 }

References NULL, and s.

Referenced by _zip_checkcons(), _zip_dirent_apply_attributes(), and _zip_dirent_write().

◆ _zip_string_new()

zip_string_t* _zip_string_new ( const zip_uint8_t raw,
zip_uint16_t  length,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 121 of file zip_string.c.

121  {
122  zip_string_t *s;
123  zip_encoding_type_t expected_encoding;
124 
125  if (length == 0)
126  return NULL;
127 
128  switch (flags & ZIP_FL_ENCODING_ALL) {
129  case ZIP_FL_ENC_GUESS:
130  expected_encoding = ZIP_ENCODING_UNKNOWN;
131  break;
132  case ZIP_FL_ENC_UTF_8:
133  expected_encoding = ZIP_ENCODING_UTF8_KNOWN;
134  break;
135  case ZIP_FL_ENC_CP437:
136  expected_encoding = ZIP_ENCODING_CP437;
137  break;
138  default:
140  return NULL;
141  }
142 
143  if ((s = (zip_string_t *)malloc(sizeof(*s))) == NULL) {
145  return NULL;
146  }
147 
148  if ((s->raw = (zip_uint8_t *)malloc((size_t)length + 1)) == NULL) {
149  free(s);
150  return NULL;
151  }
152 
153  memcpy(s->raw, raw, length);
154  s->raw[length] = '\0';
155  s->length = length;
156  s->encoding = ZIP_ENCODING_UNKNOWN;
157  s->converted = NULL;
158  s->converted_length = 0;
159 
160  if (expected_encoding != ZIP_ENCODING_UNKNOWN) {
161  if (_zip_guess_encoding(s, expected_encoding) == ZIP_ENCODING_ERROR) {
164  return NULL;
165  }
166  }
167 
168  return s;
169 }
#define ZIP_FL_ENC_CP437
Definition: zip.h:89

References _zip_guess_encoding(), _zip_string_free(), error(), flags, free(), length, malloc(), memcpy(), NULL, s, ZIP_ENCODING_CP437, ZIP_ENCODING_ERROR, ZIP_ENCODING_UNKNOWN, ZIP_ENCODING_UTF8_KNOWN, ZIP_ER_INVAL, ZIP_ER_MEMORY, zip_error_set(), ZIP_FL_ENC_CP437, ZIP_FL_ENC_GUESS, ZIP_FL_ENC_UTF_8, and ZIP_FL_ENCODING_ALL.

Referenced by _zip_dirent_process_ef_utf_8(), _zip_name_locate(), _zip_read_cdir(), _zip_read_string(), _zip_set_name(), zip_file_set_comment(), and zip_set_archive_comment().

◆ _zip_string_write()

int _zip_string_write ( zip_t za,
const zip_string_t string 
)

Definition at line 173 of file zip_string.c.

173  {
174  if (s == NULL)
175  return 0;
176 
177  return _zip_write(za, s->raw, s->length);
178 }

References _zip_write(), NULL, s, and za.

Referenced by _zip_dirent_write().

◆ _zip_u2d_time()

void _zip_u2d_time ( time_t  intime,
zip_uint16_t dtime,
zip_uint16_t ddate 
)

Definition at line 1090 of file zip_dirent.c.

1090  {
1091  struct tm *tpm;
1092 
1093 #ifdef HAVE_LOCALTIME_R
1094  struct tm tm;
1095  tpm = localtime_r(&intime, &tm);
1096 #else
1097  tpm = localtime(&intime);
1098 #endif
1099  if (tpm == NULL) {
1100  /* if localtime() fails, return an arbitrary date (1980-01-01 00:00:00) */
1101  *ddate = (1 << 5) + 1;
1102  *dtime = 0;
1103  return;
1104  }
1105  if (tpm->tm_year < 80) {
1106  tpm->tm_year = 80;
1107  }
1108 
1109  *ddate = (zip_uint16_t)(((tpm->tm_year + 1900 - 1980) << 9) + ((tpm->tm_mon + 1) << 5) + tpm->tm_mday);
1110  *dtime = (zip_uint16_t)(((tpm->tm_hour) << 11) + ((tpm->tm_min) << 5) + ((tpm->tm_sec) >> 1));
1111 
1112  return;
1113 }

References NULL.

Referenced by _zip_dirent_write(), decrypt_header(), and encrypt_header().

◆ _zip_unchange()

int _zip_unchange ( zip_t za,
zip_uint64_t  idx,
int  allow_duplicates 
)

Definition at line 47 of file zip_unchange.c.

47  {
48  zip_int64_t i;
49  bool renamed;
50 
51  if (idx >= za->nentry) {
53  return -1;
54  }
55 
57  if (!allow_duplicates && (renamed || za->entry[idx].deleted)) {
58  const char *orig_name = NULL;
59  const char *changed_name = NULL;
60 
61  if (za->entry[idx].orig != NULL) {
62  if ((orig_name = _zip_get_name(za, idx, ZIP_FL_UNCHANGED, &za->error)) == NULL) {
63  return -1;
64  }
65 
66  i = _zip_name_locate(za, orig_name, 0, NULL);
67  if (i >= 0 && (zip_uint64_t)i != idx) {
69  return -1;
70  }
71  }
72 
73  if (renamed) {
74  if ((changed_name = _zip_get_name(za, idx, 0, &za->error)) == NULL) {
75  return -1;
76  }
77  }
78 
79  if (orig_name) {
80  if (_zip_hash_add(za->names, (const zip_uint8_t *)orig_name, idx, 0, &za->error) == false) {
81  return -1;
82  }
83  }
84  if (changed_name) {
85  if (_zip_hash_delete(za->names, (const zip_uint8_t *)changed_name, &za->error) == false) {
86  _zip_hash_delete(za->names, (const zip_uint8_t *)orig_name, NULL);
87  return -1;
88  }
89  }
90  }
91 
93  za->entry[idx].changes = NULL;
94 
96 
97  return 0;
98 }

References _zip_dirent_free(), _zip_get_name(), _zip_hash_add(), _zip_hash_delete(), _zip_name_locate(), _zip_unchange_data(), zip_dirent::changed, zip_entry::changes, zip_entry::deleted, zip::entry, zip::error, i, setup::idx, zip::names, zip::nentry, NULL, zip_entry::orig, za, ZIP_DIRENT_FILENAME, ZIP_ER_EXISTS, ZIP_ER_INVAL, zip_error_set(), and ZIP_FL_UNCHANGED.

Referenced by zip_delete(), zip_unchange(), and zip_unchange_all().

◆ _zip_unchange_data()

void _zip_unchange_data ( zip_entry_t ze)

◆ _zip_winzip_aes_decrypt()

bool _zip_winzip_aes_decrypt ( zip_winzip_aes_t ctx,
zip_uint8_t data,
zip_uint64_t  length 
)

Definition at line 142 of file zip_winzip_aes.c.

142  {
143  return _zip_crypto_hmac(ctx->hmac, data, length) && aes_crypt(ctx, data, length);
144 }
#define _zip_crypto_hmac(hmac, data, length)
static bool aes_crypt(zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length)

References _zip_crypto_hmac, aes_crypt(), and length.

Referenced by winzip_aes_decrypt().

◆ _zip_winzip_aes_encrypt()

bool _zip_winzip_aes_encrypt ( zip_winzip_aes_t ctx,
zip_uint8_t data,
zip_uint64_t  length 
)

Definition at line 136 of file zip_winzip_aes.c.

136  {
137  return aes_crypt(ctx, data, length) && _zip_crypto_hmac(ctx->hmac, data, length);
138 }

References _zip_crypto_hmac, aes_crypt(), and length.

Referenced by winzip_aes_encrypt().

◆ _zip_winzip_aes_finish()

bool _zip_winzip_aes_finish ( zip_winzip_aes_t ctx,
zip_uint8_t hmac 
)

Definition at line 148 of file zip_winzip_aes.c.

148  {
149  return _zip_crypto_hmac_output(ctx->hmac, hmac);
150 }
#define _zip_crypto_hmac_output(hmac, data)

References _zip_crypto_hmac_output.

Referenced by verify_hmac(), and winzip_aes_encrypt().

◆ _zip_winzip_aes_free()

void _zip_winzip_aes_free ( zip_winzip_aes_t ctx)

Definition at line 154 of file zip_winzip_aes.c.

154  {
155  if (ctx == NULL) {
156  return;
157  }
158 
160  _zip_crypto_hmac_free(ctx->hmac);
161  free(ctx);
162 }
void _zip_crypto_hmac_free(_zip_crypto_hmac_t *hmac)
void _zip_crypto_aes_free(_zip_crypto_aes_t *aes)

References _zip_crypto_aes_free(), _zip_crypto_hmac_free(), free(), and NULL.

Referenced by decrypt_header(), encrypt_header(), verify_hmac(), winzip_aes_encrypt(), and winzip_aes_free().

◆ _zip_winzip_aes_new()

zip_winzip_aes_t* _zip_winzip_aes_new ( const zip_uint8_t password,
zip_uint64_t  password_length,
const zip_uint8_t salt,
zip_uint16_t  key_size,
zip_uint8_t password_verify,
zip_error_t error 
)

Definition at line 78 of file zip_winzip_aes.c.

78  {
81  zip_uint16_t key_size = 0; /* in bits */
82  zip_uint16_t key_length; /* in bytes */
83 
84  switch (encryption_method) {
85  case ZIP_EM_AES_128:
86  key_size = 128;
87  break;
88  case ZIP_EM_AES_192:
89  key_size = 192;
90  break;
91  case ZIP_EM_AES_256:
92  key_size = 256;
93  break;
94  }
95 
96  if (key_size == 0 || salt == NULL || password == NULL || password_length == 0) {
98  return NULL;
99  }
100 
101  key_length = key_size / 8;
102 
103  if ((ctx = (zip_winzip_aes_t *)malloc(sizeof(*ctx))) == NULL) {
105  return NULL;
106  }
107 
108  memset(ctx->counter, 0, sizeof(ctx->counter));
109  ctx->pad_offset = ZIP_CRYPTO_AES_BLOCK_LENGTH;
110 
111  if (!_zip_crypto_pbkdf2(password, password_length, salt, key_length / 2, PBKDF2_ITERATIONS, buffer, 2 * key_length + WINZIP_AES_PASSWORD_VERIFY_LENGTH)) {
112  free(ctx);
113  return NULL;
114  }
115 
116  if ((ctx->aes = _zip_crypto_aes_new(buffer, key_size, error)) == NULL) {
117  _zip_crypto_clear(ctx, sizeof(*ctx));
118  free(ctx);
119  return NULL;
120  }
121  if ((ctx->hmac = _zip_crypto_hmac_new(buffer + key_length, key_length, error)) == NULL) {
123  free(ctx);
124  return NULL;
125  }
126 
127  if (password_verify) {
128  memcpy(password_verify, buffer + (2 * key_size / 8), WINZIP_AES_PASSWORD_VERIFY_LENGTH);
129  }
130 
131  return ctx;
132 }
#define ZIP_CRYPTO_AES_BLOCK_LENGTH
Definition: zip_crypto.h:38
_zip_crypto_aes_t * _zip_crypto_aes_new(const zip_uint8_t *key, zip_uint16_t key_size, zip_error_t *error)
_zip_crypto_hmac_t * _zip_crypto_hmac_new(const zip_uint8_t *secret, zip_uint64_t secret_length, zip_error_t *error)
#define _zip_crypto_pbkdf2(key, key_length, salt, salt_length, iterations, output, output_length)
#define MAX_KEY_LENGTH
#define PBKDF2_ITERATIONS
#define WINZIP_AES_PASSWORD_VERIFY_LENGTH
Definition: zipint.h:75

References _zip_crypto_aes_free(), _zip_crypto_aes_new(), _zip_crypto_clear, _zip_crypto_hmac_new(), _zip_crypto_pbkdf2, error(), free(), malloc(), MAX_KEY_LENGTH, memcpy(), memset(), NULL, PBKDF2_ITERATIONS, WINZIP_AES_PASSWORD_VERIFY_LENGTH, ZIP_CRYPTO_AES_BLOCK_LENGTH, ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_ER_INVAL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by decrypt_header(), and encrypt_header().

◆ _zip_write()

int _zip_write ( zip_t za,
const void *  data,
zip_uint64_t  length 
)

Definition at line 121 of file zip_io_util.c.

121  {
122  zip_int64_t n;
123 
124  if ((n = zip_source_write(za->src, data, length)) < 0) {
126  return -1;
127  }
128  if ((zip_uint64_t)n != length) {
130  return -1;
131  }
132 
133  return 0;
134 }
#define ZIP_ER_WRITE
Definition: zip.h:111
ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *_Nonnull, const void *_Nullable, zip_uint64_t)
#define EINTR
Definition: sftypes.h:114

References _zip_error_set_from_source(), EINTR, zip::error, length, n, zip::src, za, ZIP_ER_WRITE, zip_error_set(), and zip_source_write().

Referenced by _zip_cdir_write(), _zip_dirent_write(), _zip_ef_write(), _zip_string_write(), copy_data(), copy_source(), and write_data_descriptor().

◆ zip_get_extra_field_by_id()

const zip_uint8_t* zip_get_extra_field_by_id ( zip_t ,
int  ,
int  ,
zip_uint16_t  ,
int  ,
zip_uint16_t  
)

◆ zip_random_uint32()

zip_uint32_t zip_random_uint32 ( void  )

Definition at line 87 of file zip_random_unix.c.

87  {
88  static bool seeded = false;
89 
91 
92  if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
93  return value;
94  }
95 
96  if (!seeded) {
97  srandom((unsigned int)time(NULL));
98  }
99 
100  return (zip_uint32_t)random();
101 }
static int value
Definition: cmd_api.c:93
static static fork const void static count static fd const char const char static newpath char char char static envp time
Definition: sflib.h:42
ZIP_EXTERN bool zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length)

References NULL, time, value, and zip_secure_random().

Referenced by create_temp_file().

◆ zip_secure_random()

ZIP_EXTERN bool zip_secure_random ( zip_uint8_t buffer,
zip_uint16_t  length 
)

Definition at line 132 of file zip_crypto_gnutls.c.

132  {
133  return gnutls_rnd(GNUTLS_RND_KEY, buffer, length) == 0;
134 }

References close, fd, free(), length, malloc(), memset(), NULL, O_RDONLY, and read().

Referenced by encrypt_header(), main(), and zip_random_uint32().

◆ zip_source_accept_empty()

bool zip_source_accept_empty ( zip_source_t src)

Definition at line 39 of file zip_source_accept_empty.c.

39  {
40  int ret;
41 
44  return zip_source_accept_empty(src->src);
45  }
46  return true;
47  }
48 
50 
51  return ret != 0;
52 }
@ ZIP_SOURCE_ACCEPT_EMPTY
Definition: zip.h:238
#define ZIP_SOURCE_IS_LAYERED(src)
Definition: zipint.h:404

References _zip_source_call(), int, NULL, src, ZIP_SOURCE_ACCEPT_EMPTY, ZIP_SOURCE_IS_LAYERED, ZIP_SOURCE_MAKE_COMMAND_BITMASK, and zip_source_supports().

Referenced by _zip_open().

◆ zip_source_buffer_with_attributes()

zip_source_t* zip_source_buffer_with_attributes ( zip_t za,
const void *  data,
zip_uint64_t  len,
int  freep,
zip_file_attributes_t attributes 
)

Definition at line 180 of file zip_source_buffer.c.

180  {
181  return zip_source_buffer_with_attributes_create(data, len, freep, attributes, &za->error);
182 }

References read_data::attributes, zip::error, len, za, and zip_source_buffer_with_attributes_create().

◆ zip_source_buffer_with_attributes_create()

zip_source_t* zip_source_buffer_with_attributes_create ( const void *  data,
zip_uint64_t  len,
int  freep,
zip_file_attributes_t attributes,
zip_error_t error 
)

Definition at line 103 of file zip_source_buffer.c.

103  {
104  zip_buffer_fragment_t fragment;
105 
106  if (data == NULL) {
107  if (len > 0) {
109  return NULL;
110  }
111 
112  return zip_source_buffer_fragment_with_attributes_create(NULL, 0, freep, attributes, error);
113  }
114 
115  fragment.data = (zip_uint8_t *)data;
116  fragment.length = len;
117 
118  return zip_source_buffer_fragment_with_attributes_create(&fragment, 1, freep, attributes, error);
119 }
zip_uint64_t length
Definition: zip.h:315
zip_uint8_t *_Nonnull data
Definition: zip.h:314
zip_source_t * zip_source_buffer_fragment_with_attributes_create(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep, zip_file_attributes_t *attributes, zip_error_t *error)

References zip_buffer_fragment::data, error(), len, zip_buffer_fragment::length, NULL, ZIP_ER_INVAL, zip_error_set(), and zip_source_buffer_fragment_with_attributes_create().

Referenced by _zip_source_zip_new(), zip_source_buffer(), zip_source_buffer_create(), and zip_source_buffer_with_attributes().

◆ zip_source_compress()

zip_source_t* zip_source_compress ( zip_t za,
zip_source_t src,
zip_int32_t  cm,
int  compression_flags 
)

Definition at line 120 of file zip_source_compress.c.

120  {
121  return compression_source_new(za, src, method, true, compression_flags);
122 }
static zip_source_t * compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, int compression_flags)

References compression_source_new(), context::method, src, and za.

Referenced by add_data().

◆ zip_source_crc_create()

zip_source_t* zip_source_crc_create ( zip_source_t src,
int  validate,
zip_error_t error 
)

Definition at line 55 of file zip_source_crc.c.

55  {
56  struct crc_context *ctx;
57 
58  if (src == NULL) {
60  return NULL;
61  }
62 
63  if ((ctx = (struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
65  return NULL;
66  }
67 
69  ctx->validate = validate;
70  ctx->crc_complete = 0;
71  ctx->crc_position = 0;
72  ctx->crc = (zip_uint32_t)crc32(0, NULL, 0);
73  ctx->size = 0;
74 
76 }
static int validate(const char *const tag)
Definition: checkTag.c:46
static zip_int64_t crc_read(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t)

References crc32(), crc_read(), ctx::error, error(), malloc(), NULL, src, validate(), ZIP_ER_INVAL, ZIP_ER_MEMORY, zip_error_init(), zip_error_set(), and zip_source_layered_create().

Referenced by _zip_source_zip_new(), and add_data().

◆ zip_source_decompress()

zip_source_t* zip_source_decompress ( zip_t za,
zip_source_t src,
zip_int32_t  cm 
)

Definition at line 125 of file zip_source_compress.c.

125  {
126  return compression_source_new(za, src, method, false, 0);
127 }

References compression_source_new(), context::method, src, and za.

Referenced by _zip_source_zip_new(), and add_data().

◆ zip_source_layered()

zip_source_t* zip_source_layered ( zip_t za,
zip_source_t src,
zip_source_layered_callback  cb,
void *  ud 
)

Definition at line 41 of file zip_source_layered.c.

41  {
42  if (za == NULL)
43  return NULL;
44 
45  return zip_source_layered_create(src, cb, ud, &za->error);
46 }
static const char * cb[]
Definition: z80_tab.h:176

References cb, zip::error, NULL, src, za, and zip_source_layered_create().

Referenced by compression_source_new(), zip_source_pkware_decode(), zip_source_pkware_encode(), zip_source_winzip_aes_decode(), and zip_source_winzip_aes_encode().

◆ zip_source_layered_create()

zip_source_t* zip_source_layered_create ( zip_source_t src,
zip_source_layered_callback  cb,
void *  ud,
zip_error_t error 
)

Definition at line 50 of file zip_source_layered.c.

50  {
51  zip_source_t *zs;
52 
53  if ((zs = _zip_source_new(error)) == NULL)
54  return NULL;
55 
57  zs->src = src;
58  zs->cb.l = cb;
59  zs->ud = ud;
60 
61  zs->supports = cb(src, ud, NULL, 0, ZIP_SOURCE_SUPPORTS);
62  if (zs->supports < 0) {
64  }
65 
66  return zs;
67 }
#define ZIP_SOURCE_SUPPORTS_READABLE
Definition: zip.h:249
zip_source_t * src
Definition: zipint.h:384
zip_source_layered_callback l
Definition: zipint.h:387
void * ud
Definition: zipint.h:389
union zip_source::@410 cb
zip_int64_t supports
Definition: zipint.h:391
zip_source_t * _zip_source_new(zip_error_t *error)

References _zip_source_new(), cb, zip_source::cb, error(), zip_source::l, NULL, zip_source::src, src, zip_source::supports, zip_source::ud, zip_source_keep(), ZIP_SOURCE_SUPPORTS, and ZIP_SOURCE_SUPPORTS_READABLE.

Referenced by _zip_source_window_new(), zip_source_crc_create(), and zip_source_layered().

◆ zip_source_pkware_decode()

zip_source_t* zip_source_pkware_decode ( zip_t za,
zip_source_t src,
zip_uint16_t  em,
int  flags,
const char *  password 
)

Definition at line 54 of file zip_source_pkware_decode.c.

54  {
55  struct trad_pkware *ctx;
57 
58  if (password == NULL || src == NULL || em != ZIP_EM_TRAD_PKWARE) {
60  return NULL;
61  }
62  if (flags & ZIP_CODEC_ENCODE) {
64  return NULL;
65  }
66 
67  if ((ctx = trad_pkware_new(password, &za->error)) == NULL) {
68  return NULL;
69  }
70 
73  return NULL;
74  }
75 
76  return s2;
77 }
zip_source_t * zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud)
static zip_int64_t pkware_decrypt(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t)
static struct trad_pkware * trad_pkware_new(const char *password, zip_error_t *error)
static void trad_pkware_free(struct trad_pkware *)
#define ZIP_CODEC_ENCODE
Definition: zipint.h:108

References zip::error, flags, NULL, trad_pkware::password, pkware_decrypt(), s2, src, trad_pkware_free(), trad_pkware_new(), za, ZIP_CODEC_ENCODE, ZIP_EM_TRAD_PKWARE, ZIP_ER_ENCRNOTSUPP, ZIP_ER_INVAL, zip_error_set(), and zip_source_layered().

Referenced by _zip_get_encryption_implementation().

◆ zip_source_pkware_encode()

zip_source_t* zip_source_pkware_encode ( zip_t za,
zip_source_t src,
zip_uint16_t  em,
int  flags,
const char *  password 
)

Definition at line 56 of file zip_source_pkware_encode.c.

56  {
57  struct trad_pkware *ctx;
59 
60  if (password == NULL || src == NULL || em != ZIP_EM_TRAD_PKWARE) {
62  return NULL;
63  }
64  if (!(flags & ZIP_CODEC_ENCODE)) {
66  return NULL;
67  }
68 
69  if ((ctx = trad_pkware_new(password, &za->error)) == NULL) {
70  return NULL;
71  }
72 
75  return NULL;
76  }
77 
78  return s2;
79 }
static zip_int64_t pkware_encrypt(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t)
static struct trad_pkware * trad_pkware_new(const char *password, zip_error_t *error)
static void trad_pkware_free(struct trad_pkware *)

References zip::error, flags, NULL, trad_pkware::password, pkware_encrypt(), s2, src, trad_pkware_free(), trad_pkware_new(), za, ZIP_CODEC_ENCODE, ZIP_EM_TRAD_PKWARE, ZIP_ER_ENCRNOTSUPP, ZIP_ER_INVAL, zip_error_set(), and zip_source_layered().

Referenced by _zip_get_encryption_implementation().

◆ zip_source_remove()

int zip_source_remove ( zip_source_t src)

Definition at line 39 of file zip_source_remove.c.

39  {
40  if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
41  return 0;
42  }
43 
45  if (zip_source_close(src) < 0) {
46  return -1;
47  }
48  }
49  if (src->write_state != ZIP_SOURCE_WRITE_CLOSED) {
51  }
52 
54  return -1;
55  }
56 
57  src->write_state = ZIP_SOURCE_WRITE_REMOVED;
58 
59  return 0;
60 }
ZIP_EXTERN int zip_source_close(zip_source_t *_Nonnull)
ZIP_EXTERN void zip_source_rollback_write(zip_source_t *_Nonnull)
@ ZIP_SOURCE_REMOVE
Definition: zip.h:235
#define ZIP_SOURCE_IS_OPEN_READING(src)
Definition: zipint.h:402

References _zip_source_call(), NULL, src, zip_source_close(), ZIP_SOURCE_IS_OPEN_READING, ZIP_SOURCE_REMOVE, zip_source_rollback_write(), ZIP_SOURCE_WRITE_CLOSED, and ZIP_SOURCE_WRITE_REMOVED.

Referenced by zip_close().

◆ zip_source_supports()

zip_int64_t zip_source_supports ( zip_source_t src)

Definition at line 41 of file zip_source_supports.c.

41  {
42  return src->supports;
43 }

References src.

Referenced by _zip_source_window_new(), crc_read(), zip_close(), zip_file_is_seekable(), zip_open_from_source(), zip_source_accept_empty(), and zip_source_open().

◆ zip_source_winzip_aes_decode()

zip_source_t* zip_source_winzip_aes_decode ( zip_t za,
zip_source_t src,
zip_uint16_t  encryption_method,
int  flags,
const char *  password 
)

Definition at line 59 of file zip_source_winzip_aes_decode.c.

59  {
61  zip_stat_t st;
62  zip_uint64_t aux_length;
63  struct winzip_aes *ctx;
64 
67  return NULL;
68  }
69  if (flags & ZIP_CODEC_ENCODE) {
71  return NULL;
72  }
73 
74  if (zip_source_stat(src, &st) != 0) {
76  return NULL;
77  }
78 
80 
81  if ((st.valid & ZIP_STAT_COMP_SIZE) == 0 || st.comp_size < aux_length) {
83  return NULL;
84  }
85 
87  return NULL;
88  }
89 
90  ctx->data_length = st.comp_size - aux_length;
91 
94  return NULL;
95  }
96 
97  return s2;
98 }
zip_uint16_t encryption_method
zip_uint64_t valid
Definition: zip.h:301
static void winzip_aes_free(struct winzip_aes *)
static struct winzip_aes * winzip_aes_new(zip_uint16_t encryption_method, const char *password, zip_error_t *error)
static zip_int64_t winzip_aes_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
#define HMAC_LENGTH
Definition: zipint.h:78
#define SALT_LENGTH(method)
Definition: zipint.h:80

References _zip_error_set_from_source(), zip_stat::comp_size, winzip_aes::encryption_method, zip::error, flags, HMAC_LENGTH, NULL, winzip_aes::password, s2, SALT_LENGTH, src, zip_stat::valid, winzip_aes_decrypt(), winzip_aes_free(), winzip_aes_new(), WINZIP_AES_PASSWORD_VERIFY_LENGTH, za, ZIP_CODEC_ENCODE, ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_ER_ENCRNOTSUPP, ZIP_ER_INVAL, ZIP_ER_OPNOTSUPP, zip_error_set(), zip_source_layered(), zip_source_stat(), and ZIP_STAT_COMP_SIZE.

Referenced by _zip_get_encryption_implementation().

◆ zip_source_winzip_aes_encode()

zip_source_t* zip_source_winzip_aes_encode ( zip_t za,
zip_source_t src,
zip_uint16_t  encryption_method,
int  flags,
const char *  password 
)

Definition at line 61 of file zip_source_winzip_aes_encode.c.

61  {
63  struct winzip_aes *ctx;
64 
67  return NULL;
68  }
69 
71  return NULL;
72  }
73 
76  return NULL;
77  }
78 
79  return s2;
80 }
static zip_int64_t winzip_aes_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
static void winzip_aes_free(struct winzip_aes *)
static struct winzip_aes * winzip_aes_new(zip_uint16_t encryption_method, const char *password, zip_error_t *error)

References winzip_aes::encryption_method, zip::error, NULL, winzip_aes::password, s2, src, winzip_aes_encrypt(), winzip_aes_free(), winzip_aes_new(), za, ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_ER_INVAL, zip_error_set(), and zip_source_layered().

Referenced by _zip_get_encryption_implementation().

Variable Documentation

◆ _zip_err_details

const struct _zip_err_info _zip_err_details[]
extern

Definition at line 51 of file zip_err_str.c.

Referenced by zip_error_strerror().

◆ _zip_err_details_count

const int _zip_err_details_count
extern

Definition at line 76 of file zip_err_str.c.

Referenced by zip_error_strerror().

◆ _zip_err_str

const struct _zip_err_info _zip_err_str[]
extern

◆ _zip_err_str_count

const int _zip_err_str_count
extern

◆ zip_algorithm_bzip2_compress

zip_compression_algorithm_t zip_algorithm_bzip2_compress
extern

Definition at line 258 of file zip_algorithm_bzip2.c.

◆ zip_algorithm_bzip2_decompress

zip_compression_algorithm_t zip_algorithm_bzip2_decompress
extern

Definition at line 272 of file zip_algorithm_bzip2.c.

◆ zip_algorithm_deflate_compress

zip_compression_algorithm_t zip_algorithm_deflate_compress
extern

Definition at line 238 of file zip_algorithm_deflate.c.

◆ zip_algorithm_deflate_decompress

zip_compression_algorithm_t zip_algorithm_deflate_decompress
extern

Definition at line 252 of file zip_algorithm_deflate.c.

◆ zip_algorithm_xz_compress

zip_compression_algorithm_t zip_algorithm_xz_compress
extern

Definition at line 379 of file zip_algorithm_xz.c.

◆ zip_algorithm_xz_decompress

zip_compression_algorithm_t zip_algorithm_xz_decompress
extern

Definition at line 393 of file zip_algorithm_xz.c.

◆ zip_algorithm_zstd_compress

zip_compression_algorithm_t zip_algorithm_zstd_compress
extern

Definition at line 267 of file zip_algorithm_zstd.c.

◆ zip_algorithm_zstd_decompress

zip_compression_algorithm_t zip_algorithm_zstd_decompress
extern

Definition at line 281 of file zip_algorithm_zstd.c.