_zip_add_entry:
   42|  22.4k|zip_int64_t _zip_add_entry(zip_t *za) {
   43|  22.4k|    zip_uint64_t idx;
   44|       |
   45|  22.4k|    if (za->nentry + 1 >= za->nentry_alloc) {
  ------------------
  |  Branch (45:9): [True: 5.39k, False: 17.0k]
  ------------------
   46|  5.39k|        zip_uint64_t additional_entries = 2 * za->nentry_alloc;
   47|       |
   48|  5.39k|        if (additional_entries < 16) {
  ------------------
  |  Branch (48:13): [True: 4.86k, False: 531]
  ------------------
   49|  4.86k|            additional_entries = 16;
   50|  4.86k|        }
   51|    531|        else if (additional_entries > 1024) {
  ------------------
  |  Branch (51:18): [True: 0, False: 531]
  ------------------
   52|      0|            additional_entries = 1024;
   53|      0|        }
   54|       |
   55|  5.39k|        if (!ZIP_REALLOC(za->entry, za->nentry_alloc, additional_entries, &za->error)) {
  ------------------
  |  |  107|  5.39k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (55:13): [True: 0, False: 5.39k]
  ------------------
   56|      0|            return -1;
   57|      0|        }
   58|  5.39k|    }
   59|       |
   60|  22.4k|    idx = za->nentry++;
   61|       |
   62|  22.4k|    _zip_entry_init(za->entry + idx);
   63|       |
   64|  22.4k|    return (zip_int64_t)idx;
   65|  22.4k|}

zip_algorithm_deflate.c:maximum_compressed_size:
   50|  10.8k|static zip_uint64_t maximum_compressed_size(zip_uint64_t uncompressed_size) {
   51|       |    /* max deflate size increase: size + ceil(size/16k)*5+6 */
   52|       |
   53|  10.8k|    zip_uint64_t compressed_size = uncompressed_size + (uncompressed_size + 16383) / 16384 * 5 + 6;
   54|       |
   55|  10.8k|    if (compressed_size < uncompressed_size) {
  ------------------
  |  Branch (55:9): [True: 0, False: 10.8k]
  ------------------
   56|      0|        return ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   57|      0|    }
   58|  10.8k|    return compressed_size;
   59|  10.8k|}
zip_algorithm_deflate.c:compress_allocate:
   89|  10.8k|static void *compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
   90|  10.8k|    (void)method;
   91|       |    return allocate(true, compression_flags, error);
   92|  10.8k|}
zip_algorithm_deflate.c:allocate:
   62|  14.4k|static void *allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error) {
   63|  14.4k|    struct ctx *ctx;
   64|       |
   65|  14.4k|    if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (65:9): [True: 0, False: 14.4k]
  ------------------
   66|      0|        zip_error_set(error, ZIP_ET_SYS, errno);
  ------------------
  |  |  172|      0|#define ZIP_ET_SYS 1    /* sys_err is errno */
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|  14.4k|    ctx->error = error;
   71|  14.4k|    ctx->compress = compress;
   72|  14.4k|    if (compression_flags >= 1 && compression_flags <= 9) {
  ------------------
  |  Branch (72:9): [True: 3.74k, False: 10.7k]
  |  Branch (72:35): [True: 3.74k, False: 0]
  ------------------
   73|  3.74k|        ctx->level = (int)compression_flags;
   74|  3.74k|    }
   75|  10.7k|    else {
   76|  10.7k|        ctx->level = Z_BEST_COMPRESSION;
   77|  10.7k|    }
   78|  14.4k|    ctx->mem_level = compression_flags == TORRENTZIP_COMPRESSION_FLAGS ? TORRENTZIP_MEM_LEVEL : MAX_MEM_LEVEL;
  ------------------
  |  |   75|  14.4k|#define TORRENTZIP_COMPRESSION_FLAGS ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|  14.4k|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
                  ctx->mem_level = compression_flags == TORRENTZIP_COMPRESSION_FLAGS ? TORRENTZIP_MEM_LEVEL : MAX_MEM_LEVEL;
  ------------------
  |  |   74|      0|#define TORRENTZIP_MEM_LEVEL 8
  ------------------
  |  Branch (78:22): [True: 0, False: 14.4k]
  ------------------
   79|  14.4k|    ctx->end_of_input = false;
   80|       |
   81|  14.4k|    ctx->zstr.zalloc = Z_NULL;
   82|  14.4k|    ctx->zstr.zfree = Z_NULL;
   83|  14.4k|    ctx->zstr.opaque = NULL;
   84|       |
   85|  14.4k|    return ctx;
   86|  14.4k|}
zip_algorithm_deflate.c:deallocate:
  101|  14.4k|static void deallocate(void *ud) {
  102|  14.4k|    struct ctx *ctx = (struct ctx *)ud;
  103|       |
  104|  14.4k|    free(ctx);
  105|  14.4k|}
zip_algorithm_deflate.c:general_purpose_bit_flags:
  108|  14.5k|static zip_uint16_t general_purpose_bit_flags(void *ud) {
  109|  14.5k|    struct ctx *ctx = (struct ctx *)ud;
  110|       |
  111|  14.5k|    if (!ctx->compress) {
  ------------------
  |  Branch (111:9): [True: 0, False: 14.5k]
  ------------------
  112|      0|        return 0;
  113|      0|    }
  114|       |
  115|  14.5k|    if (ctx->level < 3) {
  ------------------
  |  Branch (115:9): [True: 2.31k, False: 12.2k]
  ------------------
  116|  2.31k|        return 2 << 1;
  117|  2.31k|    }
  118|  12.2k|    else if (ctx->level > 7) {
  ------------------
  |  Branch (118:14): [True: 8.60k, False: 3.63k]
  ------------------
  119|  8.60k|        return 1 << 1;
  120|  8.60k|    }
  121|  3.63k|    return 0;
  122|  14.5k|}
zip_algorithm_deflate.c:start:
  125|  14.4k|static bool start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
  126|  14.4k|    struct ctx *ctx = (struct ctx *)ud;
  127|  14.4k|    int ret;
  128|       |
  129|  14.4k|    (void)st;
  130|  14.4k|    (void)attributes;
  131|       |
  132|  14.4k|    ctx->zstr.avail_in = 0;
  133|  14.4k|    ctx->zstr.next_in = NULL;
  134|  14.4k|    ctx->zstr.avail_out = 0;
  135|  14.4k|    ctx->zstr.next_out = NULL;
  136|       |
  137|  14.4k|    if (ctx->compress) {
  ------------------
  |  Branch (137:9): [True: 10.8k, False: 3.61k]
  ------------------
  138|       |        /* negative value to tell zlib not to write a header */
  139|  10.8k|        ret = deflateInit2(&ctx->zstr, ctx->level, Z_DEFLATED, -MAX_WBITS, ctx->mem_level, Z_DEFAULT_STRATEGY);
  140|  10.8k|    }
  141|  3.61k|    else {
  142|  3.61k|        ret = inflateInit2(&ctx->zstr, -MAX_WBITS);
  143|  3.61k|    }
  144|       |
  145|  14.4k|    if (ret != Z_OK) {
  ------------------
  |  Branch (145:9): [True: 0, False: 14.4k]
  ------------------
  146|      0|        zip_error_set(ctx->error, ZIP_ER_ZLIB, ret);
  ------------------
  |  |  144|      0|#define ZIP_ER_ZLIB 13            /* Z Zlib error */
  ------------------
  147|      0|        return false;
  148|      0|    }
  149|       |
  150|       |
  151|  14.4k|    return true;
  152|  14.4k|}
zip_algorithm_deflate.c:end:
  155|  14.4k|static bool end(void *ud) {
  156|  14.4k|    struct ctx *ctx = (struct ctx *)ud;
  157|  14.4k|    int err;
  158|       |
  159|  14.4k|    if (ctx->compress) {
  ------------------
  |  Branch (159:9): [True: 10.8k, False: 3.61k]
  ------------------
  160|  10.8k|        err = deflateEnd(&ctx->zstr);
  161|  10.8k|    }
  162|  3.61k|    else {
  163|  3.61k|        err = inflateEnd(&ctx->zstr);
  164|  3.61k|    }
  165|       |
  166|  14.4k|    if (err != Z_OK) {
  ------------------
  |  Branch (166:9): [True: 0, False: 14.4k]
  ------------------
  167|      0|        zip_error_set(ctx->error, ZIP_ER_ZLIB, err);
  ------------------
  |  |  144|      0|#define ZIP_ER_ZLIB 13            /* Z Zlib error */
  ------------------
  168|      0|        return false;
  169|      0|    }
  170|       |
  171|  14.4k|    return true;
  172|  14.4k|}
zip_algorithm_deflate.c:input:
  175|  5.96k|static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
  176|  5.96k|    struct ctx *ctx = (struct ctx *)ud;
  177|       |
  178|  5.96k|    if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
  ------------------
  |  Branch (178:9): [True: 0, False: 5.96k]
  |  Branch (178:30): [True: 0, False: 5.96k]
  ------------------
  179|      0|        zip_error_set(ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  180|      0|        return false;
  181|      0|    }
  182|       |
  183|  5.96k|    ctx->zstr.avail_in = (uInt)length;
  184|  5.96k|    ctx->zstr.next_in = (Bytef *)data;
  185|       |
  186|       |    return true;
  187|  5.96k|}
zip_algorithm_deflate.c:end_of_input:
  190|  14.4k|static bool end_of_input(void *ud) {
  191|  14.4k|    struct ctx *ctx = (struct ctx *)ud;
  192|       |
  193|       |    ctx->end_of_input = true;
  194|  14.4k|    return ctx->zstr.avail_in != 0;
  195|  14.4k|}
zip_algorithm_deflate.c:process:
  198|  44.5k|static zip_compression_status_t process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
  199|  44.5k|    struct ctx *ctx = (struct ctx *)ud;
  200|  44.5k|    uInt avail_out;
  201|       |
  202|  44.5k|    int ret;
  203|       |
  204|  44.5k|    avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
  ------------------
  |  |  515|  44.5k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 44.5k]
  |  |  ------------------
  ------------------
  205|  44.5k|    ctx->zstr.avail_out = avail_out;
  206|  44.5k|    ctx->zstr.next_out = (Bytef *)data;
  207|       |
  208|  44.5k|    if (ctx->compress) {
  ------------------
  |  Branch (208:9): [True: 37.3k, False: 7.22k]
  ------------------
  209|  37.3k|        ret = deflate(&ctx->zstr, ctx->end_of_input ? Z_FINISH : 0);
  ------------------
  |  Branch (209:35): [True: 10.8k, False: 26.4k]
  ------------------
  210|  37.3k|    }
  211|  7.22k|    else {
  212|  7.22k|        ret = inflate(&ctx->zstr, Z_SYNC_FLUSH);
  213|  7.22k|    }
  214|       |
  215|  44.5k|    *length = avail_out - ctx->zstr.avail_out;
  216|       |
  217|  44.5k|    switch (ret) {
  218|  13.2k|    case Z_OK:
  ------------------
  |  Branch (218:5): [True: 13.2k, False: 31.3k]
  ------------------
  219|  13.2k|        return ZIP_COMPRESSION_OK;
  220|       |
  221|  14.4k|    case Z_STREAM_END:
  ------------------
  |  Branch (221:5): [True: 14.4k, False: 30.0k]
  ------------------
  222|  14.4k|        return ZIP_COMPRESSION_END;
  223|       |
  224|  16.8k|    case Z_BUF_ERROR:
  ------------------
  |  Branch (224:5): [True: 16.8k, False: 27.7k]
  ------------------
  225|  16.8k|        if (ctx->zstr.avail_in == 0) {
  ------------------
  |  Branch (225:13): [True: 16.8k, False: 0]
  ------------------
  226|  16.8k|            return ZIP_COMPRESSION_NEED_DATA;
  227|  16.8k|        }
  228|       |
  229|       |        /* fallthrough */
  230|       |
  231|      0|    default:
  ------------------
  |  Branch (231:5): [True: 0, False: 44.5k]
  ------------------
  232|      0|        zip_error_set(ctx->error, ZIP_ER_ZLIB, ret);
  ------------------
  |  |  144|      0|#define ZIP_ER_ZLIB 13            /* Z Zlib error */
  ------------------
  233|      0|        return ZIP_COMPRESSION_ERROR;
  234|  44.5k|    }
  235|  44.5k|}
zip_algorithm_deflate.c:decompress_allocate:
   95|  3.61k|static void *decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
   96|  3.61k|    (void)method;
   97|       |    return allocate(false, compression_flags, error);
   98|  3.61k|}

_zip_buffer_data:
   39|  49.1k|zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer) {
   40|  49.1k|    return buffer->data;
   41|  49.1k|}
_zip_buffer_free:
   44|   189k|void _zip_buffer_free(zip_buffer_t *buffer) {
   45|   189k|    if (buffer == NULL) {
  ------------------
  |  Branch (45:9): [True: 11.2k, False: 177k]
  ------------------
   46|  11.2k|        return;
   47|  11.2k|    }
   48|       |
   49|   177k|    if (buffer->free_data) {
  ------------------
  |  Branch (49:9): [True: 7.67k, False: 170k]
  ------------------
   50|  7.67k|        free(buffer->data);
   51|  7.67k|    }
   52|       |
   53|   177k|    free(buffer);
   54|   177k|}
_zip_buffer_eof:
   57|  28.0k|bool _zip_buffer_eof(zip_buffer_t *buffer) {
   58|  28.0k|    return buffer->ok && buffer->offset == buffer->size;
  ------------------
  |  Branch (58:12): [True: 27.9k, False: 22]
  |  Branch (58:26): [True: 27.2k, False: 697]
  ------------------
   59|  28.0k|}
_zip_buffer_get:
   62|  1.59M|zip_uint8_t *_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length) {
   63|  1.59M|    zip_uint8_t *data;
   64|       |
   65|  1.59M|    data = _zip_buffer_peek(buffer, length);
   66|       |
   67|  1.59M|    if (data != NULL) {
  ------------------
  |  Branch (67:9): [True: 1.59M, False: 148]
  ------------------
   68|  1.59M|        buffer->offset += length;
   69|  1.59M|    }
   70|       |
   71|  1.59M|    return data;
   72|  1.59M|}
_zip_buffer_get_16:
   75|   331k|zip_uint16_t _zip_buffer_get_16(zip_buffer_t *buffer) {
   76|   331k|    zip_uint8_t *data = _zip_buffer_get(buffer, 2);
   77|       |
   78|   331k|    if (data == NULL) {
  ------------------
  |  Branch (78:9): [True: 0, False: 331k]
  ------------------
   79|      0|        return 0;
   80|      0|    }
   81|       |
   82|   331k|    return (zip_uint16_t)(data[0] + (data[1] << 8));
   83|   331k|}
_zip_buffer_get_32:
   86|   127k|zip_uint32_t _zip_buffer_get_32(zip_buffer_t *buffer) {
   87|   127k|    zip_uint8_t *data = _zip_buffer_get(buffer, 4);
   88|       |
   89|   127k|    if (data == NULL) {
  ------------------
  |  Branch (89:9): [True: 5, False: 127k]
  ------------------
   90|      5|        return 0;
   91|      5|    }
   92|       |
   93|   127k|    return ((((((zip_uint32_t)data[3] << 8) + data[2]) << 8) + data[1]) << 8) + data[0];
   94|   127k|}
_zip_buffer_get_64:
   97|  8.48k|zip_uint64_t _zip_buffer_get_64(zip_buffer_t *buffer) {
   98|  8.48k|    zip_uint8_t *data = _zip_buffer_get(buffer, 8);
   99|       |
  100|  8.48k|    if (data == NULL) {
  ------------------
  |  Branch (100:9): [True: 23, False: 8.46k]
  ------------------
  101|     23|        return 0;
  102|     23|    }
  103|       |
  104|  8.46k|    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];
  105|  8.48k|}
_zip_buffer_get_8:
  108|  8.41k|zip_uint8_t _zip_buffer_get_8(zip_buffer_t *buffer) {
  109|  8.41k|    zip_uint8_t *data = _zip_buffer_get(buffer, 1);
  110|       |
  111|  8.41k|    if (data == NULL) {
  ------------------
  |  Branch (111:9): [True: 0, False: 8.41k]
  ------------------
  112|      0|        return 0;
  113|      0|    }
  114|       |
  115|  8.41k|    return data[0];
  116|  8.41k|}
_zip_buffer_left:
  119|   123k|zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer) {
  120|   123k|    return buffer->ok ? buffer->size - buffer->offset : 0;
  ------------------
  |  Branch (120:12): [True: 123k, False: 0]
  ------------------
  121|   123k|}
_zip_buffer_read:
  124|  18.4k|zip_uint64_t _zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
  125|  18.4k|    zip_uint64_t copied;
  126|       |
  127|  18.4k|    if (_zip_buffer_left(buffer) < length) {
  ------------------
  |  Branch (127:9): [True: 18.4k, False: 0]
  ------------------
  128|  18.4k|        length = _zip_buffer_left(buffer);
  129|  18.4k|    }
  130|       |
  131|  18.4k|    copied = 0;
  132|  36.9k|    while (copied < length) {
  ------------------
  |  Branch (132:12): [True: 18.4k, False: 18.4k]
  ------------------
  133|  18.4k|        size_t n = ZIP_MIN(length - copied, SIZE_MAX);
  ------------------
  |  |  515|  18.4k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 18.4k, False: 0]
  |  |  ------------------
  ------------------
  134|  18.4k|        (void)memcpy_s(data + copied, n, _zip_buffer_get(buffer, n), n);
  ------------------
  |  |  202|  18.4k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  135|  18.4k|        copied += n;
  136|  18.4k|    }
  137|       |
  138|  18.4k|    return copied;
  139|  18.4k|}
_zip_buffer_new:
  142|   177k|zip_buffer_t *_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) {
  143|   177k|    bool free_data = (data == NULL);
  144|   177k|    zip_buffer_t *buffer;
  145|       |
  146|       |#if ZIP_UINT64_MAX > SIZE_MAX
  147|       |    if (size > SIZE_MAX) {
  148|       |        return NULL;
  149|       |    }
  150|       |#endif
  151|       |
  152|   177k|    if (data == NULL) {
  ------------------
  |  Branch (152:9): [True: 7.67k, False: 170k]
  ------------------
  153|  7.67k|        if ((data = (zip_uint8_t *)malloc((size_t)size)) == NULL) {
  ------------------
  |  Branch (153:13): [True: 0, False: 7.67k]
  ------------------
  154|      0|            return NULL;
  155|      0|        }
  156|  7.67k|    }
  157|       |
  158|   177k|    if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) {
  ------------------
  |  Branch (158:9): [True: 0, False: 177k]
  ------------------
  159|      0|        if (free_data) {
  ------------------
  |  Branch (159:13): [True: 0, False: 0]
  ------------------
  160|      0|            free(data);
  161|      0|        }
  162|      0|        return NULL;
  163|      0|    }
  164|       |
  165|   177k|    buffer->ok = true;
  166|   177k|    buffer->data = data;
  167|   177k|    buffer->size = size;
  168|   177k|    buffer->offset = 0;
  169|   177k|    buffer->free_data = free_data;
  170|       |
  171|   177k|    return buffer;
  172|   177k|}
_zip_buffer_new_from_source:
  175|  16.1k|zip_buffer_t *_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error) {
  176|  16.1k|    zip_buffer_t *buffer;
  177|       |
  178|  16.1k|    if ((buffer = _zip_buffer_new(buf, size)) == NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 16.1k]
  ------------------
  179|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  180|      0|        return NULL;
  181|      0|    }
  182|       |
  183|  16.1k|    if (_zip_read(src, buffer->data, size, error) < 0) {
  ------------------
  |  Branch (183:9): [True: 0, False: 16.1k]
  ------------------
  184|      0|        _zip_buffer_free(buffer);
  185|      0|        return NULL;
  186|      0|    }
  187|       |
  188|  16.1k|    return buffer;
  189|  16.1k|}
_zip_buffer_offset:
  192|  94.6k|zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer) {
  193|  94.6k|    return buffer->ok ? buffer->offset : 0;
  ------------------
  |  Branch (193:12): [True: 94.6k, False: 0]
  ------------------
  194|  94.6k|}
_zip_buffer_ok:
  197|   185k|bool _zip_buffer_ok(zip_buffer_t *buffer) {
  198|   185k|    return buffer->ok;
  199|   185k|}
_zip_buffer_peek:
  202|  1.60M|zip_uint8_t *_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length) {
  203|  1.60M|    zip_uint8_t *data;
  204|       |
  205|  1.60M|    if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) {
  ------------------
  |  Branch (205:9): [True: 6, False: 1.60M]
  |  Branch (205:24): [True: 0, False: 1.60M]
  |  Branch (205:60): [True: 142, False: 1.60M]
  ------------------
  206|    148|        buffer->ok = false;
  207|    148|        return NULL;
  208|    148|    }
  209|       |
  210|  1.60M|    data = buffer->data + buffer->offset;
  211|  1.60M|    return data;
  212|  1.60M|}
_zip_buffer_put:
  214|  94.8k|int _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) {
  215|  94.8k|    zip_uint8_t *dst = _zip_buffer_get(buffer, length);
  216|       |
  217|  94.8k|    if (dst == NULL) {
  ------------------
  |  Branch (217:9): [True: 0, False: 94.8k]
  ------------------
  218|      0|        return -1;
  219|      0|    }
  220|       |
  221|  94.8k|    (void)memcpy_s(dst, length, src, length);
  ------------------
  |  |  202|  94.8k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  222|  94.8k|    return 0;
  223|  94.8k|}
_zip_buffer_put_16:
  226|   646k|int _zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i) {
  227|   646k|    zip_uint8_t *data = _zip_buffer_get(buffer, 2);
  228|       |
  229|   646k|    if (data == NULL) {
  ------------------
  |  Branch (229:9): [True: 0, False: 646k]
  ------------------
  230|      0|        return -1;
  231|      0|    }
  232|       |
  233|   646k|    data[0] = (zip_uint8_t)(i & 0xff);
  234|   646k|    data[1] = (zip_uint8_t)((i >> 8) & 0xff);
  235|       |
  236|   646k|    return 0;
  237|   646k|}
_zip_buffer_put_32:
  240|   249k|int _zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i) {
  241|   249k|    zip_uint8_t *data = _zip_buffer_get(buffer, 4);
  242|       |
  243|   249k|    if (data == NULL) {
  ------------------
  |  Branch (243:9): [True: 0, False: 249k]
  ------------------
  244|      0|        return -1;
  245|      0|    }
  246|       |
  247|   249k|    data[0] = (zip_uint8_t)(i & 0xff);
  248|   249k|    data[1] = (zip_uint8_t)((i >> 8) & 0xff);
  249|   249k|    data[2] = (zip_uint8_t)((i >> 16) & 0xff);
  250|   249k|    data[3] = (zip_uint8_t)((i >> 24) & 0xff);
  251|       |
  252|   249k|    return 0;
  253|   249k|}
_zip_buffer_put_8:
  276|  25.9k|int _zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i) {
  277|  25.9k|    zip_uint8_t *data = _zip_buffer_get(buffer, 1);
  278|       |
  279|  25.9k|    if (data == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 25.9k]
  ------------------
  280|      0|        return -1;
  281|      0|    }
  282|       |
  283|  25.9k|    data[0] = i;
  284|       |
  285|  25.9k|    return 0;
  286|  25.9k|}
_zip_buffer_set_offset:
  289|  85.9k|int _zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset) {
  290|  85.9k|    if (offset > buffer->size) {
  ------------------
  |  Branch (290:9): [True: 5.03k, False: 80.9k]
  ------------------
  291|  5.03k|        buffer->ok = false;
  292|  5.03k|        return -1;
  293|  5.03k|    }
  294|       |
  295|  80.9k|    buffer->ok = true;
  296|  80.9k|    buffer->offset = offset;
  297|       |
  298|  80.9k|    return 0;
  299|  85.9k|}
_zip_buffer_skip:
  302|  22.8k|int _zip_buffer_skip(zip_buffer_t *buffer, zip_uint64_t length) {
  303|  22.8k|    zip_uint64_t offset = buffer->offset + length;
  304|       |
  305|  22.8k|    if (offset < buffer->offset) {
  ------------------
  |  Branch (305:9): [True: 0, False: 22.8k]
  ------------------
  306|      0|        buffer->ok = false;
  307|      0|        return -1;
  308|      0|    }
  309|  22.8k|    return _zip_buffer_set_offset(buffer, offset);
  310|  22.8k|}
_zip_buffer_size:
  312|  10.5k|zip_uint64_t _zip_buffer_size(zip_buffer_t *buffer) {
  313|  10.5k|    return buffer->size;
  314|  10.5k|}

zip_close:
   52|  7.62k|ZIP_EXTERN int zip_close(zip_t *za) {
   53|  7.62k|    zip_uint64_t i, j, survivors, unchanged_offset;
   54|  7.62k|    zip_int64_t off;
   55|  7.62k|    int error;
   56|  7.62k|    zip_filelist_t *filelist;
   57|  7.62k|    int changed;
   58|       |
   59|  7.62k|    if (za == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 7.62k]
  ------------------
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|  7.62k|    changed = _zip_changed(za, &survivors);
   64|       |
   65|  7.62k|    if (survivors == 0 && !(za->ch_flags & ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE)) {
  ------------------
  |  |  116|    205|#define ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE 16u /* don't remove file if archive is empty */
  ------------------
  |  Branch (65:9): [True: 205, False: 7.42k]
  |  Branch (65:27): [True: 205, False: 0]
  ------------------
   66|       |        /* don't create zip files with no entries */
   67|    205|        if ((za->open_flags & ZIP_TRUNCATE) || changed) {
  ------------------
  |  |   89|    205|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (67:13): [True: 198, False: 7]
  |  Branch (67:48): [True: 0, False: 7]
  ------------------
   68|    198|            if (zip_source_remove(za->src) < 0) {
  ------------------
  |  Branch (68:17): [True: 0, False: 198]
  ------------------
   69|      0|                if (!((zip_error_code_zip(zip_source_error(za->src)) == ZIP_ER_REMOVE) && (zip_error_code_system(zip_source_error(za->src)) == ENOENT))) {
  ------------------
  |  |  153|      0|#define ZIP_ER_REMOVE 22          /* S Can't remove file */
  ------------------
  |  Branch (69:23): [True: 0, False: 0]
  |  Branch (69:91): [True: 0, False: 0]
  ------------------
   70|      0|                    zip_error_set_from_source(&za->error, za->src);
   71|      0|                    return -1;
   72|      0|                }
   73|      0|            }
   74|    198|        }
   75|    205|        zip_discard(za);
   76|    205|        return 0;
   77|    205|    }
   78|       |
   79|       |    /* Always write empty archive if we are told to keep it, otherwise it wouldn't be created if the file doesn't already exist. */
   80|  7.42k|    if (!changed && survivors > 0) {
  ------------------
  |  Branch (80:9): [True: 2.63k, False: 4.78k]
  |  Branch (80:21): [True: 2.63k, False: 0]
  ------------------
   81|  2.63k|        zip_discard(za);
   82|  2.63k|        return 0;
   83|  2.63k|    }
   84|       |
   85|  4.78k|    if (survivors > za->nentry) {
  ------------------
  |  Branch (85:9): [True: 0, False: 4.78k]
  ------------------
   86|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   87|      0|        return -1;
   88|      0|    }
   89|       |
   90|  4.78k|    if ((filelist = (zip_filelist_t *)malloc(sizeof(filelist[0]) * (size_t)survivors)) == NULL) {
  ------------------
  |  Branch (90:9): [True: 0, False: 4.78k]
  ------------------
   91|      0|        return -1;
   92|      0|    }
   93|       |
   94|  4.78k|    unchanged_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|  4.78k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   95|       |    /* create list of files with index into original archive  */
   96|  26.4k|    for (i = j = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (96:21): [True: 21.6k, False: 4.78k]
  ------------------
   97|  21.6k|        if (za->entry[i].orig != NULL && ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
  ------------------
  |  |  519|      0|#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (518:35): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  517|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (517:34): [True: 0, False: 0]
  |  |  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (519:64): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (97:13): [True: 0, False: 21.6k]
  ------------------
   98|      0|            unchanged_offset = ZIP_MIN(unchanged_offset, za->entry[i].orig->offset);
  ------------------
  |  |  515|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   99|      0|        }
  100|  21.6k|        if (za->entry[i].deleted) {
  ------------------
  |  Branch (100:13): [True: 400, False: 21.2k]
  ------------------
  101|    400|            continue;
  102|    400|        }
  103|       |
  104|  21.2k|        if (j >= survivors) {
  ------------------
  |  Branch (104:13): [True: 0, False: 21.2k]
  ------------------
  105|      0|            free(filelist);
  106|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  107|      0|            return -1;
  108|      0|        }
  109|       |
  110|  21.2k|        filelist[j].idx = i;
  111|  21.2k|        filelist[j].name = zip_get_name(za, i, 0);
  112|  21.2k|        j++;
  113|  21.2k|    }
  114|  4.78k|    if (j < survivors) {
  ------------------
  |  Branch (114:9): [True: 0, False: 4.78k]
  ------------------
  115|      0|        free(filelist);
  116|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  117|      0|        return -1;
  118|      0|    }
  119|       |
  120|  4.78k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  4.78k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  4.78k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
  121|      0|        qsort(filelist, (size_t)survivors, sizeof(filelist[0]), torrentzip_compare_names);
  122|      0|    }
  123|       |
  124|  4.78k|    if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
  ------------------
  |  |  523|  9.57k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  4.78k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
                  if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
  ------------------
  |  |  276|  4.78k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (124:36): [True: 0, False: 4.78k]
  ------------------
  125|      0|        unchanged_offset = 0;
  126|      0|    }
  127|  4.78k|    else {
  128|  4.78k|        if (unchanged_offset == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|  4.78k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (128:13): [True: 4.78k, False: 0]
  ------------------
  129|       |            /* we're keeping all file data, find the end of the last one */
  130|  4.78k|            zip_uint64_t last_index = ZIP_UINT64_MAX;
  ------------------
  |  |   46|  4.78k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  131|  4.78k|            unchanged_offset = 0;
  132|       |
  133|  26.4k|            for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (133:25): [True: 21.6k, False: 4.78k]
  ------------------
  134|  21.6k|                if (za->entry[i].orig != NULL) {
  ------------------
  |  Branch (134:21): [True: 0, False: 21.6k]
  ------------------
  135|      0|                    if (za->entry[i].orig->offset >= unchanged_offset) {
  ------------------
  |  Branch (135:25): [True: 0, False: 0]
  ------------------
  136|      0|                        unchanged_offset = za->entry[i].orig->offset;
  137|      0|                        last_index = i;
  138|      0|                    }
  139|      0|                }
  140|  21.6k|            }
  141|  4.78k|            if (last_index != ZIP_UINT64_MAX) {
  ------------------
  |  |   46|  4.78k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (141:17): [True: 0, False: 4.78k]
  ------------------
  142|      0|                if ((unchanged_offset = _zip_file_get_end(za, last_index, &za->error)) == 0) {
  ------------------
  |  Branch (142:21): [True: 0, False: 0]
  ------------------
  143|      0|                    free(filelist);
  144|      0|                    return -1;
  145|      0|                }
  146|      0|            }
  147|  4.78k|        }
  148|  4.78k|        if (unchanged_offset > 0) {
  ------------------
  |  Branch (148:13): [True: 0, False: 4.78k]
  ------------------
  149|      0|            if (zip_source_begin_write_cloning(za->src, unchanged_offset) < 0) {
  ------------------
  |  Branch (149:17): [True: 0, False: 0]
  ------------------
  150|       |                /* cloning not supported, need to copy everything */
  151|      0|                unchanged_offset = 0;
  152|      0|            }
  153|      0|        }
  154|  4.78k|    }
  155|  4.78k|    if (unchanged_offset == 0) {
  ------------------
  |  Branch (155:9): [True: 4.78k, False: 0]
  ------------------
  156|  4.78k|        if (zip_source_begin_write(za->src) < 0) {
  ------------------
  |  Branch (156:13): [True: 0, False: 4.78k]
  ------------------
  157|      0|            zip_error_set_from_source(&za->error, za->src);
  158|      0|            free(filelist);
  159|      0|            return -1;
  160|      0|        }
  161|  4.78k|    }
  162|       |
  163|  4.78k|    if (_zip_progress_start(za->progress) != 0) {
  ------------------
  |  Branch (163:9): [True: 0, False: 4.78k]
  ------------------
  164|      0|        zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
  ------------------
  |  |  163|      0|#define ZIP_ER_CANCELLED 32       /* N Operation cancelled */
  ------------------
  165|      0|        zip_source_rollback_write(za->src);
  166|      0|        free(filelist);
  167|      0|        return -1;
  168|      0|    }
  169|  4.78k|    error = 0;
  170|  26.0k|    for (j = 0; j < survivors; j++) {
  ------------------
  |  Branch (170:17): [True: 21.2k, False: 4.78k]
  ------------------
  171|  21.2k|        int new_data;
  172|  21.2k|        zip_entry_t *entry;
  173|  21.2k|        zip_dirent_t *de;
  174|       |
  175|  21.2k|        if (_zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors) != 0) {
  ------------------
  |  Branch (175:13): [True: 0, False: 21.2k]
  ------------------
  176|      0|            zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
  ------------------
  |  |  163|      0|#define ZIP_ER_CANCELLED 32       /* N Operation cancelled */
  ------------------
  177|      0|            error = 1;
  178|      0|            break;
  179|      0|        }
  180|       |
  181|  21.2k|        i = filelist[j].idx;
  182|  21.2k|        entry = za->entry + i;
  183|       |
  184|  21.2k|        if (entry->orig != NULL && entry->orig->offset < unchanged_offset) {
  ------------------
  |  Branch (184:13): [True: 0, False: 21.2k]
  |  Branch (184:36): [True: 0, False: 0]
  ------------------
  185|       |            /* already implicitly copied by cloning */
  186|      0|            continue;
  187|      0|        }
  188|       |
  189|  21.2k|        new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  518|  42.4k|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  ------------------
  |  |  |  Branch (518:35): [True: 21.2k, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  517|  21.2k|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  ------------------
  |  |  |  Branch (517:34): [True: 0, False: 0]
  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  517|      0|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  ------------------
  |  |  |  Branch (517:34): [True: 0, False: 0]
  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  523|      0|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|      0|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
                      new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
  ------------------
  |  |  522|      0|#define ZIP_IS_TORRENTZIP(za) ((za)->flags & ZIP_AFL_IS_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  114|      0|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  |  |  ------------------
  ------------------
  |  Branch (189:193): [True: 0, False: 0]
  ------------------
  190|       |
  191|       |        /* create new local directory entry */
  192|  21.2k|        if (entry->changes == NULL) {
  ------------------
  |  Branch (192:13): [True: 0, False: 21.2k]
  ------------------
  193|      0|            if ((entry->changes = _zip_dirent_clone(entry->orig)) == NULL) {
  ------------------
  |  Branch (193:17): [True: 0, False: 0]
  ------------------
  194|      0|                zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  195|      0|                error = 1;
  196|      0|                break;
  197|      0|            }
  198|      0|        }
  199|  21.2k|        else if (entry->orig != NULL) {
  ------------------
  |  Branch (199:18): [True: 0, False: 21.2k]
  ------------------
  200|      0|            if (!_zip_dirent_merge(entry->changes, entry->orig, ZIP_ENTRY_DATA_CHANGED(entry), &za->error)) {
  ------------------
  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  ------------------
  |  Branch (200:17): [True: 0, False: 0]
  ------------------
  201|      0|                error = 1;
  202|      0|                break;
  203|      0|            }
  204|      0|        }
  205|  21.2k|        de = entry->changes;
  206|       |
  207|  21.2k|        if (_zip_read_local_ef(za, i) < 0) {
  ------------------
  |  Branch (207:13): [True: 0, False: 21.2k]
  ------------------
  208|      0|            error = 1;
  209|      0|            break;
  210|      0|        }
  211|       |
  212|  21.2k|        if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  21.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 21.2k]
  |  |  ------------------
  ------------------
  213|      0|            zip_dirent_torrentzip_normalize(entry->changes);
  214|      0|        }
  215|       |
  216|  21.2k|        if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (216:13): [True: 0, False: 21.2k]
  ------------------
  217|      0|            zip_error_set_from_source(&za->error, za->src);
  218|      0|            error = 1;
  219|      0|            break;
  220|      0|        }
  221|  21.2k|        de->offset = (zip_uint64_t)off;
  222|       |
  223|  21.2k|        if (new_data) {
  ------------------
  |  Branch (223:13): [True: 21.2k, False: 0]
  ------------------
  224|  21.2k|            zip_source_t *zs;
  225|       |
  226|  21.2k|            zs = NULL;
  227|  21.2k|            if (!ZIP_ENTRY_DATA_CHANGED(entry)) {
  ------------------
  |  |  518|  21.2k|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  ------------------
  |  Branch (227:17): [True: 0, False: 21.2k]
  ------------------
  228|      0|                if ((zs = zip_source_zip_file_create(za, i, ZIP_FL_UNCHANGED, 0, -1, NULL, &za->error)) == NULL) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (228:21): [True: 0, False: 0]
  ------------------
  229|      0|                    error = 1;
  230|      0|                    break;
  231|      0|                }
  232|      0|            }
  233|       |
  234|       |            /* add_data writes dirent */
  235|  21.2k|            if (add_data(za, zs ? zs : entry->source, de) < 0) {
  ------------------
  |  Branch (235:17): [True: 0, False: 21.2k]
  |  Branch (235:30): [True: 0, False: 21.2k]
  ------------------
  236|      0|                error = 1;
  237|      0|                if (zs) {
  ------------------
  |  Branch (237:21): [True: 0, False: 0]
  ------------------
  238|      0|                    zip_source_free(zs);
  239|      0|                }
  240|      0|                break;
  241|      0|            }
  242|  21.2k|            if (zs) {
  ------------------
  |  Branch (242:17): [True: 0, False: 21.2k]
  ------------------
  243|      0|                zip_source_free(zs);
  244|      0|            }
  245|  21.2k|        }
  246|      0|        else {
  247|      0|            zip_uint64_t offset;
  248|       |
  249|      0|            if (de->encryption_method != ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|      0|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (249:17): [True: 0, False: 0]
  ------------------
  250|       |                /* when copying data, all sizes are known -> no data descriptor needed */
  251|       |                /* except for PKWare encryption, where removing the data descriptor breaks password validation */
  252|      0|                de->bitflags &= (zip_uint16_t)~ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  254|      0|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  253|      0|            }
  254|      0|            if (_zip_dirent_write(za, de, ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (254:17): [True: 0, False: 0]
  ------------------
  255|      0|                error = 1;
  256|      0|                break;
  257|      0|            }
  258|      0|            if ((offset = _zip_file_get_offset(za, i, &za->error)) == 0) {
  ------------------
  |  Branch (258:17): [True: 0, False: 0]
  ------------------
  259|      0|                error = 1;
  260|      0|                break;
  261|      0|            }
  262|      0|            if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (262:17): [True: 0, False: 0]
  ------------------
  263|      0|                zip_error_set_from_source(&za->error, za->src);
  264|      0|                error = 1;
  265|      0|                break;
  266|      0|            }
  267|      0|            if (copy_data(za, de->comp_size) < 0) {
  ------------------
  |  Branch (267:17): [True: 0, False: 0]
  ------------------
  268|      0|                error = 1;
  269|      0|                break;
  270|      0|            }
  271|       |
  272|      0|            if (de->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
  ------------------
  |  |  254|      0|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  |  Branch (272:17): [True: 0, False: 0]
  ------------------
  273|      0|                if (write_data_descriptor(za, de, _zip_dirent_needs_zip64(de, 0)) < 0) {
  ------------------
  |  Branch (273:21): [True: 0, False: 0]
  ------------------
  274|      0|                    error = 1;
  275|      0|                    break;
  276|      0|                }
  277|      0|            }
  278|      0|        }
  279|  21.2k|    }
  280|       |
  281|  4.78k|    if (!error) {
  ------------------
  |  Branch (281:9): [True: 4.78k, False: 0]
  ------------------
  282|  4.78k|        if (write_cdir(za, filelist, survivors) < 0) {
  ------------------
  |  Branch (282:13): [True: 0, False: 4.78k]
  ------------------
  283|      0|            error = 1;
  284|      0|        }
  285|  4.78k|    }
  286|       |
  287|  4.78k|    free(filelist);
  288|       |
  289|  4.78k|    if (!error) {
  ------------------
  |  Branch (289:9): [True: 4.78k, False: 0]
  ------------------
  290|  4.78k|        if (zip_source_commit_write(za->src) != 0) {
  ------------------
  |  Branch (290:13): [True: 0, False: 4.78k]
  ------------------
  291|      0|            zip_error_set_from_source(&za->error, za->src);
  292|      0|            error = 1;
  293|      0|        }
  294|  4.78k|        _zip_progress_end(za->progress);
  295|  4.78k|    }
  296|       |
  297|  4.78k|    if (error) {
  ------------------
  |  Branch (297:9): [True: 0, False: 4.78k]
  ------------------
  298|      0|        zip_source_rollback_write(za->src);
  299|      0|        return -1;
  300|      0|    }
  301|       |
  302|  4.78k|    zip_discard(za);
  303|       |
  304|  4.78k|    return 0;
  305|  4.78k|}
_zip_changed:
  731|  7.62k|int _zip_changed(const zip_t *za, zip_uint64_t *survivorsp) {
  732|  7.62k|    int changed;
  733|  7.62k|    zip_uint64_t i, survivors;
  734|       |
  735|  7.62k|    changed = 0;
  736|  7.62k|    survivors = 0;
  737|       |
  738|  7.62k|    if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
  ------------------
  |  |  523|  14.1k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  7.08k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 7.08k]
  |  |  ------------------
  ------------------
                  if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
  ------------------
  |  |  522|      0|#define ZIP_IS_TORRENTZIP(za) ((za)->flags & ZIP_AFL_IS_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  114|      0|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  |  |  ------------------
  ------------------
  |  Branch (738:9): [True: 538, False: 7.08k]
  |  Branch (738:60): [True: 0, False: 0]
  ------------------
  739|    538|        changed = 1;
  740|    538|    }
  741|       |
  742|  47.9k|    for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (742:17): [True: 40.3k, False: 7.62k]
  ------------------
  743|  40.3k|        if (ZIP_ENTRY_HAS_CHANGES(&za->entry[i])) {
  ------------------
  |  |  519|  40.3k|#define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  518|  80.6k|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (518:35): [True: 21.2k, False: 19.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
  |  |  ------------------
  |  |  |  |  517|  18.6k|#define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (517:34): [True: 0, False: 18.6k]
  |  |  |  |  |  Branch (517:50): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (519:64): [True: 484, False: 18.6k]
  |  |  ------------------
  ------------------
  744|  21.7k|            changed = 1;
  745|  21.7k|        }
  746|  40.3k|        if (!za->entry[i].deleted) {
  ------------------
  |  Branch (746:13): [True: 39.8k, False: 484]
  ------------------
  747|  39.8k|            survivors++;
  748|  39.8k|        }
  749|  40.3k|    }
  750|       |
  751|  7.62k|    if (survivorsp) {
  ------------------
  |  Branch (751:9): [True: 7.62k, False: 0]
  ------------------
  752|  7.62k|        *survivorsp = survivors;
  753|  7.62k|    }
  754|       |
  755|  7.62k|    return changed;
  756|  7.62k|}
zip_close.c:add_data:
  308|  21.2k|static int add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de) {
  309|  21.2k|    zip_int64_t offstart, offdata, offend, data_length;
  310|  21.2k|    zip_stat_t st;
  311|  21.2k|    zip_file_attributes_t attributes;
  312|  21.2k|    zip_source_t *src_final, *src_tmp;
  313|  21.2k|    int ret;
  314|  21.2k|    int is_zip64;
  315|  21.2k|    zip_flags_t flags;
  316|  21.2k|    bool needs_recompress, needs_decompress, needs_crc, needs_compress, needs_reencrypt, needs_decrypt, needs_encrypt;
  317|  21.2k|    bool dirent_changed;
  318|  21.2k|    bool have_dos_time = false;
  319|  21.2k|    time_t mtime_before_copy;
  320|       |
  321|  21.2k|    if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (321:9): [True: 0, False: 21.2k]
  ------------------
  322|      0|        zip_error_set_from_source(&za->error, src);
  323|      0|        return -1;
  324|      0|    }
  325|       |
  326|  21.2k|    de->bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  254|  21.2k|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  327|       |
  328|  21.2k|    if ((st.valid & ZIP_STAT_COMP_METHOD) == 0) {
  ------------------
  |  |  329|  21.2k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  |  Branch (328:9): [True: 0, False: 21.2k]
  ------------------
  329|      0|        st.valid |= ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  330|      0|        st.comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  331|      0|    }
  332|       |
  333|  21.2k|    if ((de->changed & ZIP_DIRENT_COMP_METHOD) == 0 && st.comp_method != ZIP_CM_STORE) {
  ------------------
  |  |  336|  21.2k|#define ZIP_DIRENT_COMP_METHOD 0x0001u
  ------------------
                  if ((de->changed & ZIP_DIRENT_COMP_METHOD) == 0 && st.comp_method != ZIP_CM_STORE) {
  ------------------
  |  |  179|  6.57k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (333:9): [True: 6.57k, False: 14.6k]
  |  Branch (333:56): [True: 0, False: 6.57k]
  ------------------
  334|      0|        de->comp_method = st.comp_method;
  335|      0|    }
  336|  21.2k|    else if (de->comp_method == ZIP_CM_STORE && (st.valid & ZIP_STAT_SIZE)) {
  ------------------
  |  |  179|  42.4k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
                  else if (de->comp_method == ZIP_CM_STORE && (st.valid & ZIP_STAT_SIZE)) {
  ------------------
  |  |  325|  10.3k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (336:14): [True: 10.3k, False: 10.8k]
  |  Branch (336:49): [True: 10.3k, False: 0]
  ------------------
  337|  10.3k|        st.valid |= ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|  10.3k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  338|  10.3k|        st.comp_size = st.size;
  339|  10.3k|    }
  340|  10.8k|    else {
  341|       |        /* we'll recompress */
  342|  10.8k|        st.valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|  10.8k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  343|  10.8k|    }
  344|       |
  345|  21.2k|    if ((st.valid & ZIP_STAT_ENCRYPTION_METHOD) == 0) {
  ------------------
  |  |  330|  21.2k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  |  Branch (345:9): [True: 0, False: 21.2k]
  ------------------
  346|      0|        st.valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|      0|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  347|      0|        st.encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|      0|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  348|      0|    }
  349|       |
  350|  21.2k|    flags = ZIP_EF_LOCAL;
  ------------------
  |  |  260|  21.2k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  21.2k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  351|       |
  352|  21.2k|    if (st.valid & ZIP_STAT_CRC) {
  ------------------
  |  |  328|  21.2k|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (352:9): [True: 0, False: 21.2k]
  ------------------
  353|      0|        de->crc = st.crc;
  354|      0|    }
  355|       |
  356|  21.2k|    if ((st.valid & ZIP_STAT_SIZE) == 0) {
  ------------------
  |  |  325|  21.2k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (356:9): [True: 0, False: 21.2k]
  ------------------
  357|       |        /* TODO: not valid for torrentzip */
  358|      0|        flags |= ZIP_FL_FORCE_ZIP64;
  ------------------
  |  |  264|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  359|      0|        data_length = -1;
  360|      0|    }
  361|  21.2k|    else {
  362|  21.2k|        de->uncomp_size = st.size;
  363|       |
  364|  21.2k|        if ((st.valid & ZIP_STAT_COMP_SIZE) == 0) {
  ------------------
  |  |  326|  21.2k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (364:13): [True: 10.8k, False: 10.3k]
  ------------------
  365|  10.8k|            zip_uint64_t max_compressed_size;
  366|  10.8k|            zip_uint16_t compression_method = ZIP_CM_ACTUAL(de->comp_method);
  ------------------
  |  |   87|  10.8k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  10.8k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|  7.57k|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 7.57k, False: 3.29k]
  |  |  ------------------
  ------------------
  367|       |
  368|       |            /* this is technically incorrect (copy_source counts compressed data), but it's the best we have */
  369|  10.8k|            data_length = (zip_int64_t)st.size;
  370|       |
  371|  10.8k|            if (compression_method == ZIP_CM_STORE) {
  ------------------
  |  |  179|  10.8k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (371:17): [True: 0, False: 10.8k]
  ------------------
  372|      0|                max_compressed_size = st.size;
  373|      0|            }
  374|  10.8k|            else {
  375|  10.8k|                zip_compression_algorithm_t *algorithm = _zip_get_compression_algorithm(compression_method, true);
  376|  10.8k|                if (algorithm == NULL) {
  ------------------
  |  Branch (376:21): [True: 0, False: 10.8k]
  ------------------
  377|      0|                    max_compressed_size = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  378|      0|                }
  379|  10.8k|                else {
  380|  10.8k|                    max_compressed_size = algorithm->maximum_compressed_size(st.size);
  381|  10.8k|                }
  382|  10.8k|            }
  383|       |
  384|  10.8k|            if (max_compressed_size > 0xffffffffu) {
  ------------------
  |  Branch (384:17): [True: 0, False: 10.8k]
  ------------------
  385|       |                /* TODO: not valid for torrentzip */
  386|      0|                flags |= ZIP_FL_FORCE_ZIP64;
  ------------------
  |  |  264|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  387|      0|            }
  388|  10.8k|        }
  389|  10.3k|        else {
  390|  10.3k|            de->comp_size = st.comp_size;
  391|  10.3k|            data_length = (zip_int64_t)st.comp_size;
  392|  10.3k|        }
  393|  21.2k|    }
  394|       |
  395|  21.2k|    if ((de->changed & ZIP_DIRENT_LAST_MOD) == 0) {
  ------------------
  |  |  341|  21.2k|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (395:9): [True: 21.2k, False: 0]
  ------------------
  396|  21.2k|        int ret2 = zip_source_get_dos_time(src, &de->last_mod);
  397|  21.2k|        if (ret2 < 0) {
  ------------------
  |  Branch (397:13): [True: 0, False: 21.2k]
  ------------------
  398|      0|            zip_error_set_from_source(&za->error, src);
  399|      0|            return -1;
  400|      0|        }
  401|  21.2k|        if (ret2 == 1) {
  ------------------
  |  Branch (401:13): [True: 0, False: 21.2k]
  ------------------
  402|      0|            have_dos_time = true;
  403|      0|        }
  404|  21.2k|        else {
  405|  21.2k|            if (st.valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  327|  21.2k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (405:17): [True: 21.2k, False: 0]
  ------------------
  406|  21.2k|                mtime_before_copy = st.mtime;
  407|  21.2k|            }
  408|      0|            else {
  409|      0|                time(&mtime_before_copy);
  410|      0|            }
  411|  21.2k|            if (_zip_u2d_time(mtime_before_copy, &de->last_mod, &za->error) < 0) {
  ------------------
  |  Branch (411:17): [True: 0, False: 21.2k]
  ------------------
  412|      0|                return -1;
  413|      0|            }
  414|  21.2k|        }
  415|  21.2k|    }
  416|       |
  417|  21.2k|    if ((offstart = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (417:9): [True: 0, False: 21.2k]
  ------------------
  418|      0|        zip_error_set_from_source(&za->error, za->src);
  419|      0|        return -1;
  420|      0|    }
  421|       |
  422|  21.2k|    needs_recompress = ZIP_WANT_TORRENTZIP(za) || st.comp_method != ZIP_CM_ACTUAL(de->comp_method);
  ------------------
  |  |  523|  42.4k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 21.2k]
  |  |  ------------------
  ------------------
                  needs_recompress = ZIP_WANT_TORRENTZIP(za) || st.comp_method != ZIP_CM_ACTUAL(de->comp_method);
  ------------------
  |  |   87|  42.4k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  21.2k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|  7.57k|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 7.57k, False: 13.6k]
  |  |  ------------------
  ------------------
  |  Branch (422:51): [True: 10.8k, False: 10.3k]
  ------------------
  423|  21.2k|    needs_decompress = needs_recompress && (st.comp_method != ZIP_CM_STORE);
  ------------------
  |  |  179|  10.8k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (423:24): [True: 10.8k, False: 10.3k]
  |  Branch (423:44): [True: 0, False: 10.8k]
  ------------------
  424|       |    /* in these cases we can compute the CRC ourselves, so we do */
  425|  21.2k|    needs_crc = (st.comp_method == ZIP_CM_STORE) || needs_decompress;
  ------------------
  |  |  179|  21.2k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (425:17): [True: 21.2k, False: 0]
  |  Branch (425:53): [True: 0, False: 0]
  ------------------
  426|  21.2k|    needs_compress = needs_recompress && (de->comp_method != ZIP_CM_STORE);
  ------------------
  |  |  179|  10.8k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (426:22): [True: 10.8k, False: 10.3k]
  |  Branch (426:42): [True: 10.8k, False: 0]
  ------------------
  427|       |
  428|  21.2k|    needs_reencrypt = needs_recompress || (de->changed & ZIP_DIRENT_PASSWORD) || (de->encryption_method != st.encryption_method);
  ------------------
  |  |  343|  10.3k|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (428:23): [True: 10.8k, False: 10.3k]
  |  Branch (428:43): [True: 10.3k, False: 0]
  |  Branch (428:82): [True: 0, False: 0]
  ------------------
  429|  21.2k|    needs_decrypt = needs_reencrypt && (st.encryption_method != ZIP_EM_NONE);
  ------------------
  |  |  207|  21.2k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (429:21): [True: 21.2k, False: 0]
  |  Branch (429:40): [True: 0, False: 21.2k]
  ------------------
  430|  21.2k|    needs_encrypt = needs_reencrypt && (de->encryption_method != ZIP_EM_NONE);
  ------------------
  |  |  207|  21.2k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (430:21): [True: 21.2k, False: 0]
  |  Branch (430:40): [True: 9.90k, False: 11.3k]
  ------------------
  431|       |
  432|  21.2k|    src_final = src;
  433|  21.2k|    zip_source_keep(src_final);
  434|       |
  435|  21.2k|    if (!needs_decrypt && st.encryption_method == ZIP_EM_TRAD_PKWARE && (de->changed & ZIP_DIRENT_LAST_MOD)) {
  ------------------
  |  |  208|  42.4k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
                  if (!needs_decrypt && st.encryption_method == ZIP_EM_TRAD_PKWARE && (de->changed & ZIP_DIRENT_LAST_MOD)) {
  ------------------
  |  |  341|      0|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (435:9): [True: 21.2k, False: 0]
  |  Branch (435:27): [True: 0, False: 21.2k]
  |  Branch (435:73): [True: 0, False: 0]
  ------------------
  436|       |        /* PKWare encryption uses the last modification time for password verification, therefore we can't change it without re-encrypting. Ignoring the requested modification time change seems more sensible than failing to close the archive. */
  437|      0|        de->changed &= ~ZIP_DIRENT_LAST_MOD;
  ------------------
  |  |  341|      0|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  438|      0|    }
  439|       |
  440|  21.2k|    if (needs_decrypt) {
  ------------------
  |  Branch (440:9): [True: 0, False: 21.2k]
  ------------------
  441|      0|        zip_encryption_implementation impl;
  442|       |
  443|      0|        if ((impl = _zip_get_encryption_implementation(st.encryption_method, ZIP_CODEC_DECODE)) == NULL) {
  ------------------
  |  |  114|      0|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (443:13): [True: 0, False: 0]
  ------------------
  444|      0|            zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  445|      0|            zip_source_free(src_final);
  446|      0|            return -1;
  447|      0|        }
  448|      0|        if ((src_tmp = impl(za, src_final, st.encryption_method, ZIP_CODEC_DECODE, za->default_password)) == NULL) {
  ------------------
  |  |  114|      0|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (448:13): [True: 0, False: 0]
  ------------------
  449|       |            /* error set by impl */
  450|      0|            zip_source_free(src_final);
  451|      0|            return -1;
  452|      0|        }
  453|       |
  454|      0|        src_final = src_tmp;
  455|      0|    }
  456|       |
  457|  21.2k|    if (needs_decompress) {
  ------------------
  |  Branch (457:9): [True: 0, False: 21.2k]
  ------------------
  458|      0|        if ((src_tmp = zip_source_decompress(za, src_final, st.comp_method)) == NULL) {
  ------------------
  |  Branch (458:13): [True: 0, False: 0]
  ------------------
  459|      0|            zip_source_free(src_final);
  460|      0|            return -1;
  461|      0|        }
  462|       |
  463|      0|        src_final = src_tmp;
  464|      0|    }
  465|       |
  466|  21.2k|    if (needs_crc) {
  ------------------
  |  Branch (466:9): [True: 21.2k, False: 0]
  ------------------
  467|  21.2k|        if ((src_tmp = zip_source_crc_create(src_final, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (467:13): [True: 0, False: 21.2k]
  ------------------
  468|      0|            zip_source_free(src_final);
  469|      0|            return -1;
  470|      0|        }
  471|       |
  472|  21.2k|        src_final = src_tmp;
  473|  21.2k|    }
  474|       |
  475|  21.2k|    if (needs_compress) {
  ------------------
  |  Branch (475:9): [True: 10.8k, False: 10.3k]
  ------------------
  476|  10.8k|        if ((src_tmp = zip_source_compress(za, src_final, de->comp_method, de->compression_level)) == NULL) {
  ------------------
  |  Branch (476:13): [True: 0, False: 10.8k]
  ------------------
  477|      0|            zip_source_free(src_final);
  478|      0|            return -1;
  479|      0|        }
  480|       |
  481|  10.8k|        src_final = src_tmp;
  482|  10.8k|    }
  483|       |
  484|       |
  485|  21.2k|    if (needs_encrypt) {
  ------------------
  |  Branch (485:9): [True: 9.90k, False: 11.3k]
  ------------------
  486|  9.90k|        zip_encryption_implementation impl;
  487|  9.90k|        const char *password = NULL;
  488|       |
  489|  9.90k|        if (de->password) {
  ------------------
  |  Branch (489:13): [True: 9.90k, False: 0]
  ------------------
  490|  9.90k|            password = de->password;
  491|  9.90k|        }
  492|      0|        else if (za->default_password) {
  ------------------
  |  Branch (492:18): [True: 0, False: 0]
  ------------------
  493|      0|            password = za->default_password;
  494|      0|        }
  495|       |
  496|  9.90k|        if ((impl = _zip_get_encryption_implementation(de->encryption_method, ZIP_CODEC_ENCODE)) == NULL) {
  ------------------
  |  |  115|  9.90k|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (496:13): [True: 0, False: 9.90k]
  ------------------
  497|      0|            zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  498|      0|            zip_source_free(src_final);
  499|      0|            return -1;
  500|      0|        }
  501|       |
  502|  9.90k|        if (de->encryption_method == ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|  9.90k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (502:13): [True: 1.34k, False: 8.56k]
  ------------------
  503|  1.34k|            de->bitflags |= ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  254|  1.34k|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  504|       |
  505|       |            /* PKWare encryption uses last_mod, make sure it gets the right value. */
  506|  1.34k|            if (de->changed & ZIP_DIRENT_LAST_MOD) {
  ------------------
  |  |  341|  1.34k|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (506:17): [True: 0, False: 1.34k]
  ------------------
  507|      0|                if ((src_tmp = _zip_source_window_new(src_final, 0, -1, NULL, 0, NULL, &de->last_mod, NULL, 0, true, &za->error)) == NULL) {
  ------------------
  |  Branch (507:21): [True: 0, False: 0]
  ------------------
  508|      0|                    zip_source_free(src_final);
  509|      0|                    return -1;
  510|      0|                }
  511|      0|                src_final = src_tmp;
  512|      0|            }
  513|  1.34k|        }
  514|       |
  515|  9.90k|        if ((src_tmp = impl(za, src_final, de->encryption_method, ZIP_CODEC_ENCODE, password)) == NULL) {
  ------------------
  |  |  115|  9.90k|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (515:13): [True: 0, False: 9.90k]
  ------------------
  516|       |            /* error set by impl */
  517|      0|            zip_source_free(src_final);
  518|      0|            return -1;
  519|      0|        }
  520|       |
  521|  9.90k|        src_final = src_tmp;
  522|  9.90k|    }
  523|       |
  524|  21.2k|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  21.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (524:9): [True: 21.2k, False: 0]
  ------------------
  525|  21.2k|        if (zip_source_get_file_attributes(src_final, &attributes) != 0) {
  ------------------
  |  Branch (525:13): [True: 0, False: 21.2k]
  ------------------
  526|      0|            zip_error_set_from_source(&za->error, src_final);
  527|      0|            zip_source_free(src_final);
  528|      0|            return -1;
  529|      0|        }
  530|  21.2k|        _zip_dirent_apply_attributes(de, &attributes, (flags & ZIP_FL_FORCE_ZIP64) != 0);
  ------------------
  |  |  264|  21.2k|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  531|  21.2k|    }
  532|       |
  533|       |    /* as long as we don't support non-seekable output, clear data descriptor bit */
  534|  21.2k|    if ((is_zip64 = _zip_dirent_write(za, de, flags)) < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 21.2k]
  ------------------
  535|      0|        zip_source_free(src_final);
  536|      0|        return -1;
  537|      0|    }
  538|       |
  539|  21.2k|    if ((offdata = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (539:9): [True: 0, False: 21.2k]
  ------------------
  540|      0|        zip_error_set_from_source(&za->error, za->src);
  541|      0|        zip_source_free(src_final);
  542|      0|        return -1;
  543|      0|    }
  544|       |
  545|  21.2k|    ret = copy_source(za, src_final, src, data_length);
  546|       |
  547|  21.2k|    if (zip_source_stat(src_final, &st) < 0) {
  ------------------
  |  Branch (547:9): [True: 0, False: 21.2k]
  ------------------
  548|      0|        zip_error_set_from_source(&za->error, src_final);
  549|      0|        ret = -1;
  550|      0|    }
  551|       |
  552|  21.2k|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  21.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (552:9): [True: 21.2k, False: 0]
  ------------------
  553|  21.2k|        if (zip_source_get_file_attributes(src_final, &attributes) != 0) {
  ------------------
  |  Branch (553:13): [True: 0, False: 21.2k]
  ------------------
  554|      0|            zip_error_set_from_source(&za->error, src_final);
  555|      0|            ret = -1;
  556|      0|        }
  557|  21.2k|    }
  558|       |
  559|  21.2k|    zip_source_free(src_final);
  560|       |
  561|  21.2k|    if (ret < 0) {
  ------------------
  |  Branch (561:9): [True: 0, False: 21.2k]
  ------------------
  562|      0|        return -1;
  563|      0|    }
  564|       |
  565|  21.2k|    if ((offend = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (565:9): [True: 0, False: 21.2k]
  ------------------
  566|      0|        zip_error_set_from_source(&za->error, za->src);
  567|      0|        return -1;
  568|      0|    }
  569|       |
  570|  21.2k|    if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  329|  21.2k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  328|  21.2k|#define ZIP_STAT_CRC 0x0020u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  325|  21.2k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  329|  21.2k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  328|  21.2k|#define ZIP_STAT_CRC 0x0020u
  ------------------
                  if ((st.valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) != (ZIP_STAT_COMP_METHOD | ZIP_STAT_CRC | ZIP_STAT_SIZE)) {
  ------------------
  |  |  325|  21.2k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (570:9): [True: 0, False: 21.2k]
  ------------------
  571|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  572|      0|        return -1;
  573|      0|    }
  574|       |
  575|  21.2k|    dirent_changed = ZIP_CM_ACTUAL(de->comp_method) != st.comp_method || de->crc != st.crc || de->uncomp_size != st.size || de->comp_size != (zip_uint64_t)(offend - offdata);
  ------------------
  |  |   87|  21.2k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  21.2k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|  7.57k|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 7.57k, False: 13.6k]
  |  |  ------------------
  ------------------
  |  Branch (575:22): [True: 7.19k, False: 14.0k]
  |  Branch (575:74): [True: 11.0k, False: 3.00k]
  |  Branch (575:95): [True: 0, False: 3.00k]
  |  Branch (575:125): [True: 2.12k, False: 887]
  ------------------
  576|  21.2k|    de->comp_method = st.comp_method;
  577|  21.2k|    de->crc = st.crc;
  578|  21.2k|    de->uncomp_size = st.size;
  579|  21.2k|    de->comp_size = (zip_uint64_t)(offend - offdata);
  580|       |
  581|  21.2k|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  21.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (581:9): [True: 21.2k, False: 0]
  ------------------
  582|  21.2k|        dirent_changed |= _zip_dirent_apply_attributes(de, &attributes, (flags & ZIP_FL_FORCE_ZIP64) != 0);
  ------------------
  |  |  264|  21.2k|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  583|       |
  584|  21.2k|        if ((de->changed & ZIP_DIRENT_LAST_MOD) == 0 && !have_dos_time) {
  ------------------
  |  |  341|  21.2k|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (584:13): [True: 21.2k, False: 0]
  |  Branch (584:57): [True: 21.2k, False: 0]
  ------------------
  585|  21.2k|            if (st.valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  327|  21.2k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (585:17): [True: 21.2k, False: 0]
  ------------------
  586|  21.2k|                if (st.mtime != mtime_before_copy) {
  ------------------
  |  Branch (586:21): [True: 0, False: 21.2k]
  ------------------
  587|      0|                    if (_zip_u2d_time(st.mtime, &de->last_mod, &za->error) < 0) {
  ------------------
  |  Branch (587:25): [True: 0, False: 0]
  ------------------
  588|      0|                        return -1;
  589|      0|                    }
  590|      0|                    dirent_changed = true;
  591|      0|                }
  592|  21.2k|            }
  593|  21.2k|        }
  594|  21.2k|    }
  595|       |
  596|  21.2k|    if (dirent_changed) {
  ------------------
  |  Branch (596:9): [True: 20.3k, False: 887]
  ------------------
  597|  20.3k|        if (zip_source_seek_write(za->src, offstart, SEEK_SET) < 0) {
  ------------------
  |  Branch (597:13): [True: 0, False: 20.3k]
  ------------------
  598|      0|            zip_error_set_from_source(&za->error, za->src);
  599|      0|            return -1;
  600|      0|        }
  601|       |
  602|  20.3k|        if ((ret = _zip_dirent_write(za, de, flags)) < 0) {
  ------------------
  |  Branch (602:13): [True: 0, False: 20.3k]
  ------------------
  603|      0|            return -1;
  604|      0|        }
  605|       |
  606|  20.3k|        if (is_zip64 != ret) {
  ------------------
  |  Branch (606:13): [True: 0, False: 20.3k]
  ------------------
  607|       |            /* Zip64 mismatch between preliminary file header written before data and final file header written afterwards */
  608|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  609|      0|            return -1;
  610|      0|        }
  611|       |
  612|  20.3k|        if (zip_source_seek_write(za->src, offend, SEEK_SET) < 0) {
  ------------------
  |  Branch (612:13): [True: 0, False: 20.3k]
  ------------------
  613|      0|            zip_error_set_from_source(&za->error, za->src);
  614|      0|            return -1;
  615|      0|        }
  616|  20.3k|    }
  617|       |
  618|  21.2k|    if (de->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
  ------------------
  |  |  254|  21.2k|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  |  Branch (618:9): [True: 1.34k, False: 19.8k]
  ------------------
  619|  1.34k|        if (write_data_descriptor(za, de, is_zip64) < 0) {
  ------------------
  |  Branch (619:13): [True: 0, False: 1.34k]
  ------------------
  620|      0|            return -1;
  621|      0|        }
  622|  1.34k|    }
  623|       |
  624|  21.2k|    return 0;
  625|  21.2k|}
zip_close.c:copy_source:
  663|  21.2k|static int copy_source(zip_t *za, zip_source_t *src, zip_source_t *src_for_length, zip_int64_t data_length) {
  664|  21.2k|    DEFINE_BYTE_ARRAY(buf, BUFSIZE);
  ------------------
  |  |  477|  21.2k|#define DEFINE_BYTE_ARRAY(buf, size) zip_uint8_t buf[size]
  ------------------
  665|  21.2k|    zip_int64_t n, current;
  666|  21.2k|    int ret;
  667|       |
  668|  21.2k|    if (zip_source_open(src) < 0) {
  ------------------
  |  Branch (668:9): [True: 0, False: 21.2k]
  ------------------
  669|      0|        zip_error_set_from_source(&za->error, src);
  670|      0|        return -1;
  671|      0|    }
  672|       |
  673|  21.2k|    if (!byte_array_init(buf, BUFSIZE)) {
  ------------------
  |  |  478|  21.2k|#define byte_array_init(buf, size) (1)
  ------------------
  |  Branch (673:9): [Folded, False: 21.2k]
  ------------------
  674|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  675|      0|        return -1;
  676|      0|    }
  677|       |
  678|  21.2k|    ret = 0;
  679|  21.2k|    current = 0;
  680|  34.9k|    while ((n = zip_source_read(src, buf, BUFSIZE)) > 0) {
  ------------------
  |  |   66|  34.9k|#define BUFSIZE 8192
  ------------------
  |  Branch (680:12): [True: 13.7k, False: 21.2k]
  ------------------
  681|  13.7k|        if (_zip_write(za, buf, (zip_uint64_t)n) < 0) {
  ------------------
  |  Branch (681:13): [True: 0, False: 13.7k]
  ------------------
  682|      0|            ret = -1;
  683|      0|            break;
  684|      0|        }
  685|  13.7k|        if (n == BUFSIZE && za->progress && data_length > 0) {
  ------------------
  |  |   66|  27.4k|#define BUFSIZE 8192
  ------------------
  |  Branch (685:13): [True: 0, False: 13.7k]
  |  Branch (685:29): [True: 0, False: 0]
  |  Branch (685:45): [True: 0, False: 0]
  ------------------
  686|      0|            zip_int64_t t;
  687|      0|            t = zip_source_tell(src_for_length);
  688|      0|            if (t >= 0) {
  ------------------
  |  Branch (688:17): [True: 0, False: 0]
  ------------------
  689|      0|                current = t;
  690|      0|            }
  691|      0|            else {
  692|      0|                current += n;
  693|      0|            }
  694|      0|            if (_zip_progress_update(za->progress, (double)current / (double)data_length) != 0) {
  ------------------
  |  Branch (694:17): [True: 0, False: 0]
  ------------------
  695|      0|                zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
  ------------------
  |  |  163|      0|#define ZIP_ER_CANCELLED 32       /* N Operation cancelled */
  ------------------
  696|      0|                ret = -1;
  697|      0|                break;
  698|      0|            }
  699|      0|        }
  700|  13.7k|    }
  701|       |
  702|  21.2k|    if (n < 0) {
  ------------------
  |  Branch (702:9): [True: 0, False: 21.2k]
  ------------------
  703|      0|        zip_error_set_from_source(&za->error, src);
  704|      0|        ret = -1;
  705|      0|    }
  706|       |
  707|  21.2k|    byte_array_fini(buf);
  ------------------
  |  |  479|  21.2k|#define byte_array_fini(buf) ((void)0)
  ------------------
  708|       |
  709|  21.2k|    zip_source_close(src);
  710|       |
  711|  21.2k|    return ret;
  712|  21.2k|}
zip_close.c:write_cdir:
  714|  4.78k|static int write_cdir(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) {
  715|  4.78k|    if (zip_source_tell_write(za->src) < 0) {
  ------------------
  |  Branch (715:9): [True: 0, False: 4.78k]
  ------------------
  716|      0|        return -1;
  717|      0|    }
  718|       |
  719|  4.78k|    if (_zip_cdir_write(za, filelist, survivors) < 0) {
  ------------------
  |  Branch (719:9): [True: 0, False: 4.78k]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|  4.78k|    if (zip_source_tell_write(za->src) < 0) {
  ------------------
  |  Branch (723:9): [True: 0, False: 4.78k]
  ------------------
  724|      0|        return -1;
  725|      0|    }
  726|       |
  727|  4.78k|    return 0;
  728|  4.78k|}
zip_close.c:write_data_descriptor:
  758|  1.34k|static int write_data_descriptor(zip_t *za, const zip_dirent_t *de, int is_zip64) {
  759|  1.34k|    zip_buffer_t *buffer = _zip_buffer_new(NULL, MAX_DATA_DESCRIPTOR_LENGTH);
  ------------------
  |  |   69|  1.34k|#define MAX_DATA_DESCRIPTOR_LENGTH 24
  ------------------
  760|  1.34k|    int ret = 0;
  761|       |
  762|  1.34k|    if (buffer == NULL) {
  ------------------
  |  Branch (762:9): [True: 0, False: 1.34k]
  ------------------
  763|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  764|      0|        return -1;
  765|      0|    }
  766|       |
  767|  1.34k|    _zip_buffer_put(buffer, DATADES_MAGIC, 4);
  ------------------
  |  |   54|  1.34k|#define DATADES_MAGIC "PK\7\10"
  ------------------
  768|  1.34k|    _zip_buffer_put_32(buffer, de->crc);
  769|  1.34k|    if (is_zip64) {
  ------------------
  |  Branch (769:9): [True: 0, False: 1.34k]
  ------------------
  770|      0|        _zip_buffer_put_64(buffer, de->comp_size);
  771|      0|        _zip_buffer_put_64(buffer, de->uncomp_size);
  772|      0|    }
  773|  1.34k|    else {
  774|  1.34k|        _zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size);
  775|  1.34k|        _zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size);
  776|  1.34k|    }
  777|       |
  778|  1.34k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (778:9): [True: 0, False: 1.34k]
  ------------------
  779|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  780|      0|        ret = -1;
  781|      0|    }
  782|  1.34k|    else {
  783|  1.34k|        ret = _zip_write(za, _zip_buffer_data(buffer), _zip_buffer_offset(buffer));
  784|  1.34k|    }
  785|       |
  786|  1.34k|    _zip_buffer_free(buffer);
  787|       |
  788|  1.34k|    return ret;
  789|  1.34k|}

_zip_crypto_aes_new:
   65|  16.8k|_zip_crypto_aes_t *_zip_crypto_aes_new(const zip_uint8_t *key, zip_uint16_t key_size, zip_error_t *error) {
   66|  16.8k|    _zip_crypto_aes_t *aes;
  ------------------
  |  |   50|  16.8k|#define _zip_crypto_aes_t EVP_CIPHER_CTX
  ------------------
   67|  16.8k|    const EVP_CIPHER *cipher_type;
   68|       |
   69|  16.8k|    switch (key_size) {
   70|  3.94k|    case 128:
  ------------------
  |  Branch (70:5): [True: 3.94k, False: 12.9k]
  ------------------
   71|  3.94k|        cipher_type = EVP_aes_128_ecb();
   72|  3.94k|        break;
   73|      0|    case 192:
  ------------------
  |  Branch (73:5): [True: 0, False: 16.8k]
  ------------------
   74|      0|        cipher_type = EVP_aes_192_ecb();
   75|      0|        break;
   76|  12.9k|    case 256:
  ------------------
  |  Branch (76:5): [True: 12.9k, False: 3.94k]
  ------------------
   77|  12.9k|        cipher_type = EVP_aes_256_ecb();
   78|  12.9k|        break;
   79|      0|    default:
  ------------------
  |  Branch (79:5): [True: 0, False: 16.8k]
  ------------------
   80|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   81|      0|        return NULL;
   82|  16.8k|    }
   83|       |
   84|       |#ifdef USE_OPENSSL_1_0_API
   85|       |    if ((aes = (_zip_crypto_aes_t *)malloc(sizeof(*aes))) == NULL) {
   86|       |        zip_error_set(error, ZIP_ER_MEMORY, 0);
   87|       |        return NULL;
   88|       |    }
   89|       |    memset(aes, 0, sizeof(*aes));
   90|       |#else
   91|  16.8k|    if ((aes = EVP_CIPHER_CTX_new()) == NULL) {
  ------------------
  |  Branch (91:9): [True: 0, False: 16.8k]
  ------------------
   92|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   93|      0|        return NULL;
   94|      0|    }
   95|  16.8k|#endif
   96|       |
   97|  16.8k|    if (EVP_EncryptInit_ex(aes, cipher_type, NULL, key, NULL) != 1) {
  ------------------
  |  Branch (97:9): [True: 0, False: 16.8k]
  ------------------
   98|       |#ifdef USE_OPENSSL_1_0_API
   99|       |        free(aes);
  100|       |#else
  101|      0|        EVP_CIPHER_CTX_free(aes);
  102|      0|#endif
  103|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  104|      0|        return NULL;
  105|      0|    }
  106|       |
  107|  16.8k|    return aes;
  108|  16.8k|}
_zip_crypto_aes_free:
  110|  16.8k|void _zip_crypto_aes_free(_zip_crypto_aes_t *aes) {
  111|  16.8k|    if (aes == NULL) {
  ------------------
  |  Branch (111:9): [True: 0, False: 16.8k]
  ------------------
  112|      0|        return;
  113|      0|    }
  114|       |
  115|       |#ifdef USE_OPENSSL_1_0_API
  116|       |    EVP_CIPHER_CTX_cleanup(aes);
  117|       |    _zip_crypto_clear(aes, sizeof(*aes));
  118|       |    free(aes);
  119|       |#else
  120|  16.8k|    EVP_CIPHER_CTX_free(aes);
  121|  16.8k|#endif
  122|  16.8k|}
_zip_crypto_aes_encrypt_block:
  125|  1.51M|bool _zip_crypto_aes_encrypt_block(_zip_crypto_aes_t *aes, const zip_uint8_t *in, zip_uint8_t *out) {
  126|  1.51M|    int len = 0;
  127|  1.51M|    if (EVP_EncryptUpdate(aes, out, &len, in, ZIP_CRYPTO_AES_BLOCK_LENGTH) != 1 || len != ZIP_CRYPTO_AES_BLOCK_LENGTH) {
  ------------------
  |  |   38|  1.51M|#define ZIP_CRYPTO_AES_BLOCK_LENGTH 16
  ------------------
                  if (EVP_EncryptUpdate(aes, out, &len, in, ZIP_CRYPTO_AES_BLOCK_LENGTH) != 1 || len != ZIP_CRYPTO_AES_BLOCK_LENGTH) {
  ------------------
  |  |   38|  1.51M|#define ZIP_CRYPTO_AES_BLOCK_LENGTH 16
  ------------------
  |  Branch (127:9): [True: 0, False: 1.51M]
  |  Branch (127:84): [True: 0, False: 1.51M]
  ------------------
  128|      0|        return false;
  129|      0|    }
  130|  1.51M|    return true;
  131|  1.51M|}
_zip_crypto_hmac_new:
  134|  16.8k|_zip_crypto_hmac_t *_zip_crypto_hmac_new(const zip_uint8_t *secret, zip_uint64_t secret_length, zip_error_t *error) {
  135|  16.8k|    _zip_crypto_hmac_t *hmac;
  ------------------
  |  |   59|  16.8k|#define _zip_crypto_hmac_t HMAC_CTX
  ------------------
  136|       |
  137|  16.8k|    if (secret_length > INT_MAX) {
  ------------------
  |  Branch (137:9): [True: 0, False: 16.8k]
  ------------------
  138|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  139|      0|        return NULL;
  140|      0|    }
  141|       |
  142|       |#ifdef USE_OPENSSL_3_API
  143|       |    if ((hmac = hmac_new()) == NULL || (hmac->mac = EVP_MAC_fetch(NULL, "HMAC", "provider=default")) == NULL || (hmac->ctx = EVP_MAC_CTX_new(hmac->mac)) == NULL) {
  144|       |        hmac_free(hmac);
  145|       |        zip_error_set(error, ZIP_ER_MEMORY, 0);
  146|       |        return NULL;
  147|       |    }
  148|       |
  149|       |    {
  150|       |        OSSL_PARAM params[2];
  151|       |        params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0);
  152|       |        params[1] = OSSL_PARAM_construct_end();
  153|       |
  154|       |        if (!EVP_MAC_init(hmac->ctx, (const unsigned char *)secret, secret_length, params)) {
  155|       |            zip_error_set(error, ZIP_ER_INTERNAL, 0);
  156|       |            hmac_free(hmac);
  157|       |            return NULL;
  158|       |        }
  159|       |    }
  160|       |#else
  161|       |#ifdef USE_OPENSSL_1_0_API
  162|       |    if ((hmac = (_zip_crypto_hmac_t *)malloc(sizeof(*hmac))) == NULL) {
  163|       |        zip_error_set(error, ZIP_ER_MEMORY, 0);
  164|       |        return NULL;
  165|       |    }
  166|       |
  167|       |    HMAC_CTX_init(hmac);
  168|       |#else
  169|  16.8k|    if ((hmac = HMAC_CTX_new()) == NULL) {
  ------------------
  |  Branch (169:9): [True: 0, False: 16.8k]
  ------------------
  170|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  171|      0|        return NULL;
  172|      0|    }
  173|  16.8k|#endif
  174|       |
  175|  16.8k|    if (HMAC_Init_ex(hmac, secret, (int)secret_length, EVP_sha1(), NULL) != 1) {
  ------------------
  |  Branch (175:9): [True: 0, False: 16.8k]
  ------------------
  176|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  177|       |#ifdef USE_OPENSSL_1_0_API
  178|       |        free(hmac);
  179|       |#else
  180|      0|        HMAC_CTX_free(hmac);
  181|      0|#endif
  182|      0|        return NULL;
  183|      0|    }
  184|  16.8k|#endif
  185|       |
  186|  16.8k|    return hmac;
  187|  16.8k|}
_zip_crypto_hmac_free:
  190|  16.8k|void _zip_crypto_hmac_free(_zip_crypto_hmac_t *hmac) {
  191|  16.8k|    if (hmac == NULL) {
  ------------------
  |  Branch (191:9): [True: 0, False: 16.8k]
  ------------------
  192|      0|        return;
  193|      0|    }
  194|       |
  195|       |#if defined(USE_OPENSSL_3_API)
  196|       |    hmac_free(hmac);
  197|       |#elif defined(USE_OPENSSL_1_0_API)
  198|       |    HMAC_CTX_cleanup(hmac);
  199|       |    _zip_crypto_clear(hmac, sizeof(*hmac));
  200|       |    free(hmac);
  201|       |#else
  202|  16.8k|    HMAC_CTX_free(hmac);
  203|  16.8k|#endif
  204|  16.8k|}
_zip_crypto_hmac_output:
  207|  16.3k|bool _zip_crypto_hmac_output(_zip_crypto_hmac_t *hmac, zip_uint8_t *data) {
  208|       |#ifdef USE_OPENSSL_3_API
  209|       |    size_t length = 0;
  210|       |    return EVP_MAC_final(hmac->ctx, data, &length, ZIP_CRYPTO_SHA1_LENGTH) == 1 && length == ZIP_CRYPTO_SHA1_LENGTH;
  211|       |#else
  212|  16.3k|    unsigned int length = 0;
  213|  16.3k|    return HMAC_Final(hmac, data, &length) == 1 && length == ZIP_CRYPTO_SHA1_LENGTH;
  ------------------
  |  |   37|  32.7k|#define ZIP_CRYPTO_SHA1_LENGTH 20
  ------------------
  |  Branch (213:12): [True: 16.3k, False: 0]
  |  Branch (213:52): [True: 16.3k, False: 0]
  ------------------
  214|  16.3k|#endif
  215|  16.3k|}
zip_secure_random:
  218|  9.90k|bool zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
  219|  9.90k|    return RAND_bytes(buffer, length) == 1;
  220|  9.90k|}

zip_delete:
   38|    669|ZIP_EXTERN int zip_delete(zip_t *za, zip_uint64_t idx) {
   39|    669|    const char *name;
   40|       |
   41|    669|    if (idx >= za->nentry) {
  ------------------
  |  Branch (41:9): [True: 0, False: 669]
  ------------------
   42|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|    669|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|    669|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|    669|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 669]
  |  |  ------------------
  ------------------
   47|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|    669|    if ((name = _zip_get_name(za, idx, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (51:9): [True: 185, False: 484]
  ------------------
   52|    185|        return -1;
   53|    185|    }
   54|       |
   55|    484|    if (!_zip_hash_delete(za->names, (const zip_uint8_t *)name, &za->error)) {
  ------------------
  |  Branch (55:9): [True: 0, False: 484]
  ------------------
   56|      0|        return -1;
   57|      0|    }
   58|       |
   59|       |    /* allow duplicate file names, because the file will
   60|       |     * be removed directly afterwards */
   61|    484|    if (_zip_unchange(za, idx, 1) != 0) {
  ------------------
  |  Branch (61:9): [True: 0, False: 484]
  ------------------
   62|      0|        return -1;
   63|      0|    }
   64|       |
   65|    484|    za->entry[idx].deleted = 1;
   66|       |
   67|    484|    return 0;
   68|    484|}

zip_dir_add:
   42|  7.65k|ZIP_EXTERN zip_int64_t zip_dir_add(zip_t *za, const char *name, zip_flags_t flags) {
   43|  7.65k|    size_t len;
   44|  7.65k|    zip_int64_t idx;
   45|  7.65k|    char *s;
   46|  7.65k|    zip_source_t *source;
   47|       |
   48|  7.65k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  7.65k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  7.65k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 7.65k]
  |  |  ------------------
  ------------------
   49|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   50|      0|        return -1;
   51|      0|    }
   52|       |
   53|  7.65k|    if (name == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 7.65k]
  ------------------
   54|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   55|      0|        return -1;
   56|      0|    }
   57|       |
   58|  7.65k|    s = NULL;
   59|  7.65k|    len = strlen(name);
   60|       |
   61|  7.65k|    if (len == 0 || name[len - 1] != '/') {
  ------------------
  |  Branch (61:9): [True: 0, False: 7.65k]
  |  Branch (61:21): [True: 7.53k, False: 118]
  ------------------
   62|  7.53k|        if (len > SIZE_MAX - 2 || (s = (char *)malloc(len + 2)) == NULL) {
  ------------------
  |  Branch (62:13): [True: 0, False: 7.53k]
  |  Branch (62:35): [True: 0, False: 7.53k]
  ------------------
   63|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   64|      0|            return -1;
   65|      0|        }
   66|  7.53k|        (void)strncpy_s(s, len + 2, name, len);
  ------------------
  |  |  222|  7.53k|#define strncpy_s(dest, destsz, src, count) (strncpy((dest), (src), (count)), 0)
  ------------------
   67|  7.53k|        s[len] = '/';
   68|  7.53k|        s[len + 1] = '\0';
   69|  7.53k|    }
   70|       |
   71|  7.65k|    if ((source = zip_source_buffer(za, NULL, 0, 0)) == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 7.65k]
  ------------------
   72|      0|        free(s);
   73|      0|        return -1;
   74|      0|    }
   75|       |
   76|  7.65k|    idx = _zip_file_replace(za, ZIP_UINT64_MAX, s ? s : name, source, flags);
  ------------------
  |  |   46|  7.65k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (76:49): [True: 7.53k, False: 118]
  ------------------
   77|       |
   78|  7.65k|    free(s);
   79|       |
   80|  7.65k|    if (idx < 0) {
  ------------------
  |  Branch (80:9): [True: 771, False: 6.88k]
  ------------------
   81|    771|        zip_source_free(source);
   82|    771|    }
   83|  6.88k|    else {
   84|  6.88k|        if (zip_file_set_external_attributes(za, (zip_uint64_t)idx, 0, ZIP_OPSYS_DEFAULT, ZIP_EXT_ATTRIB_DEFAULT_DIR) < 0) {
  ------------------
  |  |  246|  6.88k|#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
  |  |  ------------------
  |  |  |  |  228|  6.88k|#define ZIP_OPSYS_UNIX 0x03u
  |  |  ------------------
  ------------------
                      if (zip_file_set_external_attributes(za, (zip_uint64_t)idx, 0, ZIP_OPSYS_DEFAULT, ZIP_EXT_ATTRIB_DEFAULT_DIR) < 0) {
  ------------------
  |  |   99|  6.88k|#define ZIP_EXT_ATTRIB_DEFAULT_DIR (0040777u << 16)
  ------------------
  |  Branch (84:13): [True: 0, False: 6.88k]
  ------------------
   85|      0|            zip_delete(za, (zip_uint64_t)idx);
   86|      0|            return -1;
   87|      0|        }
   88|  6.88k|    }
   89|       |
   90|  7.65k|    return idx;
   91|  7.65k|}

_zip_cdir_free:
   49|  8.77k|void _zip_cdir_free(zip_cdir_t *cd) {
   50|  8.77k|    zip_uint64_t i;
   51|       |
   52|  8.77k|    if (cd == NULL) {
  ------------------
  |  Branch (52:9): [True: 0, False: 8.77k]
  ------------------
   53|      0|        return;
   54|      0|    }
   55|       |
   56|  50.1M|    for (i = 0; i < cd->nentry; i++) {
  ------------------
  |  Branch (56:17): [True: 50.1M, False: 8.77k]
  ------------------
   57|  50.1M|        _zip_entry_finalize(cd->entry + i);
   58|  50.1M|    }
   59|  8.77k|    free(cd->entry);
   60|  8.77k|    _zip_string_free(cd->comment);
   61|  8.77k|    free(cd);
   62|  8.77k|}
_zip_cdir_new:
   65|  11.4k|zip_cdir_t *_zip_cdir_new(zip_error_t *error) {
   66|  11.4k|    zip_cdir_t *cd;
   67|       |
   68|  11.4k|    if ((cd = (zip_cdir_t *)malloc(sizeof(*cd))) == NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 11.4k]
  ------------------
   69|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   70|      0|        return NULL;
   71|      0|    }
   72|       |
   73|  11.4k|    cd->entry = NULL;
   74|  11.4k|    cd->nentry = cd->nentry_alloc = 0;
   75|  11.4k|    cd->size = cd->offset = 0;
   76|  11.4k|    cd->comment = NULL;
   77|  11.4k|    cd->is_zip64 = false;
   78|       |
   79|  11.4k|    return cd;
   80|  11.4k|}
_zip_cdir_grow:
   83|  4.15k|bool _zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error) {
   84|  4.15k|    zip_uint64_t i;
   85|       |
   86|  4.15k|    if (additional_entries == 0) {
  ------------------
  |  Branch (86:9): [True: 700, False: 3.45k]
  ------------------
   87|    700|        return true;
   88|    700|    }
   89|       |
   90|  3.45k|    if (!ZIP_REALLOC(cd->entry, cd->nentry_alloc, additional_entries, error)) {
  ------------------
  |  |  107|  3.45k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (90:9): [True: 0, False: 3.45k]
  ------------------
   91|      0|        return false;
   92|      0|    }
   93|       |
   94|  50.1M|    for (i = cd->nentry; i < cd->nentry_alloc; i++) {
  ------------------
  |  Branch (94:26): [True: 50.1M, False: 3.45k]
  ------------------
   95|  50.1M|        _zip_entry_init(cd->entry + i);
   96|  50.1M|    }
   97|       |
   98|  3.45k|    cd->nentry = cd->nentry_alloc;
   99|       |
  100|       |    return true;
  101|  3.45k|}
_zip_cdir_write:
  104|  4.78k|zip_int64_t _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors) {
  105|  4.78k|    zip_uint64_t offset, size;
  106|  4.78k|    zip_string_t *comment;
  107|  4.78k|    zip_uint8_t buf[EOCDLEN + EOCD64LEN + EOCD64LOCLEN];
  108|  4.78k|    zip_buffer_t *buffer;
  109|  4.78k|    zip_int64_t off;
  110|  4.78k|    zip_uint64_t i;
  111|  4.78k|    zip_uint32_t cdir_crc;
  112|       |
  113|  4.78k|    if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (113:9): [True: 0, False: 4.78k]
  ------------------
  114|      0|        zip_error_set_from_source(&za->error, za->src);
  115|      0|        return -1;
  116|      0|    }
  117|  4.78k|    offset = (zip_uint64_t)off;
  118|       |
  119|  4.78k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  4.78k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  4.78k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
  120|      0|        cdir_crc = (zip_uint32_t)crc32(0, NULL, 0);
  121|      0|        za->write_crc = &cdir_crc;
  122|      0|    }
  123|       |
  124|  26.0k|    for (i = 0; i < survivors; i++) {
  ------------------
  |  Branch (124:17): [True: 21.2k, False: 4.78k]
  ------------------
  125|  21.2k|        zip_entry_t *entry = za->entry + filelist[i].idx;
  126|       |
  127|  21.2k|        if (_zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL) < 0) {
  ------------------
  |  |  105|  21.2k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
  |  Branch (127:13): [True: 0, False: 21.2k]
  |  Branch (127:35): [True: 21.2k, False: 0]
  ------------------
  128|      0|            za->write_crc = NULL;
  129|      0|            return -1;
  130|      0|        }
  131|  21.2k|    }
  132|       |
  133|  4.78k|    za->write_crc = NULL;
  134|       |
  135|  4.78k|    if ((off = zip_source_tell_write(za->src)) < 0) {
  ------------------
  |  Branch (135:9): [True: 0, False: 4.78k]
  ------------------
  136|      0|        zip_error_set_from_source(&za->error, za->src);
  137|      0|        return -1;
  138|      0|    }
  139|  4.78k|    size = (zip_uint64_t)off - offset;
  140|       |
  141|  4.78k|    if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
  ------------------
  |  Branch (141:9): [True: 0, False: 4.78k]
  ------------------
  142|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  143|      0|        return -1;
  144|      0|    }
  145|       |
  146|  4.78k|    if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) {
  ------------------
  |  |   38|  9.57k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
                  if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  9.57k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (survivors > ZIP_UINT16_MAX || offset > ZIP_UINT32_MAX || size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  4.78k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (146:9): [True: 0, False: 4.78k]
  |  Branch (146:39): [True: 0, False: 4.78k]
  |  Branch (146:66): [True: 0, False: 4.78k]
  ------------------
  147|      0|        _zip_buffer_put(buffer, EOCD64_MAGIC, 4);
  ------------------
  |  |   56|      0|#define EOCD64_MAGIC "PK\6\6"
  ------------------
  148|      0|        _zip_buffer_put_64(buffer, EOCD64LEN - 12);
  ------------------
  |  |   64|      0|#define EOCD64LEN 56
  ------------------
  149|      0|        _zip_buffer_put_16(buffer, 45);
  150|      0|        _zip_buffer_put_16(buffer, 45);
  151|      0|        _zip_buffer_put_32(buffer, 0);
  152|      0|        _zip_buffer_put_32(buffer, 0);
  153|      0|        _zip_buffer_put_64(buffer, survivors);
  154|      0|        _zip_buffer_put_64(buffer, survivors);
  155|      0|        _zip_buffer_put_64(buffer, size);
  156|      0|        _zip_buffer_put_64(buffer, offset);
  157|      0|        _zip_buffer_put(buffer, EOCD64LOC_MAGIC, 4);
  ------------------
  |  |   55|      0|#define EOCD64LOC_MAGIC "PK\6\7"
  ------------------
  158|      0|        _zip_buffer_put_32(buffer, 0);
  159|      0|        _zip_buffer_put_64(buffer, offset + size);
  160|      0|        _zip_buffer_put_32(buffer, 1);
  161|      0|    }
  162|       |
  163|  4.78k|    _zip_buffer_put(buffer, EOCD_MAGIC, 4);
  ------------------
  |  |   53|  4.78k|#define EOCD_MAGIC "PK\5\6"
  ------------------
  164|  4.78k|    _zip_buffer_put_32(buffer, 0);
  165|  4.78k|    _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|  4.78k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
                  _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (165:47): [True: 0, False: 4.78k]
  ------------------
  166|  4.78k|    _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|  4.78k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
                  _zip_buffer_put_16(buffer, (zip_uint16_t)(survivors >= ZIP_UINT16_MAX ? ZIP_UINT16_MAX : survivors));
  ------------------
  |  |   38|      0|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (166:47): [True: 0, False: 4.78k]
  ------------------
  167|  4.78k|    _zip_buffer_put_32(buffer, size >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)size);
  ------------------
  |  |   42|  4.78k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  _zip_buffer_put_32(buffer, size >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)size);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (167:32): [True: 0, False: 4.78k]
  ------------------
  168|  4.78k|    _zip_buffer_put_32(buffer, offset >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)offset);
  ------------------
  |  |   42|  4.78k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  _zip_buffer_put_32(buffer, offset >= ZIP_UINT32_MAX ? ZIP_UINT32_MAX : (zip_uint32_t)offset);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (168:32): [True: 0, False: 4.78k]
  ------------------
  169|       |
  170|  4.78k|    comment = za->comment_changed ? za->comment_changes : za->comment_orig;
  ------------------
  |  Branch (170:15): [True: 514, False: 4.27k]
  ------------------
  171|       |
  172|  4.78k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  4.78k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  4.78k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
  173|      0|        _zip_buffer_put_16(buffer, TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   72|      0|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
                      _zip_buffer_put_16(buffer, TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   73|      0|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  174|      0|    }
  175|  4.78k|    else {
  176|  4.78k|        _zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0));
  ------------------
  |  Branch (176:51): [True: 514, False: 4.27k]
  ------------------
  177|  4.78k|    }
  178|       |
  179|       |
  180|  4.78k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (180:9): [True: 0, False: 4.78k]
  ------------------
  181|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  182|      0|        _zip_buffer_free(buffer);
  183|      0|        return -1;
  184|      0|    }
  185|       |
  186|  4.78k|    if (_zip_write(za, _zip_buffer_data(buffer), _zip_buffer_offset(buffer)) < 0) {
  ------------------
  |  Branch (186:9): [True: 0, False: 4.78k]
  ------------------
  187|      0|        _zip_buffer_free(buffer);
  188|      0|        return -1;
  189|      0|    }
  190|       |
  191|  4.78k|    _zip_buffer_free(buffer);
  192|       |
  193|  4.78k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  4.78k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  4.78k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
  194|      0|        char torrentzip_comment[TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH + 1];
  195|      0|        snprintf(torrentzip_comment, sizeof(torrentzip_comment), TORRENTZIP_SIGNATURE "%08X", cdir_crc);
  ------------------
  |  |   71|      0|#define TORRENTZIP_SIGNATURE "TORRENTZIPPED-"
  ------------------
  196|       |
  197|      0|        if (_zip_write(za, torrentzip_comment, strlen(torrentzip_comment)) < 0) {
  ------------------
  |  Branch (197:13): [True: 0, False: 0]
  ------------------
  198|      0|            return -1;
  199|      0|        }
  200|      0|    }
  201|  4.78k|    else if (comment != NULL) {
  ------------------
  |  Branch (201:14): [True: 514, False: 4.27k]
  ------------------
  202|    514|        if (_zip_write(za, comment->raw, comment->length) < 0) {
  ------------------
  |  Branch (202:13): [True: 0, False: 514]
  ------------------
  203|      0|            return -1;
  204|      0|        }
  205|    514|    }
  206|       |
  207|  4.78k|    return (zip_int64_t)size;
  208|  4.78k|}
_zip_dirent_clone:
  211|  21.7k|zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *sde) {
  212|  21.7k|    zip_dirent_t *tde;
  213|       |
  214|  21.7k|    if ((tde = (zip_dirent_t *)malloc(sizeof(*tde))) == NULL) {
  ------------------
  |  Branch (214:9): [True: 0, False: 21.7k]
  ------------------
  215|      0|        return NULL;
  216|      0|    }
  217|       |
  218|  21.7k|    if (sde) {
  ------------------
  |  Branch (218:9): [True: 0, False: 21.7k]
  ------------------
  219|      0|        (void)memcpy_s(tde, sizeof(*tde), sde, sizeof(*sde));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  220|      0|        _zip_extra_fields_clone(&tde->extra_fields, NULL);
  221|      0|    }
  222|  21.7k|    else {
  223|  21.7k|        _zip_dirent_init(tde);
  224|  21.7k|    }
  225|       |
  226|  21.7k|    tde->changed = 0;
  227|  21.7k|    tde->cloned = 1;
  228|       |
  229|  21.7k|    return tde;
  230|  21.7k|}
_zip_dirent_finalize:
  233|  41.3k|void _zip_dirent_finalize(zip_dirent_t *zde) {
  234|  41.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  337|  21.7k|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (234:9): [True: 19.6k, False: 21.7k]
  |  Branch (234:25): [True: 21.7k, False: 0]
  ------------------
  235|  41.3k|        _zip_string_free(zde->filename);
  236|  41.3k|        zde->filename = NULL;
  237|  41.3k|    }
  238|  41.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_EXTRA_FIELD) {
  ------------------
  |  |  339|  21.7k|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  |  Branch (238:9): [True: 19.6k, False: 21.7k]
  |  Branch (238:25): [True: 21.7k, False: 0]
  ------------------
  239|  41.3k|        _zip_extra_fields_fini(&zde->extra_fields);
  240|  41.3k|    }
  241|  41.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_COMMENT) {
  ------------------
  |  |  338|  21.7k|#define ZIP_DIRENT_COMMENT 0x0004u
  ------------------
  |  Branch (241:9): [True: 19.6k, False: 21.7k]
  |  Branch (241:25): [True: 2.41k, False: 19.2k]
  ------------------
  242|  22.0k|        _zip_string_free(zde->comment);
  243|  22.0k|        zde->comment = NULL;
  244|  22.0k|    }
  245|  41.3k|    if (!zde->cloned || zde->changed & ZIP_DIRENT_PASSWORD) {
  ------------------
  |  |  343|  21.7k|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (245:9): [True: 19.6k, False: 21.7k]
  |  Branch (245:25): [True: 14.8k, False: 6.88k]
  ------------------
  246|  34.4k|        if (zde->password) {
  ------------------
  |  Branch (246:13): [True: 14.8k, False: 19.6k]
  ------------------
  247|  14.8k|            _zip_crypto_clear(zde->password, strlen(zde->password));
  ------------------
  |  |  533|  14.8k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  248|  14.8k|        }
  249|  34.4k|        free(zde->password);
  250|       |        zde->password = NULL;
  251|  34.4k|    }
  252|  41.3k|}
_zip_dirent_free:
  255|   100M|void _zip_dirent_free(zip_dirent_t *zde) {
  256|   100M|    if (zde == NULL) {
  ------------------
  |  Branch (256:9): [True: 100M, False: 41.3k]
  ------------------
  257|   100M|        return;
  258|   100M|    }
  259|       |
  260|  41.3k|    _zip_dirent_finalize(zde);
  261|  41.3k|    free(zde);
  262|  41.3k|}
_zip_dirent_init:
  313|  60.7k|void _zip_dirent_init(zip_dirent_t *de) {
  314|  60.7k|    de->changed = 0;
  315|  60.7k|    de->local_extra_fields_read = 0;
  316|  60.7k|    de->cloned = 0;
  317|       |
  318|  60.7k|    de->crc_valid = true;
  319|  60.7k|    de->last_mod_mtime_valid = false;
  320|  60.7k|    de->version_madeby = 63 | (ZIP_OPSYS_DEFAULT << 8);
  ------------------
  |  |  246|  60.7k|#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
  |  |  ------------------
  |  |  |  |  228|  60.7k|#define ZIP_OPSYS_UNIX 0x03u
  |  |  ------------------
  ------------------
  321|  60.7k|    de->version_needed = 10; /* 1.0 */
  322|  60.7k|    de->bitflags = 0;
  323|  60.7k|    de->comp_method = ZIP_CM_DEFAULT;
  ------------------
  |  |  178|  60.7k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  324|  60.7k|    de->last_mod.date = 0;
  325|  60.7k|    de->last_mod.time = 0;
  326|  60.7k|    de->crc = 0;
  327|  60.7k|    de->comp_size = 0;
  328|  60.7k|    de->uncomp_size = 0;
  329|  60.7k|    de->filename = NULL;
  330|  60.7k|    _zip_extra_fields_init(&de->extra_fields);
  331|  60.7k|    de->comment = NULL;
  332|  60.7k|    de->disk_number = 0;
  333|  60.7k|    de->int_attrib = 0;
  334|  60.7k|    de->ext_attrib = ZIP_EXT_ATTRIB_DEFAULT;
  ------------------
  |  |   97|  60.7k|#define ZIP_EXT_ATTRIB_DEFAULT (0100666u << 16)
  ------------------
  335|  60.7k|    de->offset = 0;
  336|  60.7k|    de->compression_level = 0;
  337|  60.7k|    de->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  60.7k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  338|       |    de->password = NULL;
  339|  60.7k|}
_zip_dirent_needs_zip64:
  342|  88.0k|bool _zip_dirent_needs_zip64(const zip_dirent_t *de, zip_flags_t flags) {
  343|  88.0k|    if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |   42|   176k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |   42|   176k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |  105|  88.0k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
                  if (de->uncomp_size >= ZIP_UINT32_MAX || de->comp_size >= ZIP_UINT32_MAX || ((flags & ZIP_FL_CENTRAL) && de->offset >= ZIP_UINT32_MAX)) {
  ------------------
  |  |   42|  21.2k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (343:9): [True: 0, False: 88.0k]
  |  Branch (343:46): [True: 0, False: 88.0k]
  |  Branch (343:82): [True: 21.2k, False: 66.8k]
  |  Branch (343:110): [True: 0, False: 21.2k]
  ------------------
  344|      0|        return true;
  345|      0|    }
  346|       |
  347|  88.0k|    return false;
  348|  88.0k|}
_zip_dirent_new:
  351|  19.6k|zip_dirent_t *_zip_dirent_new(void) {
  352|  19.6k|    zip_dirent_t *de;
  353|       |
  354|  19.6k|    if ((de = (zip_dirent_t *)malloc(sizeof(*de))) == NULL) {
  ------------------
  |  Branch (354:9): [True: 0, False: 19.6k]
  ------------------
  355|      0|        return NULL;
  356|      0|    }
  357|       |
  358|  19.6k|    _zip_dirent_init(de);
  359|  19.6k|    return de;
  360|  19.6k|}
_zip_dirent_read:
  373|  19.6k|zip_int64_t _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, bool is_zip64, zip_uint64_t central_compressed_size, bool check_consistency, zip_error_t *error) {
  374|  19.6k|    zip_uint8_t buf[CDENTRYSIZE];
  375|  19.6k|    zip_uint32_t size, variable_size;
  376|  19.6k|    zip_uint16_t filename_len, comment_len, ef_len;
  377|  19.6k|    zip_string_t *utf8_string;
  378|  19.6k|    zip_extra_field_t **efp;
  379|       |
  380|  19.6k|    bool from_buffer = (buffer != NULL);
  381|       |
  382|  19.6k|    size = local ? LENTRYSIZE : CDENTRYSIZE;
  ------------------
  |  |   59|      0|#define LENTRYSIZE 30
  ------------------
                  size = local ? LENTRYSIZE : CDENTRYSIZE;
  ------------------
  |  |   58|  39.2k|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (382:12): [True: 0, False: 19.6k]
  ------------------
  383|       |
  384|  19.6k|    if (buffer) {
  ------------------
  |  Branch (384:9): [True: 19.6k, False: 0]
  ------------------
  385|  19.6k|        if (_zip_buffer_left(buffer) < size) {
  ------------------
  |  Branch (385:13): [True: 165, False: 19.4k]
  ------------------
  386|    165|            zip_error_set(error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|    165|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  387|    165|            return -1;
  388|    165|        }
  389|  19.6k|    }
  390|      0|    else {
  391|      0|        if ((buffer = _zip_buffer_new_from_source(src, size, buf, error)) == NULL) {
  ------------------
  |  Branch (391:13): [True: 0, False: 0]
  ------------------
  392|      0|            return -1;
  393|      0|        }
  394|      0|    }
  395|       |
  396|  19.4k|    if (memcmp(_zip_buffer_get(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
  ------------------
  |  |   52|      0|#define LOCAL_MAGIC "PK\3\4"
  ------------------
                  if (memcmp(_zip_buffer_get(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
  ------------------
  |  |   51|  19.4k|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (396:9): [True: 18, False: 19.4k]
  |  Branch (396:45): [True: 0, False: 19.4k]
  ------------------
  397|     18|        zip_error_set(error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|     18|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  398|     18|        if (!from_buffer) {
  ------------------
  |  Branch (398:13): [True: 0, False: 18]
  ------------------
  399|      0|            _zip_buffer_free(buffer);
  400|      0|        }
  401|     18|        return -1;
  402|     18|    }
  403|       |
  404|       |    /* convert buffercontents to zip_dirent */
  405|       |
  406|  19.4k|    _zip_dirent_init(zde);
  407|  19.4k|    if (!local) {
  ------------------
  |  Branch (407:9): [True: 19.4k, False: 0]
  ------------------
  408|  19.4k|        zde->version_madeby = _zip_buffer_get_16(buffer);
  409|  19.4k|    }
  410|      0|    else {
  411|      0|        zde->version_madeby = 0;
  412|      0|    }
  413|  19.4k|    zde->version_needed = _zip_buffer_get_16(buffer);
  414|  19.4k|    zde->bitflags = _zip_buffer_get_16(buffer);
  415|  19.4k|    zde->comp_method = _zip_buffer_get_16(buffer);
  416|       |
  417|       |    /* convert to time_t */
  418|  19.4k|    zde->last_mod.time = _zip_buffer_get_16(buffer);
  419|  19.4k|    zde->last_mod.date = _zip_buffer_get_16(buffer);
  420|       |
  421|  19.4k|    zde->crc = _zip_buffer_get_32(buffer);
  422|  19.4k|    zde->comp_size = _zip_buffer_get_32(buffer);
  423|  19.4k|    zde->uncomp_size = _zip_buffer_get_32(buffer);
  424|       |
  425|  19.4k|    filename_len = _zip_buffer_get_16(buffer);
  426|  19.4k|    ef_len = _zip_buffer_get_16(buffer);
  427|       |
  428|  19.4k|    if (local) {
  ------------------
  |  Branch (428:9): [True: 0, False: 19.4k]
  ------------------
  429|      0|        comment_len = 0;
  430|      0|        zde->disk_number = 0;
  431|      0|        zde->int_attrib = 0;
  432|      0|        zde->ext_attrib = 0;
  433|      0|        zde->offset = 0;
  434|      0|    }
  435|  19.4k|    else {
  436|  19.4k|        comment_len = _zip_buffer_get_16(buffer);
  437|  19.4k|        zde->disk_number = _zip_buffer_get_16(buffer);
  438|  19.4k|        zde->int_attrib = _zip_buffer_get_16(buffer);
  439|  19.4k|        zde->ext_attrib = _zip_buffer_get_32(buffer);
  440|  19.4k|        zde->offset = _zip_buffer_get_32(buffer);
  441|  19.4k|    }
  442|       |
  443|  19.4k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (443:9): [True: 0, False: 19.4k]
  ------------------
  444|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  445|      0|        if (!from_buffer) {
  ------------------
  |  Branch (445:13): [True: 0, False: 0]
  ------------------
  446|      0|            _zip_buffer_free(buffer);
  447|      0|        }
  448|      0|        return -1;
  449|      0|    }
  450|       |
  451|  19.4k|    if (zde->bitflags & ZIP_GPBF_ENCRYPTED) {
  ------------------
  |  |  253|  19.4k|#define ZIP_GPBF_ENCRYPTED 0x0001u         /* is encrypted */
  ------------------
  |  Branch (451:9): [True: 10.1k, False: 9.24k]
  ------------------
  452|  10.1k|        if (zde->bitflags & ZIP_GPBF_STRONG_ENCRYPTION) {
  ------------------
  |  |  255|  10.1k|#define ZIP_GPBF_STRONG_ENCRYPTION 0x0040u /* uses strong encryption */
  ------------------
  |  Branch (452:13): [True: 654, False: 9.54k]
  ------------------
  453|       |            /* TODO */
  454|    654|            zde->encryption_method = ZIP_EM_UNKNOWN;
  ------------------
  |  |  223|    654|#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
  ------------------
  455|    654|        }
  456|  9.54k|        else {
  457|  9.54k|            zde->encryption_method = ZIP_EM_TRAD_PKWARE;
  ------------------
  |  |  208|  9.54k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  458|  9.54k|        }
  459|  10.1k|    }
  460|  9.24k|    else {
  461|  9.24k|        zde->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  9.24k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  462|  9.24k|    }
  463|       |
  464|  19.4k|    zde->filename = NULL;
  465|  19.4k|    _zip_extra_fields_init(&zde->extra_fields);
  466|  19.4k|    zde->comment = NULL;
  467|       |
  468|  19.4k|    variable_size = (zip_uint32_t)filename_len + (zip_uint32_t)ef_len + (zip_uint32_t)comment_len;
  469|       |
  470|  19.4k|    if (from_buffer) {
  ------------------
  |  Branch (470:9): [True: 19.4k, False: 0]
  ------------------
  471|  19.4k|        if (_zip_buffer_left(buffer) < variable_size) {
  ------------------
  |  Branch (471:13): [True: 16, False: 19.4k]
  ------------------
  472|     16|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  152|     16|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  233|     16|#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW 12           /* E variable size fields overflow header */
  ------------------
  473|     16|            return -1;
  474|     16|        }
  475|  19.4k|    }
  476|      0|    else {
  477|      0|        _zip_buffer_free(buffer);
  478|       |
  479|      0|        if ((buffer = _zip_buffer_new_from_source(src, variable_size, NULL, error)) == NULL) {
  ------------------
  |  Branch (479:13): [True: 0, False: 0]
  ------------------
  480|      0|            return -1;
  481|      0|        }
  482|      0|    }
  483|       |
  484|  19.4k|    if (filename_len) {
  ------------------
  |  Branch (484:9): [True: 18.6k, False: 763]
  ------------------
  485|  18.6k|        zde->filename = _zip_read_string(buffer, src, filename_len, 1, error);
  486|  18.6k|        if (zde->filename == NULL) {
  ------------------
  |  Branch (486:13): [True: 0, False: 18.6k]
  ------------------
  487|      0|            if (zip_error_code_zip(error) == ZIP_ER_EOF) {
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  |  Branch (487:17): [True: 0, False: 0]
  ------------------
  488|      0|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
  ------------------
  |  |  233|      0|#define ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW 12           /* E variable size fields overflow header */
  ------------------
  489|      0|            }
  490|      0|            if (!from_buffer) {
  ------------------
  |  Branch (490:17): [True: 0, False: 0]
  ------------------
  491|      0|                _zip_buffer_free(buffer);
  492|      0|            }
  493|      0|            return -1;
  494|      0|        }
  495|       |
  496|  18.6k|        if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
  ------------------
  |  |  256|  18.6k|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  |  Branch (496:13): [True: 230, False: 18.4k]
  ------------------
  497|    230|            if (_zip_guess_encoding(zde->filename, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (497:17): [True: 2, False: 228]
  ------------------
  498|      2|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME);
  ------------------
  |  |  152|      2|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME);
  ------------------
  |  |  234|      2|#define ZIP_ER_DETAIL_INVALID_UTF8_IN_FILENAME 13         /* E invalid UTF-8 in filename */
  ------------------
  499|      2|                if (!from_buffer) {
  ------------------
  |  Branch (499:21): [True: 0, False: 2]
  ------------------
  500|      0|                    _zip_buffer_free(buffer);
  501|      0|                }
  502|      2|                return -1;
  503|      2|            }
  504|    230|        }
  505|       |
  506|  18.6k|        if (check_consistency) {
  ------------------
  |  Branch (506:13): [True: 0, False: 18.6k]
  ------------------
  507|      0|            zip_uint8_t *p;
  508|       |
  509|      0|            for (p = zde->filename->raw; p < zde->filename->raw + zde->filename->length; p++) {
  ------------------
  |  Branch (509:42): [True: 0, False: 0]
  ------------------
  510|      0|                if (*p == 0) {
  ------------------
  |  Branch (510:21): [True: 0, False: 0]
  ------------------
  511|      0|                    zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_NUL_IN_FILENAME);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                                  zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_NUL_IN_FILENAME);
  ------------------
  |  |  247|      0|#define ZIP_ER_DETAIL_NUL_IN_FILENAME 26                  /* E NUL byte in file name */
  ------------------
  512|      0|                    if (!from_buffer) {
  ------------------
  |  Branch (512:25): [True: 0, False: 0]
  ------------------
  513|      0|                        _zip_buffer_free(buffer);
  514|      0|                    }
  515|      0|                    return -1;
  516|      0|                }
  517|      0|            }
  518|      0|        }
  519|  18.6k|    }
  520|       |
  521|  19.4k|    if (ef_len) {
  ------------------
  |  Branch (521:9): [True: 9.06k, False: 10.3k]
  ------------------
  522|  9.06k|        zip_uint8_t *ef = _zip_read_data(buffer, src, ef_len, 0, error);
  523|       |
  524|  9.06k|        if (ef == NULL) {
  ------------------
  |  Branch (524:13): [True: 0, False: 9.06k]
  ------------------
  525|      0|            if (!from_buffer) {
  ------------------
  |  Branch (525:17): [True: 0, False: 0]
  ------------------
  526|      0|                _zip_buffer_free(buffer);
  527|      0|            }
  528|      0|            return -1;
  529|      0|        }
  530|  9.06k|        if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, (local ? &zde->extra_fields.local : &zde->extra_fields.central), error)) {
  ------------------
  |  |  260|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
                      if (!_zip_ef_parse(ef, ef_len, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, (local ? &zde->extra_fields.local : &zde->extra_fields.central), error)) {
  ------------------
  |  |  261|  9.06k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  9.06k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (530:13): [True: 69, False: 8.99k]
  |  Branch (530:40): [True: 0, False: 9.06k]
  |  Branch (530:80): [True: 0, False: 9.06k]
  ------------------
  531|     69|            free(ef);
  532|     69|            if (!from_buffer) {
  ------------------
  |  Branch (532:17): [True: 0, False: 69]
  ------------------
  533|      0|                _zip_buffer_free(buffer);
  534|      0|            }
  535|     69|            return -1;
  536|     69|        }
  537|  8.99k|        free(ef);
  538|  8.99k|        if (local) {
  ------------------
  |  Branch (538:13): [True: 0, False: 8.99k]
  ------------------
  539|      0|            zde->local_extra_fields_read = 1;
  540|      0|        }
  541|  8.99k|    }
  542|       |
  543|  19.3k|    if (comment_len) {
  ------------------
  |  Branch (543:9): [True: 362, False: 18.9k]
  ------------------
  544|    362|        zde->comment = _zip_read_string(buffer, src, comment_len, 0, error);
  545|    362|        if (zde->comment == NULL) {
  ------------------
  |  Branch (545:13): [True: 0, False: 362]
  ------------------
  546|      0|            if (!from_buffer) {
  ------------------
  |  Branch (546:17): [True: 0, False: 0]
  ------------------
  547|      0|                _zip_buffer_free(buffer);
  548|      0|            }
  549|      0|            return -1;
  550|      0|        }
  551|    362|        if (zde->bitflags & ZIP_GPBF_ENCODING_UTF_8) {
  ------------------
  |  |  256|    362|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  |  Branch (551:13): [True: 46, False: 316]
  ------------------
  552|     46|            if (_zip_guess_encoding(zde->comment, ZIP_ENCODING_UTF8_KNOWN) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (552:17): [True: 1, False: 45]
  ------------------
  553|      1|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT);
  ------------------
  |  |  152|      1|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT);
  ------------------
  |  |  235|      1|#define ZIP_ER_DETAIL_INVALID_UTF8_IN_COMMENT 14          /* E invalid UTF-8 in comment */
  ------------------
  554|      1|                if (!from_buffer) {
  ------------------
  |  Branch (554:21): [True: 0, False: 1]
  ------------------
  555|      0|                    _zip_buffer_free(buffer);
  556|      0|                }
  557|      1|                return -1;
  558|      1|            }
  559|     46|        }
  560|    362|    }
  561|       |
  562|  19.3k|    if ((utf8_string = _zip_dirent_process_ef_utf_8(zde, ZIP_EF_UTF_8_NAME, zde->filename, check_consistency)) == NULL && zde->filename != NULL) {
  ------------------
  |  |   90|  19.3k|#define ZIP_EF_UTF_8_NAME 0x7075
  ------------------
  |  Branch (562:9): [True: 694, False: 18.6k]
  |  Branch (562:123): [True: 0, False: 694]
  ------------------
  563|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH);
  ------------------
  |  |  244|      0|#define ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH 23           /* E UTF-8 filename is ASCII and doesn't match filename */
  ------------------
  564|      0|        if (!from_buffer) {
  ------------------
  |  Branch (564:13): [True: 0, False: 0]
  ------------------
  565|      0|            _zip_buffer_free(buffer);
  566|      0|        }
  567|      0|        return -1;
  568|      0|    }
  569|  19.3k|    zde->filename = utf8_string;
  570|  19.3k|    if (!local) {
  ------------------
  |  Branch (570:9): [True: 19.3k, False: 0]
  ------------------
  571|  19.3k|        if ((utf8_string = _zip_dirent_process_ef_utf_8(zde, ZIP_EF_UTF_8_COMMENT, zde->comment, check_consistency)) == NULL && zde->comment != NULL) {
  ------------------
  |  |   89|  19.3k|#define ZIP_EF_UTF_8_COMMENT 0x6375
  ------------------
  |  Branch (571:13): [True: 18.9k, False: 361]
  |  Branch (571:129): [True: 0, False: 18.9k]
  ------------------
  572|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH);
  ------------------
  |  |  245|      0|#define ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH 24            /* E UTF-8 comment is ASCII and doesn't match comment */
  ------------------
  573|      0|            if (!from_buffer) {
  ------------------
  |  Branch (573:17): [True: 0, False: 0]
  ------------------
  574|      0|                _zip_buffer_free(buffer);
  575|      0|            }
  576|      0|            return -1;
  577|      0|        }
  578|  19.3k|        zde->comment = utf8_string;
  579|  19.3k|    }
  580|       |
  581|       |    /* Zip64 */
  582|       |
  583|  19.3k|    if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  38.7k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  38.5k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  19.1k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (583:9): [True: 186, False: 19.1k]
  |  Branch (583:47): [True: 32, False: 19.1k]
  |  Branch (583:83): [True: 313, False: 18.8k]
  ------------------
  584|    531|        zip_uint16_t got_len;
  585|    531|        const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
  ------------------
  |  |   92|    531|#define ZIP_EF_ZIP64 0x0001
  ------------------
                      const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
  ------------------
  |  |  260|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
                      const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
  ------------------
  |  |  261|    531|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|    531|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (585:108): [True: 0, False: 531]
  ------------------
  586|    531|        if (ef != NULL) {
  ------------------
  |  Branch (586:13): [True: 501, False: 30]
  ------------------
  587|    501|            if (!zip_dirent_process_ef_zip64(zde, ef, got_len, local, error)) {
  ------------------
  |  Branch (587:17): [True: 419, False: 82]
  ------------------
  588|    419|                if (!from_buffer) {
  ------------------
  |  Branch (588:21): [True: 0, False: 419]
  ------------------
  589|      0|                    _zip_buffer_free(buffer);
  590|      0|                }
  591|    419|                return -1;
  592|    419|            }
  593|    501|        }
  594|     30|        else if (is_zip64) {
  ------------------
  |  Branch (594:18): [True: 0, False: 30]
  ------------------
  595|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_MISSING_ZIP64_EF);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_MISSING_ZIP64_EF);
  ------------------
  |  |  248|      0|#define ZIP_ER_DETAIL_MISSING_ZIP64_EF 27                 /* E missing Zip64 extra field */
  ------------------
  596|      0|            if (!from_buffer) {
  ------------------
  |  Branch (596:17): [True: 0, False: 0]
  ------------------
  597|      0|                _zip_buffer_free(buffer);
  598|      0|            }
  599|      0|            return -1;
  600|      0|        }
  601|    531|    }
  602|       |
  603|       |
  604|  18.9k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (604:9): [True: 0, False: 18.9k]
  ------------------
  605|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  606|      0|        if (!from_buffer) {
  ------------------
  |  Branch (606:13): [True: 0, False: 0]
  ------------------
  607|      0|            _zip_buffer_free(buffer);
  608|      0|        }
  609|      0|        return -1;
  610|      0|    }
  611|       |
  612|  18.9k|    if (!from_buffer) {
  ------------------
  |  Branch (612:9): [True: 0, False: 18.9k]
  ------------------
  613|      0|        _zip_buffer_free(buffer);
  614|      0|    }
  615|       |
  616|  18.9k|    if (local && zde->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
  ------------------
  |  |  254|      0|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  |  Branch (616:9): [True: 0, False: 18.9k]
  |  Branch (616:18): [True: 0, False: 0]
  ------------------
  617|      0|        zip_uint32_t df_crc;
  618|      0|        zip_uint64_t df_comp_size, df_uncomp_size;
  619|       |
  620|      0|        if (zip_source_seek(src, central_compressed_size, SEEK_CUR) != 0 || (buffer = _zip_buffer_new_from_source(src, MAX_DATA_DESCRIPTOR_LENGTH, buf, error)) == NULL) {
  ------------------
  |  |   69|      0|#define MAX_DATA_DESCRIPTOR_LENGTH 24
  ------------------
  |  Branch (620:13): [True: 0, False: 0]
  |  Branch (620:77): [True: 0, False: 0]
  ------------------
  621|      0|            return -1;
  622|      0|        }
  623|      0|        if (memcmp(_zip_buffer_peek(buffer, MAGIC_LEN), DATADES_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   57|      0|#define MAGIC_LEN 4
  ------------------
                      if (memcmp(_zip_buffer_peek(buffer, MAGIC_LEN), DATADES_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   54|      0|#define DATADES_MAGIC "PK\7\10"
  ------------------
                      if (memcmp(_zip_buffer_peek(buffer, MAGIC_LEN), DATADES_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   57|      0|#define MAGIC_LEN 4
  ------------------
  |  Branch (623:13): [True: 0, False: 0]
  ------------------
  624|      0|            _zip_buffer_skip(buffer, MAGIC_LEN);
  ------------------
  |  |   57|      0|#define MAGIC_LEN 4
  ------------------
  625|      0|        }
  626|      0|        df_crc = _zip_buffer_get_32(buffer);
  627|      0|        df_comp_size = is_zip64 ? _zip_buffer_get_64(buffer) : _zip_buffer_get_32(buffer);
  ------------------
  |  Branch (627:24): [True: 0, False: 0]
  ------------------
  628|      0|        df_uncomp_size = is_zip64 ? _zip_buffer_get_64(buffer) : _zip_buffer_get_32(buffer);
  ------------------
  |  Branch (628:26): [True: 0, False: 0]
  ------------------
  629|       |
  630|      0|        if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (630:13): [True: 0, False: 0]
  ------------------
  631|      0|            zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  632|      0|            _zip_buffer_free(buffer);
  633|      0|            return -1;
  634|      0|        }
  635|      0|        _zip_buffer_free(buffer);
  636|       |
  637|       |        /* According to the appnote, it should be 0, but some implementations write the actual value. */
  638|      0|        if ((zde->crc != 0 && zde->crc != df_crc) || (zde->comp_size != 0 && zde->comp_size != df_comp_size) || (zde->uncomp_size != 0 && zde->uncomp_size != df_uncomp_size)) {
  ------------------
  |  Branch (638:14): [True: 0, False: 0]
  |  Branch (638:31): [True: 0, False: 0]
  |  Branch (638:55): [True: 0, False: 0]
  |  Branch (638:78): [True: 0, False: 0]
  |  Branch (638:114): [True: 0, False: 0]
  |  Branch (638:139): [True: 0, False: 0]
  ------------------
  639|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_DATA_DESCRIPTOR_MISMATCH);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_DATA_DESCRIPTOR_MISMATCH);
  ------------------
  |  |  242|      0|#define ZIP_ER_DETAIL_DATA_DESCRIPTOR_MISMATCH 21         /* E local header and data descriptor do not match */
  ------------------
  640|      0|            return -1;
  641|      0|        }
  642|      0|        zde->crc = df_crc;
  643|      0|        zde->comp_size = df_comp_size;
  644|      0|        zde->uncomp_size = df_uncomp_size;
  645|      0|    }
  646|       |
  647|       |    /* zip_source_seek / zip_source_tell don't support values > ZIP_INT64_MAX */
  648|  18.9k|    if (zde->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  18.9k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (648:9): [True: 74, False: 18.8k]
  ------------------
  649|     74|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|     74|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  650|     74|        return -1;
  651|     74|    }
  652|       |
  653|  18.8k|    if (!_zip_dirent_process_winzip_aes(zde, error)) {
  ------------------
  |  Branch (653:9): [True: 1, False: 18.8k]
  ------------------
  654|      1|        return -1;
  655|      1|    }
  656|       |
  657|  18.8k|    efp = local ? &zde->extra_fields.local : &zde->extra_fields.central;
  ------------------
  |  Branch (657:11): [True: 0, False: 18.8k]
  ------------------
  658|  18.8k|    *efp = _zip_ef_remove_internal(*efp);
  659|       |
  660|  18.8k|    return (zip_int64_t)size + (zip_int64_t)variable_size;
  661|  18.8k|}
zip_dirent_process_ef_zip64:
  663|    501|bool zip_dirent_process_ef_zip64(zip_dirent_t *zde, const zip_uint8_t *ef, zip_uint64_t got_len, bool local, zip_error_t *error) {
  664|    501|    zip_buffer_t *ef_buffer;
  665|       |
  666|    501|    if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
  ------------------
  |  Branch (666:9): [True: 0, False: 501]
  ------------------
  667|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  668|      0|        return false;
  669|      0|    }
  670|       |
  671|    501|    if (zde->uncomp_size == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    501|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (671:9): [True: 183, False: 318]
  ------------------
  672|    183|        zde->uncomp_size = _zip_buffer_get_64(ef_buffer);
  673|    183|    }
  674|    318|    else if (local) {
  ------------------
  |  Branch (674:14): [True: 0, False: 318]
  ------------------
  675|       |        /* From appnote.txt: This entry in the Local header MUST
  676|       |           include BOTH original and compressed file size fields. */
  677|      0|        (void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
  678|      0|    }
  679|    501|    if (zde->comp_size == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    501|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (679:9): [True: 157, False: 344]
  ------------------
  680|    157|        zde->comp_size = _zip_buffer_get_64(ef_buffer);
  681|    157|    }
  682|    501|    if (!local) {
  ------------------
  |  Branch (682:9): [True: 501, False: 0]
  ------------------
  683|    501|        if (zde->offset == ZIP_UINT32_MAX) {
  ------------------
  |  |   42|    501|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (683:13): [True: 343, False: 158]
  ------------------
  684|    343|            zde->offset = _zip_buffer_get_64(ef_buffer);
  685|    343|        }
  686|    501|        if (zde->disk_number == ZIP_UINT16_MAX) {
  ------------------
  |  |   38|    501|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (686:13): [True: 9, False: 492]
  ------------------
  687|      9|            zde->disk_number = _zip_buffer_get_32(ef_buffer);
  688|      9|        }
  689|    501|    }
  690|       |
  691|    501|    if (!_zip_buffer_eof(ef_buffer)) {
  ------------------
  |  Branch (691:9): [True: 458, False: 43]
  ------------------
  692|       |        /* accept additional fields if values match */
  693|    458|        bool ok = true;
  694|    458|        switch (got_len) {
  695|    426|        case 28:
  ------------------
  |  Branch (695:9): [True: 426, False: 32]
  ------------------
  696|    426|            _zip_buffer_set_offset(ef_buffer, 24);
  697|    426|            if (zde->disk_number != _zip_buffer_get_32(ef_buffer)) {
  ------------------
  |  Branch (697:17): [True: 352, False: 74]
  ------------------
  698|    352|                ok = false;
  699|    352|            }
  700|       |            /* fallthrough */
  701|    432|        case 24:
  ------------------
  |  Branch (701:9): [True: 6, False: 452]
  ------------------
  702|    432|            _zip_buffer_set_offset(ef_buffer, 0);
  703|    432|            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))) {
  ------------------
  |  Branch (703:17): [True: 179, False: 253]
  |  Branch (703:72): [True: 111, False: 142]
  |  Branch (703:125): [True: 103, False: 39]
  ------------------
  704|    393|                ok = false;
  705|    393|            }
  706|    432|            break;
  707|       |
  708|     26|        default:
  ------------------
  |  Branch (708:9): [True: 26, False: 432]
  ------------------
  709|     26|            ok = false;
  710|    458|        }
  711|    458|        if (!ok) {
  ------------------
  |  Branch (711:13): [True: 419, False: 39]
  ------------------
  712|    419|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_ZIP64_EF);
  ------------------
  |  |  152|    419|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_ZIP64_EF);
  ------------------
  |  |  236|    419|#define ZIP_ER_DETAIL_INVALID_ZIP64_EF 15                 /* E invalid Zip64 extra field */
  ------------------
  713|    419|            _zip_buffer_free(ef_buffer);
  714|    419|            return false;
  715|    419|        }
  716|    458|    }
  717|     82|    _zip_buffer_free(ef_buffer);
  718|       |
  719|       |    return true;
  720|    501|}
_zip_dirent_size:
  846|  11.3k|zip_int32_t _zip_dirent_size(zip_source_t *src, zip_uint16_t flags, zip_error_t *error) {
  847|  11.3k|    zip_int32_t size;
  848|  11.3k|    bool local = (flags & ZIP_EF_LOCAL) != 0;
  ------------------
  |  |  260|  11.3k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  11.3k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  849|  11.3k|    int i;
  850|  11.3k|    zip_uint8_t b[CDENTRYSIZE];
  851|  11.3k|    zip_buffer_t *buffer;
  852|       |
  853|  11.3k|    size = local ? LENTRYSIZE : CDENTRYSIZE;
  ------------------
  |  |   59|  11.3k|#define LENTRYSIZE 30
  ------------------
                  size = local ? LENTRYSIZE : CDENTRYSIZE;
  ------------------
  |  |   58|  11.3k|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (853:12): [True: 11.3k, False: 0]
  ------------------
  854|       |
  855|       |    /* Central header has fixed fields after size pointers. */
  856|  11.3k|    if ((buffer = _zip_buffer_new_from_source(src, local ? LENTRYSIZE : 34, b, error)) == NULL) {
  ------------------
  |  |   59|  11.3k|#define LENTRYSIZE 30
  ------------------
  |  Branch (856:9): [True: 0, False: 11.3k]
  |  Branch (856:52): [True: 11.3k, False: 0]
  ------------------
  857|      0|        return -1;
  858|      0|    }
  859|  11.3k|    if (_zip_buffer_left(buffer) != (local ? LENTRYSIZE : 34)) {
  ------------------
  |  |   59|  11.3k|#define LENTRYSIZE 30
  ------------------
  |  Branch (859:9): [True: 0, False: 11.3k]
  |  Branch (859:38): [True: 11.3k, False: 0]
  ------------------
  860|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_ENTRY_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_ENTRY_INVALID);
  ------------------
  |  |  225|      0|#define ZIP_ER_DETAIL_CDIR_ENTRY_INVALID 4                /* E central header invalid */
  ------------------
  861|      0|        _zip_buffer_free(buffer);
  862|      0|        return -1;
  863|      0|    }
  864|       |
  865|  11.3k|    if (memcmp(_zip_buffer_peek(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
  ------------------
  |  |   52|  11.3k|#define LOCAL_MAGIC "PK\3\4"
  ------------------
                  if (memcmp(_zip_buffer_peek(buffer, 4), (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
  ------------------
  |  |   51|      0|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (865:9): [True: 0, False: 11.3k]
  |  Branch (865:46): [True: 11.3k, False: 0]
  ------------------
  866|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_ENTRY_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_ENTRY_INVALID);
  ------------------
  |  |  225|      0|#define ZIP_ER_DETAIL_CDIR_ENTRY_INVALID 4                /* E central header invalid */
  ------------------
  867|      0|        _zip_buffer_free(buffer);
  868|      0|        return -1;
  869|      0|    }
  870|       |
  871|       |    /* Skip to size pointers. */
  872|  11.3k|    _zip_buffer_skip(buffer, local ? 26 : 28);
  ------------------
  |  Branch (872:30): [True: 11.3k, False: 0]
  ------------------
  873|       |
  874|  34.1k|    for (i = 0; i < (local ? 2 : 3); i++) {
  ------------------
  |  Branch (874:17): [True: 22.7k, False: 11.3k]
  |  Branch (874:22): [True: 34.1k, False: 0]
  ------------------
  875|  22.7k|        size += _zip_buffer_get_16(buffer);
  876|  22.7k|    }
  877|       |
  878|  11.3k|    _zip_buffer_free(buffer);
  879|  11.3k|    return size;
  880|  11.3k|}
_zip_dirent_write:
  893|  62.7k|int _zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) {
  894|  62.7k|    zip_dostime_t dostime;
  895|  62.7k|    zip_encoding_type_t com_enc, name_enc;
  896|  62.7k|    zip_extra_field_t *ef;
  897|  62.7k|    zip_extra_field_t *ef64;
  898|  62.7k|    zip_int32_t ef_size, de_ef_size;
  899|  62.7k|    bool is_zip64;
  900|  62.7k|    bool is_really_zip64;
  901|  62.7k|    bool is_winzip_aes;
  902|  62.7k|    zip_uint8_t buf[CDENTRYSIZE];
  903|  62.7k|    zip_buffer_t *buffer;
  904|       |
  905|  62.7k|    ef = NULL;
  906|       |
  907|  62.7k|    name_enc = _zip_guess_encoding(de->filename, ZIP_ENCODING_UNKNOWN);
  908|  62.7k|    com_enc = _zip_guess_encoding(de->comment, ZIP_ENCODING_UNKNOWN);
  909|       |
  910|  62.7k|    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)) {
  ------------------
  |  Branch (910:10): [True: 710, False: 62.0k]
  |  Branch (910:49): [True: 541, False: 169]
  |  Branch (910:84): [True: 16.5k, False: 45.6k]
  |  Branch (910:118): [True: 113, False: 16.4k]
  |  Branch (910:158): [True: 169, False: 61.9k]
  |  Branch (910:197): [True: 33, False: 136]
  ------------------
  911|    687|        de->bitflags |= ZIP_GPBF_ENCODING_UTF_8;
  ------------------
  |  |  256|    687|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  912|    687|    }
  913|  62.0k|    else {
  914|  62.0k|        de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCODING_UTF_8;
  ------------------
  |  |  256|  62.0k|#define ZIP_GPBF_ENCODING_UTF_8 0x0800u    /* file name encoding is UTF-8 */
  ------------------
  915|  62.0k|        if (name_enc == ZIP_ENCODING_UTF8_KNOWN) {
  ------------------
  |  Branch (915:13): [True: 136, False: 61.9k]
  ------------------
  916|    136|            ef = _zip_ef_utf8(ZIP_EF_UTF_8_NAME, de->filename, &za->error);
  ------------------
  |  |   90|    136|#define ZIP_EF_UTF_8_NAME 0x7075
  ------------------
  917|    136|            if (ef == NULL) {
  ------------------
  |  Branch (917:17): [True: 0, False: 136]
  ------------------
  918|      0|                return -1;
  919|      0|            }
  920|    136|        }
  921|  62.0k|        if ((flags & ZIP_FL_LOCAL) == 0 && com_enc == ZIP_ENCODING_UTF8_KNOWN) {
  ------------------
  |  |  104|  62.0k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (921:13): [True: 20.9k, False: 41.1k]
  |  Branch (921:44): [True: 68, False: 20.9k]
  ------------------
  922|     68|            zip_extra_field_t *ef2 = _zip_ef_utf8(ZIP_EF_UTF_8_COMMENT, de->comment, &za->error);
  ------------------
  |  |   89|     68|#define ZIP_EF_UTF_8_COMMENT 0x6375
  ------------------
  923|     68|            if (ef2 == NULL) {
  ------------------
  |  Branch (923:17): [True: 0, False: 68]
  ------------------
  924|      0|                _zip_ef_free(ef);
  925|      0|                return -1;
  926|      0|            }
  927|     68|            ef2->next = ef;
  928|     68|            ef = ef2;
  929|     68|        }
  930|  62.0k|    }
  931|       |
  932|  62.7k|    if (de->encryption_method == ZIP_EM_NONE) {
  ------------------
  |  |  207|  62.7k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (932:9): [True: 33.0k, False: 29.7k]
  ------------------
  933|  33.0k|        de->bitflags &= (zip_uint16_t)~ZIP_GPBF_ENCRYPTED;
  ------------------
  |  |  253|  33.0k|#define ZIP_GPBF_ENCRYPTED 0x0001u         /* is encrypted */
  ------------------
  934|  33.0k|    }
  935|  29.7k|    else {
  936|  29.7k|        de->bitflags |= (zip_uint16_t)ZIP_GPBF_ENCRYPTED;
  ------------------
  |  |  253|  29.7k|#define ZIP_GPBF_ENCRYPTED 0x0001u         /* is encrypted */
  ------------------
  937|  29.7k|    }
  938|       |
  939|  62.7k|    is_really_zip64 = _zip_dirent_needs_zip64(de, flags);
  940|  62.7k|    is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  264|  62.7k|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
                  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  is_zip64 = (flags & (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64)) == (ZIP_FL_LOCAL | ZIP_FL_FORCE_ZIP64) || is_really_zip64;
  ------------------
  |  |  264|  62.7k|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
  |  Branch (940:16): [True: 0, False: 62.7k]
  |  Branch (940:104): [True: 0, False: 62.7k]
  ------------------
  941|  62.7k|    is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
  ------------------
  |  |  220|   125k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
                  is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
  ------------------
  |  |  221|   119k|#define ZIP_EM_AES_192 0x0102
  ------------------
                  is_winzip_aes = de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256;
  ------------------
  |  |  222|   119k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (941:21): [True: 5.96k, False: 56.8k]
  |  Branch (941:64): [True: 0, False: 56.8k]
  |  Branch (941:107): [True: 19.7k, False: 37.0k]
  ------------------
  942|       |
  943|  62.7k|    if (is_zip64) {
  ------------------
  |  Branch (943:9): [True: 0, False: 62.7k]
  ------------------
  944|      0|        zip_uint8_t ef_zip64[EFZIP64SIZE];
  945|      0|        zip_buffer_t *ef_buffer = _zip_buffer_new(ef_zip64, sizeof(ef_zip64));
  946|      0|        if (ef_buffer == NULL) {
  ------------------
  |  Branch (946:13): [True: 0, False: 0]
  ------------------
  947|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  948|      0|            _zip_ef_free(ef);
  949|      0|            return -1;
  950|      0|        }
  951|       |
  952|      0|        if (flags & ZIP_FL_LOCAL) {
  ------------------
  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (952:13): [True: 0, False: 0]
  ------------------
  953|      0|            if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
  ------------------
  |  |  264|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (953:17): [True: 0, False: 0]
  |  Branch (953:49): [True: 0, False: 0]
  |  Branch (953:83): [True: 0, False: 0]
  ------------------
  954|      0|                _zip_buffer_put_64(ef_buffer, de->uncomp_size);
  955|      0|                _zip_buffer_put_64(ef_buffer, de->comp_size);
  956|      0|            }
  957|      0|        }
  958|      0|        else {
  959|      0|            if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |  264|      0|#define ZIP_FL_FORCE_ZIP64 1024 /* force zip64 extra field (_zip_dirent_write) */
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                          if ((flags & ZIP_FL_FORCE_ZIP64) || de->comp_size > ZIP_UINT32_MAX || de->uncomp_size > ZIP_UINT32_MAX || de->offset > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (959:17): [True: 0, False: 0]
  |  Branch (959:49): [True: 0, False: 0]
  |  Branch (959:83): [True: 0, False: 0]
  |  Branch (959:119): [True: 0, False: 0]
  ------------------
  960|      0|                if (de->uncomp_size >= ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (960:21): [True: 0, False: 0]
  ------------------
  961|      0|                    _zip_buffer_put_64(ef_buffer, de->uncomp_size);
  962|      0|                }
  963|      0|                if (de->comp_size >= ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (963:21): [True: 0, False: 0]
  ------------------
  964|      0|                    _zip_buffer_put_64(ef_buffer, de->comp_size);
  965|      0|                }
  966|      0|                if (de->offset >= ZIP_UINT32_MAX) {
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (966:21): [True: 0, False: 0]
  ------------------
  967|      0|                    _zip_buffer_put_64(ef_buffer, de->offset);
  968|      0|                }
  969|      0|            }
  970|      0|        }
  971|       |
  972|      0|        if (!_zip_buffer_ok(ef_buffer)) {
  ------------------
  |  Branch (972:13): [True: 0, False: 0]
  ------------------
  973|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  974|      0|            _zip_buffer_free(ef_buffer);
  975|      0|            _zip_ef_free(ef);
  976|      0|            return -1;
  977|      0|        }
  978|       |
  979|      0|        ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64);
  ------------------
  |  |   92|      0|#define ZIP_EF_ZIP64 0x0001
  ------------------
  980|      0|        _zip_buffer_free(ef_buffer);
  981|      0|        if (ef64 == NULL) {
  ------------------
  |  Branch (981:13): [True: 0, False: 0]
  ------------------
  982|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  983|      0|            _zip_ef_free(ef);
  984|      0|            return -1;
  985|      0|        }
  986|      0|        ef64->next = ef;
  987|      0|        ef = ef64;
  988|      0|    }
  989|       |
  990|  62.7k|    if (is_winzip_aes) {
  ------------------
  |  Branch (990:9): [True: 25.6k, False: 37.0k]
  ------------------
  991|  25.6k|        zip_uint8_t data[EF_WINZIP_AES_SIZE];
  992|  25.6k|        zip_buffer_t *ef_buffer = _zip_buffer_new(data, sizeof(data));
  993|  25.6k|        zip_extra_field_t *ef_winzip;
  994|       |
  995|  25.6k|        if (ef_buffer == NULL) {
  ------------------
  |  Branch (995:13): [True: 0, False: 25.6k]
  ------------------
  996|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  997|      0|            _zip_ef_free(ef);
  998|      0|            return -1;
  999|      0|        }
 1000|       |
 1001|  25.6k|        _zip_buffer_put_16(ef_buffer, 2);
 1002|  25.6k|        _zip_buffer_put(ef_buffer, "AE", 2);
 1003|  25.6k|        _zip_buffer_put_8(ef_buffer, (zip_uint8_t)(de->encryption_method & 0xff));
 1004|  25.6k|        _zip_buffer_put_16(ef_buffer, (zip_uint16_t)de->comp_method);
 1005|       |
 1006|  25.6k|        if (!_zip_buffer_ok(ef_buffer)) {
  ------------------
  |  Branch (1006:13): [True: 0, False: 25.6k]
  ------------------
 1007|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
 1008|      0|            _zip_buffer_free(ef_buffer);
 1009|      0|            _zip_ef_free(ef);
 1010|      0|            return -1;
 1011|      0|        }
 1012|       |
 1013|  25.6k|        ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data);
  ------------------
  |  |   91|  25.6k|#define ZIP_EF_WINZIP_AES 0x9901
  ------------------
                      ef_winzip = _zip_ef_new(ZIP_EF_WINZIP_AES, EF_WINZIP_AES_SIZE, data);
  ------------------
  |  |   68|  25.6k|#define EF_WINZIP_AES_SIZE 7
  ------------------
 1014|  25.6k|        _zip_buffer_free(ef_buffer);
 1015|  25.6k|        if (ef_winzip == NULL) {
  ------------------
  |  Branch (1015:13): [True: 0, False: 25.6k]
  ------------------
 1016|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
 1017|      0|            _zip_ef_free(ef);
 1018|      0|            return -1;
 1019|      0|        }
 1020|  25.6k|        ef_winzip->next = ef;
 1021|  25.6k|        ef = ef_winzip;
 1022|  25.6k|    }
 1023|       |
 1024|  62.7k|    if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
  ------------------
  |  Branch (1024:9): [True: 0, False: 62.7k]
  ------------------
 1025|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
 1026|      0|        _zip_ef_free(ef);
 1027|      0|        return -1;
 1028|      0|    }
 1029|       |
 1030|  62.7k|    _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
  ------------------
  |  |   52|  41.5k|#define LOCAL_MAGIC "PK\3\4"
  ------------------
                  _zip_buffer_put(buffer, (flags & ZIP_FL_LOCAL) ? LOCAL_MAGIC : CENTRAL_MAGIC, 4);
  ------------------
  |  |   51|  83.9k|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (1030:29): [True: 41.5k, False: 21.2k]
  ------------------
 1031|       |
 1032|  62.7k|    if ((flags & ZIP_FL_LOCAL) == 0) {
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (1032:9): [True: 21.2k, False: 41.5k]
  ------------------
 1033|  21.2k|        _zip_buffer_put_16(buffer, de->version_madeby);
 1034|  21.2k|    }
 1035|  62.7k|    _zip_buffer_put_16(buffer, ZIP_MAX(is_really_zip64 ? 45 : 0, de->version_needed));
  ------------------
  |  |  514|   125k|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (514:24): [True: 0, False: 62.7k]
  |  |  |  Branch (514:25): [True: 0, False: 62.7k]
  |  |  |  Branch (514:37): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1036|  62.7k|    _zip_buffer_put_16(buffer, de->bitflags);
 1037|  62.7k|    if (is_winzip_aes) {
  ------------------
  |  Branch (1037:9): [True: 25.6k, False: 37.0k]
  ------------------
 1038|  25.6k|        _zip_buffer_put_16(buffer, ZIP_CM_WINZIP_AES);
  ------------------
  |  |   79|  25.6k|#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
  ------------------
 1039|  25.6k|    }
 1040|  37.0k|    else {
 1041|  37.0k|        _zip_buffer_put_16(buffer, (zip_uint16_t)ZIP_CM_ACTUAL(de->comp_method));
  ------------------
  |  |   87|  37.0k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  37.0k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|  7.05k|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 7.05k, False: 30.0k]
  |  |  ------------------
  ------------------
 1042|  37.0k|    }
 1043|       |
 1044|  62.7k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  62.7k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  62.7k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 62.7k]
  |  |  ------------------
  ------------------
 1045|      0|        dostime.time = 0xbc00;
 1046|      0|        dostime.date = 0x2198;
 1047|      0|    }
 1048|  62.7k|    else {
 1049|  62.7k|        dostime = de->last_mod;
 1050|  62.7k|    }
 1051|  62.7k|    _zip_buffer_put_16(buffer, dostime.time);
 1052|  62.7k|    _zip_buffer_put_16(buffer, dostime.date);
 1053|       |
 1054|  62.7k|    if (is_winzip_aes && de->uncomp_size < 20) {
  ------------------
  |  Branch (1054:9): [True: 25.6k, False: 37.0k]
  |  Branch (1054:26): [True: 6.80k, False: 18.8k]
  ------------------
 1055|  6.80k|        _zip_buffer_put_32(buffer, 0);
 1056|  6.80k|    }
 1057|  55.9k|    else {
 1058|  55.9k|        _zip_buffer_put_32(buffer, de->crc);
 1059|  55.9k|    }
 1060|       |
 1061|  62.7k|    if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |   42|  41.5k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
                  if (((flags & ZIP_FL_LOCAL) == ZIP_FL_LOCAL) && ((de->comp_size >= ZIP_UINT32_MAX) || (de->uncomp_size >= ZIP_UINT32_MAX))) {
  ------------------
  |  |   42|  41.5k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1061:9): [True: 41.5k, False: 21.2k]
  |  Branch (1061:54): [True: 0, False: 41.5k]
  |  Branch (1061:91): [True: 0, False: 41.5k]
  ------------------
 1062|       |        /* In local headers, if a ZIP64 EF is written, it MUST contain
 1063|       |         * both compressed and uncompressed sizes (even if one of the
 1064|       |         * two is smaller than 0xFFFFFFFF); on the other hand, those
 1065|       |         * may only appear when the corresponding standard entry is
 1066|       |         * 0xFFFFFFFF.  (appnote.txt 4.5.3) */
 1067|      0|        _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1068|      0|        _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1069|      0|    }
 1070|  62.7k|    else {
 1071|  62.7k|        if (de->comp_size < ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  62.7k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1071:13): [True: 62.7k, False: 0]
  ------------------
 1072|  62.7k|            _zip_buffer_put_32(buffer, (zip_uint32_t)de->comp_size);
 1073|  62.7k|        }
 1074|      0|        else {
 1075|      0|            _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1076|      0|        }
 1077|  62.7k|        if (de->uncomp_size < ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  62.7k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1077:13): [True: 62.7k, False: 0]
  ------------------
 1078|  62.7k|            _zip_buffer_put_32(buffer, (zip_uint32_t)de->uncomp_size);
 1079|  62.7k|        }
 1080|      0|        else {
 1081|      0|            _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1082|      0|        }
 1083|  62.7k|    }
 1084|       |
 1085|  62.7k|    _zip_buffer_put_16(buffer, _zip_string_length(de->filename));
 1086|       |
 1087|  62.7k|    ef_size = _zip_ef_size(ef);
 1088|  62.7k|    if (!ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  62.7k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  62.7k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (1088:9): [True: 62.7k, False: 0]
  ------------------
 1089|  62.7k|        de_ef_size = _zip_ef_size((flags & ZIP_FL_LOCAL) ? de->extra_fields.local : de->extra_fields.central);
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (1089:35): [True: 41.5k, False: 21.2k]
  ------------------
 1090|  62.7k|    }
 1091|      0|    else {
 1092|      0|        de_ef_size = 0;
 1093|      0|    }
 1094|  62.7k|    if (ef_size < 0 || de_ef_size < 0 || ef_size + de_ef_size > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  62.7k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (1094:9): [True: 0, False: 62.7k]
  |  Branch (1094:24): [True: 0, False: 62.7k]
  |  Branch (1094:42): [True: 0, False: 62.7k]
  ------------------
 1095|      0|        zip_error_set(&za->error, ZIP_ER_EF_TOO_LARGE, 0);
  ------------------
  |  |  167|      0|#define ZIP_ER_EF_TOO_LARGE 36    /* N Extra fields too large */
  ------------------
 1096|      0|        _zip_buffer_free(buffer);
 1097|      0|        _zip_ef_free(ef);
 1098|      0|        return -1;
 1099|      0|    }
 1100|  62.7k|    _zip_buffer_put_16(buffer, (zip_uint16_t)(ef_size + de_ef_size));
 1101|       |
 1102|  62.7k|    if ((flags & ZIP_FL_LOCAL) == 0) {
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (1102:9): [True: 21.2k, False: 41.5k]
  ------------------
 1103|  21.2k|        _zip_buffer_put_16(buffer, ZIP_WANT_TORRENTZIP(za) ? 0 : _zip_string_length(de->comment));
  ------------------
  |  |  523|  21.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 21.2k]
  |  |  ------------------
  ------------------
 1104|  21.2k|        _zip_buffer_put_16(buffer, (zip_uint16_t)de->disk_number);
 1105|  21.2k|        _zip_buffer_put_16(buffer, de->int_attrib);
 1106|  21.2k|        _zip_buffer_put_32(buffer, de->ext_attrib);
 1107|  21.2k|        if (de->offset < ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  21.2k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (1107:13): [True: 21.2k, False: 0]
  ------------------
 1108|  21.2k|            _zip_buffer_put_32(buffer, (zip_uint32_t)de->offset);
 1109|  21.2k|        }
 1110|      0|        else {
 1111|      0|            _zip_buffer_put_32(buffer, ZIP_UINT32_MAX);
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
 1112|      0|        }
 1113|  21.2k|    }
 1114|       |
 1115|  62.7k|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (1115:9): [True: 0, False: 62.7k]
  ------------------
 1116|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
 1117|      0|        _zip_buffer_free(buffer);
 1118|      0|        _zip_ef_free(ef);
 1119|      0|        return -1;
 1120|      0|    }
 1121|       |
 1122|  62.7k|    if (_zip_write(za, buf, _zip_buffer_offset(buffer)) < 0) {
  ------------------
  |  Branch (1122:9): [True: 0, False: 62.7k]
  ------------------
 1123|      0|        _zip_buffer_free(buffer);
 1124|      0|        _zip_ef_free(ef);
 1125|      0|        return -1;
 1126|      0|    }
 1127|       |
 1128|  62.7k|    _zip_buffer_free(buffer);
 1129|       |
 1130|  62.7k|    if (de->filename) {
  ------------------
  |  Branch (1130:9): [True: 62.7k, False: 0]
  ------------------
 1131|  62.7k|        if (_zip_string_write(za, de->filename) < 0) {
  ------------------
  |  Branch (1131:13): [True: 0, False: 62.7k]
  ------------------
 1132|      0|            _zip_ef_free(ef);
 1133|      0|            return -1;
 1134|      0|        }
 1135|  62.7k|    }
 1136|       |
 1137|  62.7k|    if (ef) {
  ------------------
  |  Branch (1137:9): [True: 25.8k, False: 36.9k]
  ------------------
 1138|  25.8k|        if (_zip_ef_write(za, ef) < 0) {
  ------------------
  |  Branch (1138:13): [True: 0, False: 25.8k]
  ------------------
 1139|      0|            _zip_ef_free(ef);
 1140|      0|            return -1;
 1141|      0|        }
 1142|  25.8k|    }
 1143|  62.7k|    _zip_ef_free(ef);
 1144|  62.7k|    ef = (flags & ZIP_FL_LOCAL) ? de->extra_fields.local : de->extra_fields.central;
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (1144:10): [True: 41.5k, False: 21.2k]
  ------------------
 1145|  62.7k|    if (ef && !ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  1.08k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  1.08k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (1145:9): [True: 1.08k, False: 61.6k]
  |  Branch (1145:15): [True: 1.08k, False: 0]
  ------------------
 1146|  1.08k|        if (_zip_ef_write(za, ef) < 0) {
  ------------------
  |  Branch (1146:13): [True: 0, False: 1.08k]
  ------------------
 1147|      0|            return -1;
 1148|      0|        }
 1149|  1.08k|    }
 1150|       |
 1151|  62.7k|    if ((flags & ZIP_FL_LOCAL) == 0 && !ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  104|  62.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
                  if ((flags & ZIP_FL_LOCAL) == 0 && !ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  21.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  21.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  ------------------
  |  Branch (1151:9): [True: 21.2k, False: 41.5k]
  |  Branch (1151:40): [True: 21.2k, False: 0]
  ------------------
 1152|  21.2k|        if (de->comment) {
  ------------------
  |  Branch (1152:13): [True: 2.39k, False: 18.8k]
  ------------------
 1153|  2.39k|            if (_zip_string_write(za, de->comment) < 0) {
  ------------------
  |  Branch (1153:17): [True: 0, False: 2.39k]
  ------------------
 1154|      0|                return -1;
 1155|      0|            }
 1156|  2.39k|        }
 1157|  21.2k|    }
 1158|       |
 1159|       |
 1160|  62.7k|    return is_zip64;
 1161|  62.7k|}
_zip_d2u_time:
 1164|  18.6k|time_t _zip_d2u_time(const zip_dostime_t *dtime) {
 1165|  18.6k|    struct tm tm;
 1166|       |
 1167|  18.6k|    memset(&tm, 0, sizeof(tm));
 1168|       |
 1169|       |    /* let mktime decide if DST is in effect */
 1170|  18.6k|    tm.tm_isdst = -1;
 1171|       |
 1172|  18.6k|    tm.tm_year = ((dtime->date >> 9) & 127) + 1980 - 1900;
 1173|  18.6k|    tm.tm_mon = ((dtime->date >> 5) & 15) - 1;
 1174|  18.6k|    tm.tm_mday = dtime->date & 31;
 1175|       |
 1176|  18.6k|    tm.tm_hour = (dtime->time >> 11) & 31;
 1177|  18.6k|    tm.tm_min = (dtime->time >> 5) & 63;
 1178|  18.6k|    tm.tm_sec = (dtime->time << 1) & 62;
 1179|       |
 1180|  18.6k|    return mktime(&tm);
 1181|  18.6k|}
_zip_get_dirent:
 1222|   115k|zip_dirent_t *_zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
 1223|   115k|    if (error == NULL) {
  ------------------
  |  Branch (1223:9): [True: 55.4k, False: 60.0k]
  ------------------
 1224|  55.4k|        error = &za->error;
 1225|  55.4k|    }
 1226|       |
 1227|   115k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (1227:9): [True: 0, False: 115k]
  ------------------
 1228|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1229|      0|        return NULL;
 1230|      0|    }
 1231|       |
 1232|   115k|    if ((flags & ZIP_FL_UNCHANGED) || za->entry[idx].changes == NULL) {
  ------------------
  |  |   98|   115k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (1232:9): [True: 37.2k, False: 78.2k]
  |  Branch (1232:39): [True: 19.0k, False: 59.1k]
  ------------------
 1233|  56.3k|        if (za->entry[idx].orig == NULL) {
  ------------------
  |  Branch (1233:13): [True: 457, False: 55.8k]
  ------------------
 1234|    457|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|    457|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1235|    457|            return NULL;
 1236|    457|        }
 1237|  55.8k|        if (za->entry[idx].deleted && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (1237:13): [True: 0, False: 55.8k]
  |  Branch (1237:39): [True: 0, False: 0]
  ------------------
 1238|      0|            zip_error_set(error, ZIP_ER_DELETED, 0);
  ------------------
  |  |  154|      0|#define ZIP_ER_DELETED 23         /* N Entry has been deleted */
  ------------------
 1239|      0|            return NULL;
 1240|      0|        }
 1241|  55.8k|        return za->entry[idx].orig;
 1242|  55.8k|    }
 1243|  59.1k|    else {
 1244|  59.1k|        return za->entry[idx].changes;
 1245|  59.1k|    }
 1246|   115k|}
_zip_u2d_time:
 1249|  22.5k|int _zip_u2d_time(time_t intime, zip_dostime_t *dtime, zip_error_t *ze) {
 1250|  22.5k|    struct tm *tpm;
 1251|  22.5k|    struct tm tm;
 1252|  22.5k|    tpm = zip_localtime(&intime, &tm);
  ------------------
  |  |  195|  22.5k|#define zip_localtime localtime_r
  ------------------
 1253|  22.5k|    if (tpm == NULL) {
  ------------------
  |  Branch (1253:9): [True: 0, False: 22.5k]
  ------------------
 1254|       |        /* if localtime fails, return an arbitrary date (1980-01-01 00:00:00) */
 1255|      0|        dtime->date = (1 << 5) + 1;
 1256|      0|        dtime->time = 0;
 1257|      0|        if (ze) {
  ------------------
  |  Branch (1257:13): [True: 0, False: 0]
  ------------------
 1258|      0|            zip_error_set(ze, ZIP_ER_INVAL, errno);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1259|      0|        }
 1260|      0|        return -1;
 1261|      0|    }
 1262|  22.5k|    if (tpm->tm_year < 80) {
  ------------------
  |  Branch (1262:9): [True: 0, False: 22.5k]
  ------------------
 1263|      0|        tpm->tm_year = 80;
 1264|      0|    }
 1265|       |
 1266|  22.5k|    dtime->date = (zip_uint16_t)(((tpm->tm_year + 1900 - 1980) << 9) + ((tpm->tm_mon + 1) << 5) + tpm->tm_mday);
 1267|  22.5k|    dtime->time = (zip_uint16_t)(((tpm->tm_hour) << 11) + ((tpm->tm_min) << 5) + ((tpm->tm_sec) >> 1));
 1268|       |
 1269|  22.5k|    return 0;
 1270|  22.5k|}
_zip_dirent_apply_attributes:
 1273|  42.4k|bool _zip_dirent_apply_attributes(zip_dirent_t *de, zip_file_attributes_t *attributes, bool force_zip64) {
 1274|  42.4k|    zip_uint16_t length;
 1275|  42.4k|    bool has_changed = false;
 1276|  42.4k|    zip_uint16_t version_madeby, version_needed;
 1277|       |
 1278|  42.4k|    if (attributes->valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS) {
  ------------------
  |  |  366|  42.4k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  |  Branch (1278:9): [True: 22.7k, False: 19.7k]
  ------------------
 1279|  22.7k|        zip_uint16_t mask = attributes->general_purpose_bit_mask & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK;
  ------------------
  |  |  102|  22.7k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK 0x083e
  ------------------
 1280|  22.7k|        zip_uint16_t bitflags = (de->bitflags & ~mask) | (attributes->general_purpose_bit_flags & mask);
 1281|  22.7k|        if (de->bitflags != bitflags) {
  ------------------
  |  Branch (1281:13): [True: 15.7k, False: 6.91k]
  ------------------
 1282|  15.7k|            de->bitflags = bitflags;
 1283|  15.7k|            has_changed = true;
 1284|  15.7k|        }
 1285|  22.7k|    }
 1286|  42.4k|    if (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) {
  ------------------
  |  |  363|  42.4k|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
  |  Branch (1286:9): [True: 0, False: 42.4k]
  ------------------
 1287|      0|        zip_uint16_t int_attrib = (de->int_attrib & ~0x1) | (attributes->ascii ? 1 : 0);
  ------------------
  |  Branch (1287:62): [True: 0, False: 0]
  ------------------
 1288|      0|        if (de->int_attrib != int_attrib) {
  ------------------
  |  Branch (1288:13): [True: 0, False: 0]
  ------------------
 1289|      0|            de->int_attrib = int_attrib;
 1290|      0|            has_changed = true;
 1291|      0|        }
 1292|      0|    }
 1293|       |    /* manually set attributes are preferred over attributes provided by source */
 1294|  42.4k|    if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES)) {
  ------------------
  |  |  340|  42.4k|#define ZIP_DIRENT_ATTRIBUTES 0x0010u
  ------------------
                  if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES)) {
  ------------------
  |  |  365|  29.2k|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
  |  Branch (1294:9): [True: 29.2k, False: 13.1k]
  |  Branch (1294:55): [True: 0, False: 29.2k]
  ------------------
 1295|      0|        if (de->ext_attrib != attributes->external_file_attributes) {
  ------------------
  |  Branch (1295:13): [True: 0, False: 0]
  ------------------
 1296|      0|            de->ext_attrib = attributes->external_file_attributes;
 1297|      0|            has_changed = true;
 1298|      0|        }
 1299|      0|    }
 1300|       |
 1301|  42.4k|    if (de->comp_method == ZIP_CM_LZMA) {
  ------------------
  |  |  193|  42.4k|#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
  ------------------
  |  Branch (1301:9): [True: 0, False: 42.4k]
  ------------------
 1302|      0|        version_needed = 63;
 1303|      0|    }
 1304|  42.4k|    else if (de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256) {
  ------------------
  |  |  220|  84.8k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
                  else if (de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256) {
  ------------------
  |  |  221|  80.9k|#define ZIP_EM_AES_192 0x0102
  ------------------
                  else if (de->encryption_method == ZIP_EM_AES_128 || de->encryption_method == ZIP_EM_AES_192 || de->encryption_method == ZIP_EM_AES_256) {
  ------------------
  |  |  222|  38.4k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (1304:14): [True: 3.97k, False: 38.4k]
  |  Branch (1304:57): [True: 0, False: 38.4k]
  |  Branch (1304:100): [True: 13.1k, False: 25.3k]
  ------------------
 1305|  17.1k|        version_needed = 51;
 1306|  17.1k|    }
 1307|  25.3k|    else if (de->comp_method == ZIP_CM_BZIP2) {
  ------------------
  |  |  191|  25.3k|#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
  ------------------
  |  Branch (1307:14): [True: 0, False: 25.3k]
  ------------------
 1308|      0|        version_needed = 46;
 1309|      0|    }
 1310|  25.3k|    else if (force_zip64 || _zip_dirent_needs_zip64(de, 0)) {
  ------------------
  |  Branch (1310:14): [True: 0, False: 25.3k]
  |  Branch (1310:29): [True: 0, False: 25.3k]
  ------------------
 1311|      0|        version_needed = 45;
 1312|      0|    }
 1313|  25.3k|    else if (de->comp_method == ZIP_CM_DEFLATE || de->encryption_method == ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  187|  50.6k|#define ZIP_CM_DEFLATE 8         /* deflated */
  ------------------
                  else if (de->comp_method == ZIP_CM_DEFLATE || de->encryption_method == ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|  22.4k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (1313:14): [True: 2.84k, False: 22.4k]
  |  Branch (1313:51): [True: 1.44k, False: 21.0k]
  ------------------
 1314|  4.29k|        version_needed = 20;
 1315|  4.29k|    }
 1316|  21.0k|    else if ((length = _zip_string_length(de->filename)) > 0 && de->filename->raw[length - 1] == '/') {
  ------------------
  |  Branch (1316:14): [True: 21.0k, False: 0]
  |  Branch (1316:65): [True: 13.1k, False: 7.84k]
  ------------------
 1317|  13.1k|        version_needed = 20;
 1318|  13.1k|    }
 1319|  7.84k|    else {
 1320|  7.84k|        version_needed = 10;
 1321|  7.84k|    }
 1322|       |
 1323|  42.4k|    if (attributes->valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED) {
  ------------------
  |  |  364|  42.4k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  |  Branch (1323:9): [True: 34.8k, False: 7.58k]
  ------------------
 1324|  34.8k|        version_needed = ZIP_MAX(version_needed, attributes->version_needed);
  ------------------
  |  |  514|  34.8k|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (514:24): [True: 0, False: 34.8k]
  |  |  ------------------
  ------------------
 1325|  34.8k|    }
 1326|       |
 1327|  42.4k|    if (de->version_needed != version_needed) {
  ------------------
  |  Branch (1327:9): [True: 17.4k, False: 25.0k]
  ------------------
 1328|  17.4k|        de->version_needed = version_needed;
 1329|  17.4k|        has_changed = true;
 1330|  17.4k|    }
 1331|       |
 1332|  42.4k|    version_madeby = 63 | (de->version_madeby & 0xff00);
 1333|  42.4k|    if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM)) {
  ------------------
  |  |  340|  42.4k|#define ZIP_DIRENT_ATTRIBUTES 0x0010u
  ------------------
                  if ((de->changed & ZIP_DIRENT_ATTRIBUTES) == 0 && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM)) {
  ------------------
  |  |  362|  29.2k|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
  |  Branch (1333:9): [True: 29.2k, False: 13.1k]
  |  Branch (1333:55): [True: 0, False: 29.2k]
  ------------------
 1334|      0|        version_madeby = (version_madeby & 0xff) | (zip_uint16_t)(attributes->host_system << 8);
 1335|      0|    }
 1336|  42.4k|    if (de->version_madeby != version_madeby) {
  ------------------
  |  Branch (1336:9): [True: 0, False: 42.4k]
  ------------------
 1337|      0|        de->version_madeby = version_madeby;
 1338|      0|        has_changed = true;
 1339|      0|    }
 1340|       |
 1341|  42.4k|    return has_changed;
 1342|  42.4k|}
zip_dirent_get_last_mod_mtime:
 1391|  18.6k|time_t zip_dirent_get_last_mod_mtime(zip_dirent_t *de) {
 1392|  18.6k|    if (!de->last_mod_mtime_valid) {
  ------------------
  |  Branch (1392:9): [True: 18.6k, False: 0]
  ------------------
 1393|  18.6k|        de->last_mod_mtime = _zip_d2u_time(&de->last_mod);
 1394|  18.6k|        de->last_mod_mtime_valid = true;
 1395|  18.6k|    }
 1396|       |
 1397|  18.6k|    return de->last_mod_mtime;
 1398|  18.6k|}
zip_dirent.c:_zip_dirent_process_ef_utf_8:
  723|  38.7k|static zip_string_t *_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str, bool check_consistency) {
  724|  38.7k|    zip_uint16_t ef_len;
  725|  38.7k|    zip_uint32_t ef_crc;
  726|  38.7k|    zip_buffer_t *buffer;
  727|       |
  728|  38.7k|    const zip_uint8_t *ef = _zip_extra_fields_get_by_id(&de->extra_fields, &ef_len, id, 0, ZIP_EF_BOTH, NULL);
  ------------------
  |  |  262|  38.7k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  38.7k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  38.7k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  38.7k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  38.7k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  729|       |
  730|  38.7k|    if (ef == NULL || ef_len < 5 || ef[0] != 1) {
  ------------------
  |  Branch (730:9): [True: 38.5k, False: 119]
  |  Branch (730:23): [True: 6, False: 113]
  |  Branch (730:37): [True: 7, False: 106]
  ------------------
  731|  38.5k|        return str;
  732|  38.5k|    }
  733|       |
  734|    106|    if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) {
  ------------------
  |  Branch (734:9): [True: 0, False: 106]
  ------------------
  735|      0|        return str;
  736|      0|    }
  737|       |
  738|    106|    _zip_buffer_get_8(buffer);
  739|    106|    ef_crc = _zip_buffer_get_32(buffer);
  740|       |
  741|    106|    if (_zip_string_crc32(str) == ef_crc) {
  ------------------
  |  Branch (741:9): [True: 105, False: 1]
  ------------------
  742|    105|        zip_uint16_t len = (zip_uint16_t)_zip_buffer_left(buffer);
  743|    105|        zip_string_t *ef_str = _zip_string_new(_zip_buffer_get(buffer, len), len, ZIP_FL_ENC_UTF_8, NULL);
  ------------------
  |  |  107|    105|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
  744|       |
  745|    105|        if (ef_str != NULL) {
  ------------------
  |  Branch (745:13): [True: 103, False: 2]
  ------------------
  746|    103|            if (check_consistency) {
  ------------------
  |  Branch (746:17): [True: 0, False: 103]
  ------------------
  747|      0|                if (!_zip_string_equal(str, ef_str) && _zip_string_is_ascii(ef_str)) {
  ------------------
  |  Branch (747:21): [True: 0, False: 0]
  |  Branch (747:56): [True: 0, False: 0]
  ------------------
  748|      0|                    _zip_string_free(ef_str);
  749|      0|                    _zip_buffer_free(buffer);
  750|      0|                    return NULL;
  751|      0|                }
  752|      0|            }
  753|       |
  754|    103|            _zip_string_free(str);
  755|    103|            str = ef_str;
  756|    103|        }
  757|    105|    }
  758|       |
  759|    106|    _zip_buffer_free(buffer);
  760|       |
  761|    106|    return str;
  762|    106|}
zip_dirent.c:_zip_dirent_process_winzip_aes:
  765|  18.8k|static bool _zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error) {
  766|  18.8k|    zip_uint16_t ef_len;
  767|  18.8k|    zip_buffer_t *buffer;
  768|  18.8k|    const zip_uint8_t *ef;
  769|  18.8k|    bool crc_valid;
  770|  18.8k|    zip_uint16_t enc_method;
  771|       |
  772|       |
  773|  18.8k|    if (de->comp_method != ZIP_CM_WINZIP_AES) {
  ------------------
  |  |   79|  18.8k|#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
  ------------------
  |  Branch (773:9): [True: 10.5k, False: 8.31k]
  ------------------
  774|  10.5k|        return true;
  775|  10.5k|    }
  776|       |
  777|  8.31k|    ef = _zip_extra_fields_get_by_id(&de->extra_fields, &ef_len, ZIP_EF_WINZIP_AES, 0, ZIP_EF_BOTH, NULL);
  ------------------
  |  |   91|  8.31k|#define ZIP_EF_WINZIP_AES 0x9901
  ------------------
                  ef = _zip_extra_fields_get_by_id(&de->extra_fields, &ef_len, ZIP_EF_WINZIP_AES, 0, ZIP_EF_BOTH, NULL);
  ------------------
  |  |  262|  8.31k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  8.31k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  8.31k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  8.31k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  8.31k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|       |
  779|  8.31k|    if (ef == NULL || ef_len < 7) {
  ------------------
  |  Branch (779:9): [True: 1, False: 8.31k]
  |  Branch (779:23): [True: 0, False: 8.31k]
  ------------------
  780|      1|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  152|      1|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  237|      1|#define ZIP_ER_DETAIL_INVALID_WINZIPAES_EF 16             /* E invalid WinZip AES extra field */
  ------------------
  781|      1|        return false;
  782|      1|    }
  783|       |
  784|  8.31k|    if ((buffer = _zip_buffer_new((zip_uint8_t *)ef, ef_len)) == NULL) {
  ------------------
  |  Branch (784:9): [True: 0, False: 8.31k]
  ------------------
  785|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  786|      0|        return false;
  787|      0|    }
  788|       |
  789|       |    /* version */
  790|       |
  791|  8.31k|    crc_valid = true;
  792|  8.31k|    switch (_zip_buffer_get_16(buffer)) {
  793|      0|    case 1:
  ------------------
  |  Branch (793:5): [True: 0, False: 8.31k]
  ------------------
  794|      0|        break;
  795|       |
  796|  8.31k|    case 2:
  ------------------
  |  Branch (796:5): [True: 8.31k, False: 0]
  ------------------
  797|  8.31k|        crc_valid = false;
  798|       |        /* TODO: When checking consistency, check that crc is 0. */
  799|  8.31k|        break;
  800|       |
  801|      0|    default:
  ------------------
  |  Branch (801:5): [True: 0, False: 8.31k]
  ------------------
  802|      0|        zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  803|      0|        _zip_buffer_free(buffer);
  804|      0|        return false;
  805|  8.31k|    }
  806|       |
  807|       |    /* vendor */
  808|  8.31k|    if (memcmp(_zip_buffer_get(buffer, 2), "AE", 2) != 0) {
  ------------------
  |  Branch (808:9): [True: 0, False: 8.31k]
  ------------------
  809|      0|        zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  810|      0|        _zip_buffer_free(buffer);
  811|      0|        return false;
  812|      0|    }
  813|       |
  814|       |    /* mode */
  815|  8.31k|    switch (_zip_buffer_get_8(buffer)) {
  816|  1.95k|    case 1:
  ------------------
  |  Branch (816:5): [True: 1.95k, False: 6.35k]
  ------------------
  817|  1.95k|        enc_method = ZIP_EM_AES_128;
  ------------------
  |  |  220|  1.95k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
  818|  1.95k|        break;
  819|      0|    case 2:
  ------------------
  |  Branch (819:5): [True: 0, False: 8.31k]
  ------------------
  820|      0|        enc_method = ZIP_EM_AES_192;
  ------------------
  |  |  221|      0|#define ZIP_EM_AES_192 0x0102
  ------------------
  821|      0|        break;
  822|  6.35k|    case 3:
  ------------------
  |  Branch (822:5): [True: 6.35k, False: 1.95k]
  ------------------
  823|  6.35k|        enc_method = ZIP_EM_AES_256;
  ------------------
  |  |  222|  6.35k|#define ZIP_EM_AES_256 0x0103
  ------------------
  824|  6.35k|        break;
  825|      0|    default:
  ------------------
  |  Branch (825:5): [True: 0, False: 8.31k]
  ------------------
  826|      0|        zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  827|      0|        _zip_buffer_free(buffer);
  828|      0|        return false;
  829|  8.31k|    }
  830|       |
  831|  8.31k|    if (ef_len != 7) {
  ------------------
  |  Branch (831:9): [True: 0, False: 8.31k]
  ------------------
  832|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_WINZIPAES_EF);
  ------------------
  |  |  237|      0|#define ZIP_ER_DETAIL_INVALID_WINZIPAES_EF 16             /* E invalid WinZip AES extra field */
  ------------------
  833|      0|        _zip_buffer_free(buffer);
  834|      0|        return false;
  835|      0|    }
  836|       |
  837|  8.31k|    de->crc_valid = crc_valid;
  838|  8.31k|    de->encryption_method = enc_method;
  839|  8.31k|    de->comp_method = _zip_buffer_get_16(buffer);
  840|       |
  841|  8.31k|    _zip_buffer_free(buffer);
  842|       |    return true;
  843|  8.31k|}
zip_dirent.c:_zip_ef_utf8:
 1184|    204|static zip_extra_field_t *_zip_ef_utf8(zip_uint16_t id, zip_string_t *str, zip_error_t *error) {
 1185|    204|    const zip_uint8_t *raw;
 1186|    204|    zip_uint32_t len;
 1187|    204|    zip_buffer_t *buffer;
 1188|    204|    zip_extra_field_t *ef;
 1189|       |
 1190|    204|    if ((raw = _zip_string_get(str, &len, ZIP_FL_ENC_RAW, NULL)) == NULL) {
  ------------------
  |  |  102|    204|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
  |  Branch (1190:9): [True: 0, False: 204]
  ------------------
 1191|       |        /* error already set */
 1192|      0|        return NULL;
 1193|      0|    }
 1194|       |
 1195|    204|    if (len + 5 > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|    204|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (1195:9): [True: 0, False: 204]
  ------------------
 1196|      0|        zip_error_set(error, ZIP_ER_INVAL, 0); /* TODO: better error code? */
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
 1197|      0|        return NULL;
 1198|      0|    }
 1199|       |
 1200|    204|    if ((buffer = _zip_buffer_new(NULL, len + 5)) == NULL) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 204]
  ------------------
 1201|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
 1202|      0|        return NULL;
 1203|      0|    }
 1204|       |
 1205|    204|    _zip_buffer_put_8(buffer, 1);
 1206|    204|    _zip_buffer_put_32(buffer, _zip_string_crc32(str));
 1207|    204|    _zip_buffer_put(buffer, raw, len);
 1208|       |
 1209|    204|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (1209:9): [True: 0, False: 204]
  ------------------
 1210|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
 1211|      0|        _zip_buffer_free(buffer);
 1212|      0|        return NULL;
 1213|      0|    }
 1214|       |
 1215|    204|    ef = _zip_ef_new(id, (zip_uint16_t)(_zip_buffer_offset(buffer)), _zip_buffer_data(buffer));
 1216|    204|    _zip_buffer_free(buffer);
 1217|       |
 1218|    204|    return ef;
 1219|    204|}

zip_discard:
   45|  9.77k|void zip_discard(zip_t *za) {
   46|  9.77k|    zip_uint64_t i;
   47|       |
   48|  9.77k|    if (za == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 9.77k]
  ------------------
   49|      0|        return;
   50|      0|    }
   51|       |
   52|  9.77k|    if (za->src) {
  ------------------
  |  Branch (52:9): [True: 9.77k, False: 0]
  ------------------
   53|  9.77k|        zip_source_close(za->src);
   54|  9.77k|        zip_source_free(za->src);
   55|  9.77k|    }
   56|       |
   57|  9.77k|    if (za->default_password != NULL) {
  ------------------
  |  Branch (57:9): [True: 7.62k, False: 2.14k]
  ------------------
   58|  7.62k|        _zip_crypto_clear(za->default_password, strlen(za->default_password));
  ------------------
  |  |  533|  7.62k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
   59|  7.62k|    }
   60|  9.77k|    free(za->default_password);
   61|  9.77k|    _zip_string_free(za->comment_orig);
   62|  9.77k|    _zip_string_free(za->comment_changes);
   63|       |
   64|  9.77k|    _zip_hash_free(za->names);
   65|       |
   66|  9.77k|    if (za->entry) {
  ------------------
  |  Branch (66:9): [True: 7.49k, False: 2.27k]
  ------------------
   67|  47.8k|        for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (67:21): [True: 40.3k, False: 7.49k]
  ------------------
   68|  40.3k|            _zip_entry_finalize(za->entry + i);
   69|  40.3k|        }
   70|  7.49k|        free(za->entry);
   71|  7.49k|    }
   72|       |
   73|  9.77k|    for (i = 0; i < za->nopen_source; i++) {
  ------------------
  |  Branch (73:17): [True: 0, False: 9.77k]
  ------------------
   74|      0|        _zip_source_invalidate(za->open_source[i]);
   75|      0|    }
   76|  9.77k|    free(za->open_source);
   77|       |
   78|  9.77k|    _zip_progress_free(za->progress);
   79|       |
   80|  9.77k|    zip_error_fini(&za->error);
   81|       |
   82|  9.77k|    free(za);
   83|       |
   84|  9.77k|    return;
   85|  9.77k|}

_zip_entry_finalize:
   37|  50.1M|void _zip_entry_finalize(zip_entry_t *e) {
   38|  50.1M|    _zip_unchange_data(e);
   39|  50.1M|    _zip_dirent_free(e->orig);
   40|  50.1M|    _zip_dirent_free(e->changes);
   41|  50.1M|}
_zip_entry_init:
   44|  50.1M|void _zip_entry_init(zip_entry_t *e) {
   45|  50.1M|    e->orig = NULL;
   46|  50.1M|    e->changes = NULL;
   47|       |    e->source = NULL;
   48|  50.1M|    e->deleted = 0;
   49|  50.1M|}

zip_error_code_system:
   39|    740|ZIP_EXTERN int zip_error_code_system(const zip_error_t *error) {
   40|    740|    return error->sys_err;
   41|    740|}
zip_error_code_zip:
   44|  25.2k|ZIP_EXTERN int zip_error_code_zip(const zip_error_t *error) {
   45|  25.2k|    return error->zip_err;
   46|  25.2k|}
zip_error_fini:
   49|  71.0k|ZIP_EXTERN void zip_error_fini(zip_error_t *err) {
   50|  71.0k|    free(err->str);
   51|       |    err->str = NULL;
   52|  71.0k|}
zip_error_init:
   55|   283k|ZIP_EXTERN void zip_error_init(zip_error_t *err) {
   56|   283k|    err->zip_err = ZIP_ER_OK;
  ------------------
  |  |  131|   283k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   57|   283k|    err->sys_err = 0;
   58|       |    err->str = NULL;
   59|   283k|}
_zip_error_clear:
   86|   134k|void _zip_error_clear(zip_error_t *err) {
   87|   134k|    if (err == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 134k]
  ------------------
   88|      0|        return;
   89|      0|    }
   90|       |
   91|   134k|    err->zip_err = ZIP_ER_OK;
  ------------------
  |  |  131|   134k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   92|   134k|    err->sys_err = 0;
   93|   134k|}
_zip_error_copy:
   96|  4.49k|void _zip_error_copy(zip_error_t *dst, const zip_error_t *src) {
   97|  4.49k|    if (dst == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 4.49k]
  ------------------
   98|      0|        return;
   99|      0|    }
  100|       |
  101|  4.49k|    dst->zip_err = src->zip_err;
  102|  4.49k|    dst->sys_err = src->sys_err;
  103|  4.49k|}
zip_error_set:
  121|  98.4k|void zip_error_set(zip_error_t *err, int ze, int se) {
  122|  98.4k|    if (err) {
  ------------------
  |  Branch (122:9): [True: 22.8k, False: 75.5k]
  ------------------
  123|  22.8k|        err->zip_err = ze;
  124|  22.8k|        err->sys_err = se;
  125|  22.8k|    }
  126|  98.4k|}
zip_error_set_from_source:
  129|    198|void zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {
  130|    198|    if (src == NULL) {
  ------------------
  |  Branch (130:9): [True: 0, False: 198]
  ------------------
  131|      0|        zip_error_set(err, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  132|      0|        return;
  133|      0|    }
  134|       |
  135|    198|    _zip_error_copy(err, zip_source_error(src));
  136|    198|}
zip_error_to_data:
  139|    232|zip_int64_t zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length) {
  140|    232|    int *e = (int *)data;
  141|       |
  142|    232|    if (length < sizeof(int) * 2) {
  ------------------
  |  Branch (142:9): [True: 0, False: 232]
  ------------------
  143|      0|        return -1;
  144|      0|    }
  145|       |
  146|    232|    e[0] = zip_error_code_zip(error);
  147|    232|    e[1] = zip_error_code_system(error);
  148|    232|    return sizeof(int) * 2;
  149|    232|}

_zip_ef_delete_by_id:
   67|  50.3k|zip_extra_field_t *_zip_ef_delete_by_id(zip_extra_field_t *ef, zip_uint16_t id, zip_uint16_t id_idx) {
   68|  50.3k|    zip_extra_field_t *head, *prev;
   69|  50.3k|    int i;
   70|       |
   71|  50.3k|    i = 0;
   72|  50.3k|    head = ef;
   73|  50.3k|    prev = NULL;
   74|  50.6k|    for (; ef; ef = (prev ? prev->next : head)) {
  ------------------
  |  Branch (74:12): [True: 293, False: 50.3k]
  |  Branch (74:22): [True: 0, False: 293]
  ------------------
   75|    293|        if ((ef->id == id) || (id == ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  121|    249|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    249|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (75:13): [True: 44, False: 249]
  |  Branch (75:31): [True: 249, False: 0]
  ------------------
   76|    293|            if (id_idx == ZIP_EXTRA_FIELD_ALL || i == id_idx) {
  ------------------
  |  |  121|    293|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    586|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (76:17): [True: 293, False: 0]
  |  Branch (76:50): [True: 0, False: 0]
  ------------------
   77|    293|                if (prev) {
  ------------------
  |  Branch (77:21): [True: 0, False: 293]
  ------------------
   78|      0|                    prev->next = ef->next;
   79|      0|                }
   80|    293|                else {
   81|    293|                    head = ef->next;
   82|    293|                }
   83|    293|                ef->next = NULL;
   84|    293|                _zip_ef_free(ef);
   85|       |
   86|    293|                if (id_idx == ZIP_EXTRA_FIELD_ALL) {
  ------------------
  |  |  121|    293|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|    293|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (86:21): [True: 293, False: 0]
  ------------------
   87|    293|                    continue;
   88|    293|                }
   89|    293|            }
   90|       |
   91|      0|            i++;
   92|      0|            if (i > id_idx) {
  ------------------
  |  Branch (92:17): [True: 0, False: 0]
  ------------------
   93|      0|                break;
   94|      0|            }
   95|      0|        }
   96|      0|        prev = ef;
   97|      0|    }
   98|       |
   99|  50.3k|    return head;
  100|  50.3k|}
_zip_ef_free:
  103|   154k|void _zip_ef_free(zip_extra_field_t *ef) {
  104|   154k|    zip_extra_field_t *ef2;
  105|       |
  106|   196k|    while (ef) {
  ------------------
  |  Branch (106:12): [True: 41.7k, False: 154k]
  ------------------
  107|  41.7k|        ef2 = ef->next;
  108|  41.7k|        free(ef->data);
  109|  41.7k|        free(ef);
  110|  41.7k|        ef = ef2;
  111|  41.7k|    }
  112|   154k|}
_zip_ef_find:
  114|  96.1k|zip_extra_field_t *_zip_ef_find(zip_extra_field_t *ef_head, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_extra_field_t **prev) {
  115|  96.1k|    zip_extra_field_t *ef;
  116|  96.1k|    zip_uint16_t i;
  117|       |
  118|  96.1k|    i = 0;
  119|   129k|    for (ef = ef_head; ef; ef = ef->next) {
  ------------------
  |  Branch (119:24): [True: 42.4k, False: 87.2k]
  ------------------
  120|  42.4k|        if (ef->id == ef_id) {
  ------------------
  |  Branch (120:13): [True: 12.6k, False: 29.7k]
  ------------------
  121|  12.6k|            if (i == ef_idx) {
  ------------------
  |  Branch (121:17): [True: 8.93k, False: 3.73k]
  ------------------
  122|  8.93k|                return ef;
  123|  8.93k|            }
  124|  3.73k|            i++;
  125|  3.73k|        }
  126|  33.5k|        if (prev) {
  ------------------
  |  Branch (126:13): [True: 5.16k, False: 28.3k]
  ------------------
  127|  5.16k|            *prev = ef;
  128|  5.16k|        }
  129|  33.5k|    }
  130|       |
  131|  87.2k|    return NULL;
  132|  96.1k|}
_zip_ef_get_by_id:
  135|  94.5k|const zip_uint8_t *_zip_ef_get_by_id(const zip_extra_field_t *ef_head, zip_uint16_t *lenp, zip_uint16_t id, zip_uint16_t id_idx, zip_flags_t flags) {
  136|  94.5k|    static const zip_uint8_t empty[1] = {'\0'};
  137|       |
  138|  94.5k|    zip_extra_field_t *ef = _zip_ef_find((zip_extra_field_t *)ef_head, id, id_idx, NULL);
  139|       |
  140|  94.5k|    if (ef) {
  ------------------
  |  Branch (140:9): [True: 8.93k, False: 85.6k]
  ------------------
  141|  8.93k|        if (lenp) {
  ------------------
  |  Branch (141:13): [True: 8.93k, False: 0]
  ------------------
  142|  8.93k|            *lenp = ef->size;
  143|  8.93k|        }
  144|  8.93k|        if (ef->size > 0) {
  ------------------
  |  Branch (144:13): [True: 8.90k, False: 23]
  ------------------
  145|  8.90k|            return ef->data;
  146|  8.90k|        }
  147|     23|        else {
  148|     23|            return empty;
  149|     23|        }
  150|  8.93k|    }
  151|       |
  152|  85.6k|    return NULL;
  153|  94.5k|}
_zip_ef_new:
  155|  41.7k|zip_extra_field_t *_zip_ef_new(zip_uint16_t id, zip_uint16_t size, const zip_uint8_t *data) {
  156|  41.7k|    zip_extra_field_t *ef;
  157|       |
  158|  41.7k|    if ((ef = (zip_extra_field_t *)malloc(sizeof(*ef))) == NULL) {
  ------------------
  |  Branch (158:9): [True: 0, False: 41.7k]
  ------------------
  159|      0|        return NULL;
  160|      0|    }
  161|       |
  162|  41.7k|    ef->next = NULL;
  163|  41.7k|    ef->id = id;
  164|  41.7k|    ef->size = size;
  165|  41.7k|    if (size > 0) {
  ------------------
  |  Branch (165:9): [True: 36.0k, False: 5.78k]
  ------------------
  166|  36.0k|        if ((ef->data = (zip_uint8_t *)_zip_memdup(data, size, NULL)) == NULL) {
  ------------------
  |  Branch (166:13): [True: 0, False: 36.0k]
  ------------------
  167|      0|            free(ef);
  168|      0|            return NULL;
  169|      0|        }
  170|  36.0k|    }
  171|  5.78k|    else {
  172|  5.78k|        ef->data = NULL;
  173|  5.78k|    }
  174|       |
  175|  41.7k|    return ef;
  176|  41.7k|}
_zip_ef_parse:
  179|  9.06k|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) {
  180|  9.06k|    zip_buffer_t *buffer;
  181|  9.06k|    zip_extra_field_t *ef, *ef2, *ef_head;
  182|       |
  183|  9.06k|    if ((buffer = _zip_buffer_new((zip_uint8_t *)data, len)) == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 9.06k]
  ------------------
  184|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  185|      0|        return false;
  186|      0|    }
  187|       |
  188|  9.06k|    ef_head = ef = NULL;
  189|       |
  190|  23.3k|    while (_zip_buffer_ok(buffer) && _zip_buffer_left(buffer) >= 4) {
  ------------------
  |  Branch (190:12): [True: 23.3k, False: 0]
  |  Branch (190:38): [True: 14.3k, False: 9.02k]
  ------------------
  191|  14.3k|        zip_uint16_t fid, flen;
  192|  14.3k|        zip_uint8_t *ef_data;
  193|       |
  194|  14.3k|        fid = _zip_buffer_get_16(buffer);
  195|  14.3k|        flen = _zip_buffer_get_16(buffer);
  196|  14.3k|        ef_data = _zip_buffer_get(buffer, flen);
  197|       |
  198|  14.3k|        if (ef_data == NULL) {
  ------------------
  |  Branch (198:13): [True: 36, False: 14.3k]
  ------------------
  199|     36|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_EF_LENGTH);
  ------------------
  |  |  152|     36|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_EF_LENGTH);
  ------------------
  |  |  239|     36|#define ZIP_ER_DETAIL_INVALID_EF_LENGTH 18                /* E extra field length is invalid */
  ------------------
  200|     36|            _zip_buffer_free(buffer);
  201|     36|            _zip_ef_free(ef_head);
  202|     36|            return false;
  203|     36|        }
  204|       |
  205|  14.3k|        if ((ef2 = _zip_ef_new(fid, flen, ef_data)) == NULL) {
  ------------------
  |  Branch (205:13): [True: 0, False: 14.3k]
  ------------------
  206|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  207|      0|            _zip_buffer_free(buffer);
  208|      0|            _zip_ef_free(ef_head);
  209|      0|            return false;
  210|      0|        }
  211|       |
  212|  14.3k|        if (ef_head) {
  ------------------
  |  Branch (212:13): [True: 5.28k, False: 9.03k]
  ------------------
  213|  5.28k|            ef->next = ef2;
  214|  5.28k|            ef = ef2;
  215|  5.28k|        }
  216|  9.03k|        else {
  217|  9.03k|            ef_head = ef = ef2;
  218|  9.03k|        }
  219|  14.3k|    }
  220|       |
  221|  9.02k|    if (!_zip_buffer_eof(buffer)) {
  ------------------
  |  Branch (221:9): [True: 261, False: 8.76k]
  ------------------
  222|       |        /* Android APK files align stored file data with padding in extra fields; ignore. */
  223|       |        /* see https://android.googlesource.com/platform/build/+/master/tools/zipalign/ZipAlign.cpp */
  224|       |        /* buffer is at most 64k long, so this can't overflow. */
  225|    261|        size_t glen = _zip_buffer_left(buffer);
  226|    261|        zip_uint8_t *garbage;
  227|    261|        garbage = _zip_buffer_get(buffer, glen);
  228|    261|        if (glen >= 4 || garbage == NULL || memcmp(garbage, "\0\0\0", (size_t)glen) != 0) {
  ------------------
  |  Branch (228:13): [True: 0, False: 261]
  |  Branch (228:26): [True: 0, False: 261]
  |  Branch (228:45): [True: 33, False: 228]
  ------------------
  229|     33|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EF_TRAILING_GARBAGE);
  ------------------
  |  |  152|     33|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EF_TRAILING_GARBAGE);
  ------------------
  |  |  238|     33|#define ZIP_ER_DETAIL_EF_TRAILING_GARBAGE 17              /* E garbage at end of extra fields */
  ------------------
  230|     33|            _zip_buffer_free(buffer);
  231|     33|            _zip_ef_free(ef_head);
  232|     33|            return false;
  233|     33|        }
  234|    261|    }
  235|       |
  236|  8.99k|    _zip_buffer_free(buffer);
  237|       |
  238|  8.99k|    if (ef_head_p) {
  ------------------
  |  Branch (238:9): [True: 8.99k, False: 0]
  ------------------
  239|  8.99k|        *ef_head_p = ef_head;
  240|  8.99k|    }
  241|      0|    else {
  242|      0|        _zip_ef_free(ef_head);
  243|      0|    }
  244|       |
  245|       |    return true;
  246|  9.02k|}
_zip_ef_remove_internal:
  249|  18.8k|zip_extra_field_t *_zip_ef_remove_internal(zip_extra_field_t *ef) {
  250|  18.8k|    zip_extra_field_t *ef_head;
  251|  18.8k|    zip_extra_field_t *prev, *next;
  252|       |
  253|  18.8k|    ef_head = ef;
  254|  18.8k|    prev = NULL;
  255|       |
  256|  28.1k|    while (ef) {
  ------------------
  |  Branch (256:12): [True: 9.31k, False: 18.8k]
  ------------------
  257|  9.31k|        if (ZIP_EF_IS_INTERNAL(ef->id)) {
  ------------------
  |  |   94|  9.31k|#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)
  |  |  ------------------
  |  |  |  |   89|  18.6k|#define ZIP_EF_UTF_8_COMMENT 0x6375
  |  |  ------------------
  |  |               #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)
  |  |  ------------------
  |  |  |  |   90|  18.5k|#define ZIP_EF_UTF_8_NAME 0x7075
  |  |  ------------------
  |  |               #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)
  |  |  ------------------
  |  |  |  |   91|  18.5k|#define ZIP_EF_WINZIP_AES 0x9901
  |  |  ------------------
  |  |               #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)
  |  |  ------------------
  |  |  |  |   92|    886|#define ZIP_EF_ZIP64 0x0001
  |  |  ------------------
  |  |  |  Branch (94:33): [True: 66, False: 9.24k]
  |  |  |  Branch (94:65): [True: 48, False: 9.19k]
  |  |  |  Branch (94:94): [True: 8.31k, False: 886]
  |  |  |  Branch (94:123): [True: 41, False: 845]
  |  |  ------------------
  ------------------
  258|  8.46k|            next = ef->next;
  259|  8.46k|            if (ef_head == ef) {
  ------------------
  |  Branch (259:17): [True: 8.41k, False: 49]
  ------------------
  260|  8.41k|                ef_head = next;
  261|  8.41k|            }
  262|  8.46k|            ef->next = NULL;
  263|  8.46k|            _zip_ef_free(ef);
  264|  8.46k|            if (prev) {
  ------------------
  |  Branch (264:17): [True: 49, False: 8.41k]
  ------------------
  265|     49|                prev->next = next;
  266|     49|            }
  267|  8.46k|            ef = next;
  268|  8.46k|        }
  269|    845|        else {
  270|    845|            prev = ef;
  271|    845|            ef = ef->next;
  272|    845|        }
  273|  9.31k|    }
  274|       |
  275|  18.8k|    return ef_head;
  276|  18.8k|}
_zip_ef_size:
  286|   127k|zip_int32_t _zip_ef_size(const zip_extra_field_t *ef) {
  287|   127k|    zip_uint32_t size;
  288|       |
  289|   127k|    size = 0;
  290|   160k|    for (; ef; ef = ef->next) {
  ------------------
  |  Branch (290:12): [True: 33.4k, False: 127k]
  ------------------
  291|  33.4k|        size = (zip_uint32_t)(size + 4 + ef->size);
  292|  33.4k|        if (size > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  33.4k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (292:13): [True: 0, False: 33.4k]
  ------------------
  293|      0|            return -1;
  294|      0|        }
  295|  33.4k|    }
  296|       |
  297|   127k|    return (zip_int32_t)size;
  298|   127k|}
_zip_ef_write:
  301|  26.9k|int _zip_ef_write(zip_t *za, const zip_extra_field_t *ef) {
  302|  26.9k|    zip_uint8_t b[4];
  303|  26.9k|    zip_buffer_t *buffer = _zip_buffer_new(b, sizeof(b));
  304|       |
  305|  26.9k|    if (buffer == NULL) {
  ------------------
  |  Branch (305:9): [True: 0, False: 26.9k]
  ------------------
  306|      0|        return -1;
  307|      0|    }
  308|       |
  309|  55.2k|    for (; ef; ef = ef->next) {
  ------------------
  |  Branch (309:12): [True: 28.2k, False: 26.9k]
  ------------------
  310|  28.2k|        _zip_buffer_set_offset(buffer, 0);
  311|  28.2k|        _zip_buffer_put_16(buffer, ef->id);
  312|  28.2k|        _zip_buffer_put_16(buffer, ef->size);
  313|  28.2k|        if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (313:13): [True: 0, False: 28.2k]
  ------------------
  314|      0|            zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  315|      0|            _zip_buffer_free(buffer);
  316|      0|            return -1;
  317|      0|        }
  318|  28.2k|        if (_zip_write(za, b, 4) < 0) {
  ------------------
  |  Branch (318:13): [True: 0, False: 28.2k]
  ------------------
  319|      0|            _zip_buffer_free(buffer);
  320|      0|            return -1;
  321|      0|        }
  322|  28.2k|        if (ef->size > 0) {
  ------------------
  |  Branch (322:13): [True: 27.2k, False: 1.01k]
  ------------------
  323|  27.2k|            if (_zip_write(za, ef->data, ef->size) < 0) {
  ------------------
  |  Branch (323:17): [True: 0, False: 27.2k]
  ------------------
  324|      0|                _zip_buffer_free(buffer);
  325|      0|                return -1;
  326|      0|            }
  327|  27.2k|        }
  328|  28.2k|    }
  329|       |
  330|  26.9k|    _zip_buffer_free(buffer);
  331|  26.9k|    return 0;
  332|  26.9k|}
_zip_read_local_ef:
  335|  21.2k|int _zip_read_local_ef(zip_t *za, zip_uint64_t idx) {
  336|  21.2k|    zip_entry_t *e;
  337|  21.2k|    unsigned char b[4];
  338|  21.2k|    zip_buffer_t *buffer;
  339|  21.2k|    zip_uint16_t fname_len, ef_len;
  340|       |
  341|  21.2k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (341:9): [True: 0, False: 21.2k]
  ------------------
  342|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  343|      0|        return -1;
  344|      0|    }
  345|       |
  346|  21.2k|    e = za->entry + idx;
  347|       |
  348|  21.2k|    if (e->orig == NULL || e->orig->local_extra_fields_read) {
  ------------------
  |  Branch (348:9): [True: 21.2k, False: 0]
  |  Branch (348:28): [True: 0, False: 0]
  ------------------
  349|  21.2k|        return 0;
  350|  21.2k|    }
  351|       |
  352|      0|    if (e->orig->offset + 26 > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (352:9): [True: 0, False: 0]
  ------------------
  353|      0|        zip_error_set(&za->error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  354|      0|        return -1;
  355|      0|    }
  356|       |
  357|      0|    if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) {
  ------------------
  |  Branch (357:9): [True: 0, False: 0]
  ------------------
  358|      0|        zip_error_set_from_source(&za->error, za->src);
  359|      0|        return -1;
  360|      0|    }
  361|       |
  362|      0|    if ((buffer = _zip_buffer_new_from_source(za->src, sizeof(b), b, &za->error)) == NULL) {
  ------------------
  |  Branch (362:9): [True: 0, False: 0]
  ------------------
  363|      0|        return -1;
  364|      0|    }
  365|       |
  366|      0|    fname_len = _zip_buffer_get_16(buffer);
  367|      0|    ef_len = _zip_buffer_get_16(buffer);
  368|       |
  369|      0|    if (!_zip_buffer_eof(buffer)) {
  ------------------
  |  Branch (369:9): [True: 0, False: 0]
  ------------------
  370|      0|        _zip_buffer_free(buffer);
  371|      0|        zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  372|      0|        return -1;
  373|      0|    }
  374|       |
  375|      0|    _zip_buffer_free(buffer);
  376|       |
  377|      0|    if (ef_len > 0) {
  ------------------
  |  Branch (377:9): [True: 0, False: 0]
  ------------------
  378|      0|        zip_extra_field_t *ef;
  379|      0|        zip_uint8_t *ef_raw;
  380|       |
  381|      0|        if (zip_source_seek(za->src, fname_len, SEEK_CUR) < 0) {
  ------------------
  |  Branch (381:13): [True: 0, False: 0]
  ------------------
  382|      0|            zip_error_set(&za->error, ZIP_ER_SEEK, errno);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  383|      0|            return -1;
  384|      0|        }
  385|       |
  386|      0|        ef_raw = _zip_read_data(NULL, za->src, ef_len, 0, &za->error);
  387|       |
  388|      0|        if (ef_raw == NULL) {
  ------------------
  |  Branch (388:13): [True: 0, False: 0]
  ------------------
  389|      0|            return -1;
  390|      0|        }
  391|       |
  392|      0|        if (!_zip_ef_parse(ef_raw, ef_len, ZIP_EF_LOCAL, &ef, &za->error)) {
  ------------------
  |  |  260|      0|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|      0|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (392:13): [True: 0, False: 0]
  ------------------
  393|      0|            free(ef_raw);
  394|      0|            return -1;
  395|      0|        }
  396|      0|        free(ef_raw);
  397|       |
  398|      0|        if (ef) {
  ------------------
  |  Branch (398:13): [True: 0, False: 0]
  ------------------
  399|      0|            ef = _zip_ef_remove_internal(ef);
  400|      0|            e->orig->extra_fields.local = ef;
  401|      0|        }
  402|      0|    }
  403|       |
  404|      0|    e->orig->local_extra_fields_read = 1;
  405|       |
  406|      0|    if (e->changes && e->changes->local_extra_fields_read == 0) {
  ------------------
  |  Branch (406:9): [True: 0, False: 0]
  |  Branch (406:23): [True: 0, False: 0]
  ------------------
  407|      0|        e->changes->extra_fields = e->orig->extra_fields;
  408|      0|        e->changes->local_extra_fields_read = 1;
  409|      0|    }
  410|       |
  411|      0|    return 0;
  412|      0|}
_zip_extra_fields_get_by_id:
  423|  47.5k|const zip_uint8_t *_zip_extra_fields_get_by_id(const zip_extra_fields_t *extra_fields, zip_uint16_t *lenp, zip_uint16_t extra_field_id, zip_uint16_t extra_field_index, zip_flags_t flags, zip_error_t *error) {
  424|  47.5k|    const zip_uint8_t *data;
  425|       |
  426|  47.5k|    if (flags & ZIP_EF_LOCAL) {
  ------------------
  |  |  260|  47.5k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  47.5k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (426:9): [True: 47.0k, False: 531]
  ------------------
  427|  47.0k|        data = _zip_ef_get_by_id(extra_fields->local, lenp, extra_field_id, extra_field_index, flags);
  428|  47.0k|        if (data) {
  ------------------
  |  Branch (428:13): [True: 0, False: 47.0k]
  ------------------
  429|      0|            return data;
  430|      0|        }
  431|  47.0k|    }
  432|       |
  433|  47.5k|    if (flags & ZIP_EF_CENTRAL) {
  ------------------
  |  |  261|  47.5k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  47.5k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (433:9): [True: 47.5k, False: 0]
  ------------------
  434|  47.5k|        data = _zip_ef_get_by_id(extra_fields->central, lenp, extra_field_id, extra_field_index, flags);
  435|  47.5k|        if (data) {
  ------------------
  |  Branch (435:13): [True: 8.93k, False: 38.6k]
  ------------------
  436|  8.93k|            return data;
  437|  8.93k|        }
  438|  47.5k|    }
  439|       |
  440|  38.6k|    zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|  38.6k|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  441|       |    return NULL;
  442|  47.5k|}
_zip_ef_set:
  472|  1.56k|zip_extra_field_t *_zip_ef_set(zip_extra_field_t *ef_head, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_error_t *error) {
  473|  1.56k|    zip_extra_field_t *ef_prev = NULL;
  474|  1.56k|    zip_extra_field_t *ef_new, *ef;
  475|  1.56k|    zip_int32_t new_len;
  476|       |
  477|  1.56k|    ef = _zip_ef_find(ef_head, ef_id, ef_idx, &ef_prev);
  478|       |
  479|  1.56k|    if (ef == NULL && ef_idx != ZIP_EXTRA_FIELD_NEW) {
  ------------------
  |  |  122|  1.56k|#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|  1.56k|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (479:9): [True: 1.56k, False: 0]
  |  Branch (479:23): [True: 0, False: 1.56k]
  ------------------
  480|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  481|      0|        return NULL;
  482|      0|    }
  483|       |
  484|  1.56k|    new_len = _zip_ef_size(ef_head);
  485|       |    /* This should not happen, but we want to assume lengths are >= 0 later. */
  486|  1.56k|    if (new_len < 0) {
  ------------------
  |  Branch (486:9): [True: 0, False: 1.56k]
  ------------------
  487|      0|        zip_error_set(error, ZIP_ER_EF_TOO_LARGE, 0);
  ------------------
  |  |  167|      0|#define ZIP_ER_EF_TOO_LARGE 36    /* N Extra fields too large */
  ------------------
  488|      0|        return NULL;
  489|      0|    }
  490|       |
  491|  1.56k|    if (ef != NULL) {
  ------------------
  |  Branch (491:9): [True: 0, False: 1.56k]
  ------------------
  492|      0|        new_len -= ef->size + 4;
  493|      0|    }
  494|  1.56k|    new_len += len + 4;
  495|       |
  496|  1.56k|    if (new_len > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  1.56k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (496:9): [True: 0, False: 1.56k]
  ------------------
  497|      0|        zip_error_set(error, ZIP_ER_EF_TOO_LARGE, 0);
  ------------------
  |  |  167|      0|#define ZIP_ER_EF_TOO_LARGE 36    /* N Extra fields too large */
  ------------------
  498|      0|        return NULL;
  499|      0|    }
  500|       |
  501|  1.56k|    if ((ef_new = _zip_ef_new(ef_id, len, data)) == NULL) {
  ------------------
  |  Branch (501:9): [True: 0, False: 1.56k]
  ------------------
  502|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  503|      0|        return NULL;
  504|      0|    }
  505|       |
  506|  1.56k|    if (ef != NULL) {
  ------------------
  |  Branch (506:9): [True: 0, False: 1.56k]
  ------------------
  507|      0|        ef_new->next = ef->next;
  508|      0|        ef->next = NULL;
  509|      0|        _zip_ef_free(ef);
  510|      0|    }
  511|  1.56k|    else if (ef_prev) {
  ------------------
  |  Branch (511:14): [True: 780, False: 788]
  ------------------
  512|    780|        ef_new->next = ef_prev->next;
  513|    780|    }
  514|       |
  515|  1.56k|    if (ef_prev) {
  ------------------
  |  Branch (515:9): [True: 780, False: 788]
  ------------------
  516|    780|        ef_prev->next = ef_new;
  517|    780|    }
  518|    788|    else {
  519|    788|        ef_head = ef_new;
  520|    788|    }
  521|       |
  522|  1.56k|    return ef_head;
  523|  1.56k|}
_zip_extra_fields_set:
  525|  1.56k|bool _zip_extra_fields_set(zip_extra_fields_t *extra_fields, zip_flags_t flags, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_error_t *error) {
  526|  1.56k|    zip_extra_field_t *ef;
  527|       |
  528|  1.56k|    if (flags & ZIP_EF_LOCAL) {
  ------------------
  |  |  260|  1.56k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  1.56k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (528:9): [True: 1.56k, False: 0]
  ------------------
  529|  1.56k|        ef = _zip_ef_set(extra_fields->local, ef_id, ef_idx, data, len, error);
  530|  1.56k|        if (ef == NULL) {
  ------------------
  |  Branch (530:13): [True: 0, False: 1.56k]
  ------------------
  531|      0|            return false;
  532|      0|        }
  533|  1.56k|        extra_fields->local = ef;
  534|  1.56k|    }
  535|  1.56k|    if (flags & ZIP_EF_CENTRAL) {
  ------------------
  |  |  261|  1.56k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  1.56k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (535:9): [True: 0, False: 1.56k]
  ------------------
  536|      0|        ef = _zip_ef_set(extra_fields->central, ef_id, ef_idx, data, len, error);
  537|      0|        if (ef == NULL) {
  ------------------
  |  Branch (537:13): [True: 0, False: 0]
  ------------------
  538|      0|            return false;
  539|      0|        }
  540|      0|        extra_fields->central = ef;
  541|      0|    }
  542|       |
  543|  1.56k|    return true;
  544|  1.56k|}
_zip_extra_fields_fini:
  564|  41.3k|void _zip_extra_fields_fini(zip_extra_fields_t *extra_fields) {
  565|  41.3k|    _zip_ef_free(extra_fields->local);
  566|  41.3k|    extra_fields->local = NULL;
  567|  41.3k|    _zip_ef_free(extra_fields->central);
  568|       |    extra_fields->central = NULL;
  569|  41.3k|}
_zip_extra_fields_init:
  571|  80.2k|void _zip_extra_fields_init(zip_extra_fields_t *extra_fields) {
  572|  80.2k|    extra_fields->local = NULL;
  573|       |    extra_fields->central = NULL;
  574|  80.2k|}
_zip_extra_fields_delete_by_id:
  577|  25.1k|void _zip_extra_fields_delete_by_id(zip_extra_fields_t *extra_fields, zip_uint16_t extra_field_id, zip_uint16_t extra_field_index, zip_flags_t flags) {
  578|  25.1k|    if (flags & ZIP_EF_LOCAL) {
  ------------------
  |  |  260|  25.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  25.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (578:9): [True: 25.1k, False: 0]
  ------------------
  579|  25.1k|        extra_fields->local = _zip_ef_delete_by_id(extra_fields->local, extra_field_id, extra_field_index);
  580|  25.1k|    }
  581|  25.1k|    if (flags & ZIP_EF_CENTRAL) {
  ------------------
  |  |  261|  25.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  ------------------
  |  |  |  |  105|  25.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  ------------------
  ------------------
  |  Branch (581:9): [True: 25.1k, False: 0]
  ------------------
  582|  25.1k|        extra_fields->central = _zip_ef_delete_by_id(extra_fields->central, extra_field_id, extra_field_index);
  583|  25.1k|    }
  584|  25.1k|}

zip_file_extra_field_delete:
   38|  25.1k|ZIP_EXTERN int zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags) {
   39|  25.1k|    zip_dirent_t *de;
   40|       |
   41|  25.1k|    if ((flags & ZIP_EF_BOTH) == 0) {
  ------------------
  |  |  262|  25.1k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  25.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  25.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  25.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  25.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (41:9): [True: 0, False: 25.1k]
  ------------------
   42|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  25.1k|    if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  262|  25.1k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  25.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  25.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  25.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  25.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  262|  25.1k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  25.1k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  25.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  25.1k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  25.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (((flags & ZIP_EF_BOTH) == ZIP_EF_BOTH) && (ef_idx != ZIP_EXTRA_FIELD_ALL)) {
  ------------------
  |  |  121|  25.1k|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|  25.1k|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
  |  Branch (46:9): [True: 25.1k, False: 0]
  |  Branch (46:51): [True: 0, False: 25.1k]
  ------------------
   47|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|  25.1k|    if (_zip_get_dirent(za, idx, 0, NULL) == NULL) {
  ------------------
  |  Branch (51:9): [True: 0, False: 25.1k]
  ------------------
   52|      0|        return -1;
   53|      0|    }
   54|       |
   55|  25.1k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  25.1k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  25.1k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 25.1k]
  |  |  ------------------
  ------------------
   56|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   57|      0|        return -1;
   58|      0|    }
   59|       |
   60|  25.1k|    if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) {
  ------------------
  |  Branch (60:9): [True: 0, False: 25.1k]
  ------------------
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|  25.1k|    de = za->entry[idx].changes;
   65|       |
   66|  25.1k|    _zip_extra_fields_delete_by_id(&de->extra_fields, ZIP_EXTRA_FIELD_ALL, ef_idx, flags);
  ------------------
  |  |  121|  25.1k|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|  25.1k|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
   67|  25.1k|    return 0;
   68|  25.1k|}
zip_file_extra_field_set:
  222|  1.86k|ZIP_EXTERN int zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags) {
  223|  1.86k|    if ((flags & ZIP_EF_BOTH) == 0) {
  ------------------
  |  |  262|  1.86k|#define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  260|  1.86k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  |  |  ------------------
  |  |  |  |  |  |  104|  1.86k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define ZIP_EF_BOTH (ZIP_EF_LOCAL | ZIP_EF_CENTRAL) /* include in both */
  |  |  ------------------
  |  |  |  |  261|  1.86k|#define ZIP_EF_CENTRAL ZIP_FL_CENTRAL               /* include in central directory */
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|  1.86k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (223:9): [True: 0, False: 1.86k]
  ------------------
  224|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  225|      0|        return -1;
  226|      0|    }
  227|       |
  228|  1.86k|    if (_zip_get_dirent(za, idx, 0, NULL) == NULL) {
  ------------------
  |  Branch (228:9): [True: 83, False: 1.78k]
  ------------------
  229|     83|        return -1;
  230|     83|    }
  231|       |
  232|  1.78k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  1.78k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  1.78k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 1.78k]
  |  |  ------------------
  ------------------
  233|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
  234|      0|        return -1;
  235|      0|    }
  236|  1.78k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  1.78k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  1.78k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 1.78k]
  |  |  ------------------
  ------------------
  237|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
  238|      0|        return -1;
  239|      0|    }
  240|       |
  241|  1.78k|    if (ZIP_EF_IS_INTERNAL(ef_id)) {
  ------------------
  |  |   94|  1.78k|#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)
  |  |  ------------------
  |  |  |  |   89|  3.57k|#define ZIP_EF_UTF_8_COMMENT 0x6375
  |  |  ------------------
  |  |               #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)
  |  |  ------------------
  |  |  |  |   90|  3.49k|#define ZIP_EF_UTF_8_NAME 0x7075
  |  |  ------------------
  |  |               #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)
  |  |  ------------------
  |  |  |  |   91|  3.43k|#define ZIP_EF_WINZIP_AES 0x9901
  |  |  ------------------
  |  |               #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)
  |  |  ------------------
  |  |  |  |   92|  1.61k|#define ZIP_EF_ZIP64 0x0001
  |  |  ------------------
  |  |  |  Branch (94:33): [True: 74, False: 1.71k]
  |  |  |  Branch (94:65): [True: 59, False: 1.65k]
  |  |  |  Branch (94:94): [True: 38, False: 1.61k]
  |  |  |  Branch (94:123): [True: 46, False: 1.56k]
  |  |  ------------------
  ------------------
  242|    217|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|    217|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  243|    217|        return -1;
  244|    217|    }
  245|       |
  246|  1.56k|    if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) {
  ------------------
  |  Branch (246:9): [True: 0, False: 1.56k]
  ------------------
  247|      0|        return -1;
  248|      0|    }
  249|       |
  250|  1.56k|    return _zip_extra_fields_set(&za->entry[idx].changes->extra_fields, flags, ef_id, ef_idx, data, len, &za->error);
  251|  1.56k|}
_zip_file_extra_field_prepare_for_change:
  254|  26.7k|int _zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx) {
  255|  26.7k|    zip_entry_t *e;
  256|       |
  257|  26.7k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (257:9): [True: 0, False: 26.7k]
  ------------------
  258|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  259|      0|        return -1;
  260|      0|    }
  261|       |
  262|  26.7k|    e = za->entry + idx;
  263|       |
  264|  26.7k|    if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD)) {
  ------------------
  |  |  339|  26.7k|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  |  Branch (264:9): [True: 26.7k, False: 0]
  |  Branch (264:23): [True: 5.02k, False: 21.7k]
  ------------------
  265|  5.02k|        return 0;
  266|  5.02k|    }
  267|       |
  268|  21.7k|    if (e->orig) {
  ------------------
  |  Branch (268:9): [True: 0, False: 21.7k]
  ------------------
  269|      0|        if (_zip_read_local_ef(za, idx) < 0) {
  ------------------
  |  Branch (269:13): [True: 0, False: 0]
  ------------------
  270|      0|            return -1;
  271|      0|        }
  272|      0|    }
  273|       |
  274|  21.7k|    if (e->changes == NULL) {
  ------------------
  |  Branch (274:9): [True: 0, False: 21.7k]
  ------------------
  275|      0|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (275:13): [True: 0, False: 0]
  ------------------
  276|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  277|      0|            return -1;
  278|      0|        }
  279|      0|    }
  280|       |
  281|  21.7k|    e->changes->changed |= ZIP_DIRENT_EXTRA_FIELD;
  ------------------
  |  |  339|  21.7k|#define ZIP_DIRENT_EXTRA_FIELD 0x0008u
  ------------------
  282|       |
  283|  21.7k|    return 0;
  284|  21.7k|}

zip_fclose:
   40|  18.6k|ZIP_EXTERN int zip_fclose(zip_file_t *zf) {
   41|  18.6k|    int ret;
   42|       |
   43|  18.6k|    if (zf == NULL) {
  ------------------
  |  Branch (43:9): [True: 0, False: 18.6k]
  ------------------
   44|      0|        return ZIP_ER_INVAL;
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   45|      0|    }
   46|       |
   47|  18.6k|    if (zf->src) {
  ------------------
  |  Branch (47:9): [True: 18.6k, False: 0]
  ------------------
   48|  18.6k|        if (ZIP_SOURCE_IS_OPEN_READING(zf->src)) {
  ------------------
  |  |  441|  18.6k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 18.6k, False: 0]
  |  |  ------------------
  ------------------
   49|  18.6k|            if (zip_source_close(zf->src) < 0) {
  ------------------
  |  Branch (49:17): [True: 0, False: 18.6k]
  ------------------
   50|      0|                zip_error_set_from_source(&zf->error, zf->src);
   51|      0|            }
   52|  18.6k|        }
   53|  18.6k|        zip_source_free(zf->src);
   54|  18.6k|    }
   55|       |
   56|  18.6k|    ret = 0;
   57|  18.6k|    if (zf->error.zip_err) {
  ------------------
  |  Branch (57:9): [True: 0, False: 18.6k]
  ------------------
   58|      0|        ret = zf->error.zip_err;
   59|      0|        if (zip_error_system_type(&zf->error) == ZIP_ET_SYS) {
  ------------------
  |  |  172|      0|#define ZIP_ET_SYS 1    /* sys_err is errno */
  ------------------
  |  Branch (59:13): [True: 0, False: 0]
  ------------------
   60|      0|            errno = zf->error.sys_err;
   61|      0|        }
   62|      0|    }
   63|       |
   64|  18.6k|    zip_error_fini(&zf->error);
   65|  18.6k|    free(zf);
   66|  18.6k|    return ret;
   67|  18.6k|}

zip_file_add:
   44|  18.2k|ZIP_EXTERN zip_int64_t zip_file_add(zip_t *za, const char *name, zip_source_t *source, zip_flags_t flags) {
   45|  18.2k|    if (name == NULL || source == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 18.2k]
  |  Branch (45:25): [True: 0, False: 18.2k]
  ------------------
   46|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|  18.2k|    return _zip_file_replace(za, ZIP_UINT64_MAX, name, source, flags);
  ------------------
  |  |   46|  18.2k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   51|  18.2k|}

_zip_file_get_offset:
   47|  11.3k|zip_uint64_t _zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error) {
   48|  11.3k|    zip_uint64_t offset;
   49|  11.3k|    zip_int32_t size;
   50|       |
   51|  11.3k|    if (za->entry[idx].orig == NULL) {
  ------------------
  |  Branch (51:9): [True: 0, False: 11.3k]
  ------------------
   52|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   53|      0|        return 0;
   54|      0|    }
   55|       |
   56|  11.3k|    offset = za->entry[idx].orig->offset;
   57|       |
   58|  11.3k|    if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (58:9): [True: 0, False: 11.3k]
  ------------------
   59|      0|        zip_error_set_from_source(error, za->src);
   60|      0|        return 0;
   61|      0|    }
   62|       |
   63|       |    /* TODO: cache? */
   64|  11.3k|    if ((size = _zip_dirent_size(za->src, ZIP_EF_LOCAL, error)) < 0) {
  ------------------
  |  |  260|  11.3k|#define ZIP_EF_LOCAL ZIP_FL_LOCAL                   /* include in local header */
  |  |  ------------------
  |  |  |  |  104|  11.3k|#define ZIP_FL_LOCAL 256u      /* in local header */
  |  |  ------------------
  ------------------
  |  Branch (64:9): [True: 0, False: 11.3k]
  ------------------
   65|      0|        return 0;
   66|      0|    }
   67|       |
   68|  11.3k|    if (offset + (zip_uint32_t)size > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  11.3k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (68:9): [True: 0, False: 11.3k]
  ------------------
   69|      0|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
   70|      0|        return 0;
   71|      0|    }
   72|       |
   73|  11.3k|    return offset + (zip_uint32_t)size;
   74|  11.3k|}

zip_file_rename:
   40|    923|ZIP_EXTERN int zip_file_rename(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) {
   41|    923|    const char *old_name;
   42|    923|    int old_is_dir, new_is_dir;
   43|    923|    size_t name_len = name != NULL ? strlen(name) : 0;
  ------------------
  |  Branch (43:23): [True: 923, False: 0]
  ------------------
   44|       |
   45|    923|    if (idx >= za->nentry || name_len > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|    923|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (45:9): [True: 0, False: 923]
  |  Branch (45:30): [True: 0, False: 923]
  ------------------
   46|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|    923|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|    923|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|    923|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 923]
  |  |  ------------------
  ------------------
   51|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   52|      0|        return -1;
   53|      0|    }
   54|       |
   55|    923|    if ((old_name = zip_get_name(za, idx, 0)) == NULL) {
  ------------------
  |  Branch (55:9): [True: 87, False: 836]
  ------------------
   56|     87|        return -1;
   57|     87|    }
   58|       |
   59|    836|    new_is_dir = (name_len > 0 && name[name_len - 1] == '/');
  ------------------
  |  Branch (59:19): [True: 836, False: 0]
  |  Branch (59:35): [True: 45, False: 791]
  ------------------
   60|    836|    old_is_dir = (old_name[0] != '\0' && old_name[strlen(old_name) - 1] == '/');
  ------------------
  |  Branch (60:19): [True: 836, False: 0]
  |  Branch (60:42): [True: 339, False: 497]
  ------------------
   61|       |
   62|    836|    if (new_is_dir != old_is_dir) {
  ------------------
  |  Branch (62:9): [True: 296, False: 540]
  ------------------
   63|    296|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|    296|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   64|    296|        return -1;
   65|    296|    }
   66|       |
   67|    540|    return _zip_set_name(za, idx, name, flags);
   68|    836|}

_zip_file_replace:
   54|  25.9k|zip_int64_t _zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *source, zip_flags_t flags) {
   55|  25.9k|    zip_uint64_t za_nentry_prev;
   56|       |
   57|  25.9k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  25.9k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  25.9k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 25.9k]
  |  |  ------------------
  ------------------
   58|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   59|      0|        return -1;
   60|      0|    }
   61|       |
   62|  25.9k|    za_nentry_prev = za->nentry;
   63|  25.9k|    if (idx == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|  25.9k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (63:9): [True: 25.9k, False: 0]
  ------------------
   64|  25.9k|        zip_int64_t i = -1;
   65|       |
   66|  25.9k|        if (flags & ZIP_FL_OVERWRITE) {
  ------------------
  |  |  109|  25.9k|#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
  ------------------
  |  Branch (66:13): [True: 18.2k, False: 7.65k]
  ------------------
   67|  18.2k|            i = _zip_name_locate(za, name, flags, NULL);
   68|  18.2k|        }
   69|       |
   70|  25.9k|        if (i == -1) {
  ------------------
  |  Branch (70:13): [True: 22.4k, False: 3.46k]
  ------------------
   71|       |            /* create and use new entry, used by zip_add */
   72|  22.4k|            if ((i = _zip_add_entry(za)) < 0) {
  ------------------
  |  Branch (72:17): [True: 0, False: 22.4k]
  ------------------
   73|      0|                return -1;
   74|      0|            }
   75|  22.4k|        }
   76|  25.9k|        idx = (zip_uint64_t)i;
   77|  25.9k|    }
   78|       |
   79|  25.9k|    if (name && _zip_set_name(za, idx, name, flags) != 0) {
  ------------------
  |  Branch (79:9): [True: 25.9k, False: 0]
  |  Branch (79:17): [True: 771, False: 25.1k]
  ------------------
   80|    771|        if (za->nentry != za_nentry_prev) {
  ------------------
  |  Branch (80:13): [True: 771, False: 0]
  ------------------
   81|    771|            _zip_entry_finalize(za->entry + idx);
   82|    771|            za->nentry = za_nentry_prev;
   83|    771|        }
   84|    771|        return -1;
   85|    771|    }
   86|       |
   87|       |    /* delete all extra fields - these are usually data that are
   88|       |     * strongly coupled with the original data */
   89|  25.1k|    if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  121|  25.1k|#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|  25.1k|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
                  if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  105|  25.1k|#define ZIP_FL_CENTRAL 512u    /* in central directory */
  ------------------
                  if (zip_file_extra_field_delete(za, idx, ZIP_EXTRA_FIELD_ALL, ZIP_FL_CENTRAL | ZIP_FL_LOCAL) < 0) {
  ------------------
  |  |  104|  25.1k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  |  Branch (89:9): [True: 0, False: 25.1k]
  ------------------
   90|      0|        return -1;
   91|      0|    }
   92|       |
   93|       |    /* does not change any name related data, so we can do it here;
   94|       |     * needed for a double add of the same file name */
   95|  25.1k|    _zip_unchange_data(za->entry + idx);
   96|       |
   97|  25.1k|    za->entry[idx].source = source;
   98|       |
   99|  25.1k|    return (zip_int64_t)idx;
  100|  25.1k|}

zip_file_set_comment:
   40|  2.89k|ZIP_EXTERN int zip_file_set_comment(zip_t *za, zip_uint64_t idx, const char *comment, zip_uint16_t len, zip_flags_t flags) {
   41|  2.89k|    zip_entry_t *e;
   42|  2.89k|    zip_string_t *cstr;
   43|  2.89k|    int changed;
   44|       |
   45|  2.89k|    if (_zip_get_dirent(za, idx, 0, NULL) == NULL) {
  ------------------
  |  Branch (45:9): [True: 102, False: 2.79k]
  ------------------
   46|    102|        return -1;
   47|    102|    }
   48|       |
   49|  2.79k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  2.79k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  2.79k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 2.79k]
  |  |  ------------------
  ------------------
   50|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|  2.79k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  2.79k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  2.79k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 2.79k]
  |  |  ------------------
  ------------------
   54|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
   55|      0|        return -1;
   56|      0|    }
   57|       |
   58|  2.79k|    if (len > 0 && comment == NULL) {
  ------------------
  |  Branch (58:9): [True: 2.64k, False: 148]
  |  Branch (58:20): [True: 0, False: 2.64k]
  ------------------
   59|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|  2.79k|    if (len > 0) {
  ------------------
  |  Branch (63:9): [True: 2.64k, False: 148]
  ------------------
   64|  2.64k|        if ((cstr = _zip_string_new((const zip_uint8_t *)comment, len, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (64:13): [True: 0, False: 2.64k]
  ------------------
   65|      0|            return -1;
   66|      0|        }
   67|  2.64k|        if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) {
  ------------------
  |  |  266|  2.64k|#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  101|  2.64k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  108|  2.64k|#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  107|  2.64k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  |  |  ------------------
  ------------------
                      if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) {
  ------------------
  |  |  101|  5.29k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (67:13): [True: 2.64k, False: 0]
  |  Branch (67:66): [True: 199, False: 2.44k]
  ------------------
   68|    199|            cstr->encoding = ZIP_ENCODING_UTF8_KNOWN;
   69|    199|        }
   70|  2.64k|    }
   71|    148|    else {
   72|    148|        cstr = NULL;
   73|    148|    }
   74|       |
   75|  2.79k|    e = za->entry + idx;
   76|       |
   77|  2.79k|    if (e->changes && e->changes->changed & ZIP_DIRENT_COMMENT) {
  ------------------
  |  |  338|  2.79k|#define ZIP_DIRENT_COMMENT 0x0004u
  ------------------
  |  Branch (77:9): [True: 2.79k, False: 0]
  |  Branch (77:23): [True: 235, False: 2.56k]
  ------------------
   78|    235|        _zip_string_free(e->changes->comment);
   79|    235|        if (e->orig && e->changes->cloned) {
  ------------------
  |  Branch (79:13): [True: 0, False: 235]
  |  Branch (79:24): [True: 0, False: 0]
  ------------------
   80|      0|            e->changes->comment = e->orig->comment;
   81|      0|        }
   82|    235|        else {
   83|    235|            e->changes->comment = NULL;
   84|    235|        }
   85|    235|        e->changes->changed &= ~ZIP_DIRENT_COMMENT;
  ------------------
  |  |  338|    235|#define ZIP_DIRENT_COMMENT 0x0004u
  ------------------
   86|    235|    }
   87|       |
   88|  2.79k|    if (e->orig && e->orig->comment) {
  ------------------
  |  Branch (88:9): [True: 0, False: 2.79k]
  |  Branch (88:20): [True: 0, False: 0]
  ------------------
   89|      0|        changed = !_zip_string_equal(e->orig->comment, cstr);
   90|      0|    }
   91|  2.79k|    else {
   92|  2.79k|        changed = (cstr != NULL);
   93|  2.79k|    }
   94|       |
   95|  2.79k|    if (changed) {
  ------------------
  |  Branch (95:9): [True: 2.64k, False: 148]
  ------------------
   96|  2.64k|        if (e->changes == NULL) {
  ------------------
  |  Branch (96:13): [True: 0, False: 2.64k]
  ------------------
   97|      0|            if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (97:17): [True: 0, False: 0]
  ------------------
   98|      0|                zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   99|      0|                _zip_string_free(cstr);
  100|      0|                return -1;
  101|      0|            }
  102|      0|        }
  103|  2.64k|        e->changes->comment = cstr;
  104|  2.64k|        e->changes->changed |= ZIP_DIRENT_COMMENT;
  ------------------
  |  |  338|  2.64k|#define ZIP_DIRENT_COMMENT 0x0004u
  ------------------
  105|  2.64k|    }
  106|    148|    else {
  107|    148|        _zip_string_free(cstr);
  108|    148|        if (e->changes && e->changes->changed == 0) {
  ------------------
  |  Branch (108:13): [True: 148, False: 0]
  |  Branch (108:27): [True: 0, False: 148]
  ------------------
  109|      0|            _zip_dirent_free(e->changes);
  110|      0|            e->changes = NULL;
  111|      0|        }
  112|    148|    }
  113|       |
  114|  2.79k|    return 0;
  115|  2.79k|}

zip_file_set_encryption:
   40|  18.2k|ZIP_EXTERN int zip_file_set_encryption(zip_t *za, zip_uint64_t idx, zip_uint16_t method, const char *password) {
   41|  18.2k|    zip_entry_t *e;
   42|  18.2k|    char *our_password = NULL;
   43|       |
   44|  18.2k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (44:9): [True: 0, False: 18.2k]
  ------------------
   45|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|  18.2k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  18.2k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  18.2k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 18.2k]
  |  |  ------------------
  ------------------
   50|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|  18.2k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  18.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  18.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 18.2k]
  |  |  ------------------
  ------------------
   54|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
   55|      0|        return -1;
   56|      0|    }
   57|       |
   58|  18.2k|    if (method != ZIP_EM_NONE && _zip_get_encryption_implementation(method, ZIP_CODEC_ENCODE) == NULL) {
  ------------------
  |  |  207|  36.5k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
                  if (method != ZIP_EM_NONE && _zip_get_encryption_implementation(method, ZIP_CODEC_ENCODE) == NULL) {
  ------------------
  |  |  115|  12.1k|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (58:9): [True: 12.1k, False: 6.09k]
  |  Branch (58:34): [True: 0, False: 12.1k]
  ------------------
   59|      0|        zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|  18.2k|    e = za->entry + idx;
   64|       |
   65|       |
   66|  18.2k|    if (e->changes == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 18.2k]
  ------------------
   67|      0|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (67:13): [True: 0, False: 0]
  ------------------
   68|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   69|      0|            return -1;
   70|      0|        }
   71|      0|    }
   72|       |
   73|  18.2k|    if (password) {
  ------------------
  |  Branch (73:9): [True: 18.2k, False: 0]
  ------------------
   74|  18.2k|        if ((our_password = strdup(password)) == NULL) {
  ------------------
  |  Branch (74:13): [True: 0, False: 18.2k]
  ------------------
   75|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   76|      0|            return -1;
   77|      0|        }
   78|  18.2k|    }
   79|       |
   80|  18.2k|    e->changes->encryption_method = method;
   81|  18.2k|    e->changes->changed |= ZIP_DIRENT_ENCRYPTION_METHOD;
  ------------------
  |  |  342|  18.2k|#define ZIP_DIRENT_ENCRYPTION_METHOD 0x0040u
  ------------------
   82|  18.2k|    if (e->changes->changed & ZIP_DIRENT_PASSWORD) {
  ------------------
  |  |  343|  18.2k|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
  |  Branch (82:9): [True: 3.46k, False: 14.8k]
  ------------------
   83|  3.46k|        _zip_crypto_clear(e->changes->password, strlen(e->changes->password));
  ------------------
  |  |  533|  3.46k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
   84|  3.46k|        free(e->changes->password);
   85|  3.46k|    }
   86|  18.2k|    if (password) {
  ------------------
  |  Branch (86:9): [True: 18.2k, False: 0]
  ------------------
   87|  18.2k|        e->changes->password = our_password;
   88|  18.2k|        e->changes->changed |= ZIP_DIRENT_PASSWORD;
  ------------------
  |  |  343|  18.2k|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
   89|  18.2k|    }
   90|      0|    else {
   91|      0|        e->changes->password = e->orig ? e->orig->password : NULL;
  ------------------
  |  Branch (91:32): [True: 0, False: 0]
  ------------------
   92|      0|        e->changes->changed &= ~ZIP_DIRENT_PASSWORD;
  ------------------
  |  |  343|      0|#define ZIP_DIRENT_PASSWORD 0x0080u
  ------------------
   93|      0|    }
   94|       |
   95|  18.2k|    return 0;
   96|  18.2k|}

zip_file_set_external_attributes:
   36|  6.88k|ZIP_EXTERN int zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_uint8_t opsys, zip_uint32_t attributes) {
   37|  6.88k|    zip_entry_t *e;
   38|  6.88k|    int changed;
   39|  6.88k|    zip_uint8_t unchanged_opsys;
   40|  6.88k|    zip_uint32_t unchanged_attributes;
   41|       |
   42|  6.88k|    if (_zip_get_dirent(za, idx, 0, NULL) == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 6.88k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  6.88k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  6.88k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  6.88k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 6.88k]
  |  |  ------------------
  ------------------
   47|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|  6.88k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  6.88k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  6.88k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 6.88k]
  |  |  ------------------
  ------------------
   51|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
   52|      0|        return -1;
   53|      0|    }
   54|       |
   55|  6.88k|    e = za->entry + idx;
   56|       |
   57|  6.88k|    unchanged_opsys = (e->orig ? (zip_uint8_t)(e->orig->version_madeby >> 8) : (zip_uint8_t)ZIP_OPSYS_DEFAULT);
  ------------------
  |  |  246|  6.88k|#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
  |  |  ------------------
  |  |  |  |  228|  6.88k|#define ZIP_OPSYS_UNIX 0x03u
  |  |  ------------------
  ------------------
  |  Branch (57:24): [True: 0, False: 6.88k]
  ------------------
   58|  6.88k|    unchanged_attributes = e->orig ? e->orig->ext_attrib : ZIP_EXT_ATTRIB_DEFAULT;
  ------------------
  |  |   97|  13.7k|#define ZIP_EXT_ATTRIB_DEFAULT (0100666u << 16)
  ------------------
  |  Branch (58:28): [True: 0, False: 6.88k]
  ------------------
   59|       |
   60|  6.88k|    changed = (opsys != unchanged_opsys || attributes != unchanged_attributes);
  ------------------
  |  Branch (60:16): [True: 0, False: 6.88k]
  |  Branch (60:44): [True: 6.88k, False: 0]
  ------------------
   61|       |
   62|  6.88k|    if (changed) {
  ------------------
  |  Branch (62:9): [True: 6.88k, False: 0]
  ------------------
   63|  6.88k|        if (e->changes == NULL) {
  ------------------
  |  Branch (63:13): [True: 0, False: 6.88k]
  ------------------
   64|      0|            if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (64:17): [True: 0, False: 0]
  ------------------
   65|      0|                zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   66|      0|                return -1;
   67|      0|            }
   68|      0|        }
   69|  6.88k|        e->changes->version_madeby = (zip_uint16_t)((opsys << 8) | (e->changes->version_madeby & 0xff));
   70|  6.88k|        e->changes->ext_attrib = attributes;
   71|  6.88k|        e->changes->changed |= ZIP_DIRENT_ATTRIBUTES;
  ------------------
  |  |  340|  6.88k|#define ZIP_DIRENT_ATTRIBUTES 0x0010u
  ------------------
   72|  6.88k|    }
   73|      0|    else if (e->changes) {
  ------------------
  |  Branch (73:14): [True: 0, False: 0]
  ------------------
   74|      0|        e->changes->changed &= ~ZIP_DIRENT_ATTRIBUTES;
  ------------------
  |  |  340|      0|#define ZIP_DIRENT_ATTRIBUTES 0x0010u
  ------------------
   75|      0|        if (e->changes->changed == 0) {
  ------------------
  |  Branch (75:13): [True: 0, False: 0]
  ------------------
   76|      0|            _zip_dirent_free(e->changes);
   77|      0|            e->changes = NULL;
   78|      0|        }
   79|      0|        else {
   80|      0|            e->changes->version_madeby = (zip_uint16_t)((unchanged_opsys << 8) | (e->changes->version_madeby & 0xff));
   81|      0|            e->changes->ext_attrib = unchanged_attributes;
   82|      0|        }
   83|      0|    }
   84|       |
   85|  6.88k|    return 0;
   86|  6.88k|}

zip_fopen_index:
   38|  18.6k|ZIP_EXTERN zip_file_t *zip_fopen_index(zip_t *za, zip_uint64_t index, zip_flags_t flags) {
   39|  18.6k|    return zip_fopen_index_encrypted(za, index, flags, za->default_password);
   40|  18.6k|}

zip_fopen_index_encrypted:
   43|  18.6k|ZIP_EXTERN zip_file_t *zip_fopen_index_encrypted(zip_t *za, zip_uint64_t index, zip_flags_t flags, const char *password) {
   44|  18.6k|    zip_file_t *zf;
   45|  18.6k|    zip_source_t *src;
   46|       |
   47|  18.6k|    if (password != NULL && password[0] == '\0') {
  ------------------
  |  Branch (47:9): [True: 18.6k, False: 0]
  |  Branch (47:29): [True: 0, False: 18.6k]
  ------------------
   48|      0|        password = NULL;
   49|      0|    }
   50|       |
   51|  18.6k|    if ((src = zip_source_zip_file_create(za, index, flags, 0, -1, password, &za->error)) == NULL) {
  ------------------
  |  Branch (51:9): [True: 0, False: 18.6k]
  ------------------
   52|      0|        return NULL;
   53|      0|    }
   54|       |
   55|  18.6k|    if (zip_source_open(src) < 0) {
  ------------------
  |  Branch (55:9): [True: 0, False: 18.6k]
  ------------------
   56|      0|        zip_error_set_from_source(&za->error, src);
   57|      0|        zip_source_free(src);
   58|      0|        return NULL;
   59|      0|    }
   60|       |
   61|  18.6k|    if ((zf = _zip_file_new(za)) == NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 18.6k]
  ------------------
   62|      0|        zip_source_free(src);
   63|      0|        return NULL;
   64|      0|    }
   65|       |
   66|  18.6k|    zf->src = src;
   67|       |
   68|  18.6k|    return zf;
   69|  18.6k|}
zip_fopen_index_encrypted.c:_zip_file_new:
   72|  18.6k|static zip_file_t *_zip_file_new(zip_t *za) {
   73|  18.6k|    zip_file_t *zf;
   74|       |
   75|  18.6k|    if ((zf = (zip_file_t *)malloc(sizeof(struct zip_file))) == NULL) {
  ------------------
  |  Branch (75:9): [True: 0, False: 18.6k]
  ------------------
   76|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   77|      0|        return NULL;
   78|      0|    }
   79|       |
   80|  18.6k|    zip_error_init(&zf->error);
   81|  18.6k|    zf->src = NULL;
   82|       |
   83|  18.6k|    return zf;
   84|  18.6k|}

zip_fread:
   38|  27.7k|ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread) {
   39|  27.7k|    zip_int64_t n;
   40|       |
   41|  27.7k|    if (zf == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 27.7k]
  ------------------
   42|      0|        return -1;
   43|      0|    }
   44|       |
   45|  27.7k|    if (zf->error.zip_err != 0) {
  ------------------
  |  Branch (45:9): [True: 0, False: 27.7k]
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|  27.7k|    if (toread > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  27.7k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (49:9): [True: 0, False: 27.7k]
  ------------------
   50|      0|        zip_error_set(&zf->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|  27.7k|    if (toread == 0) {
  ------------------
  |  Branch (54:9): [True: 0, False: 27.7k]
  ------------------
   55|      0|        return 0;
   56|      0|    }
   57|       |
   58|  27.7k|    if ((n = zip_source_read(zf->src, outbuf, toread)) < 0) {
  ------------------
  |  Branch (58:9): [True: 0, False: 27.7k]
  ------------------
   59|      0|        zip_error_set_from_source(&zf->error, zf->src);
   60|      0|        return -1;
   61|      0|    }
   62|       |
   63|  27.7k|    return n;
   64|  27.7k|}

_zip_get_encryption_implementation:
   38|  31.6k|zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t em, int operation) {
   39|  31.6k|    switch (em) {
   40|  4.69k|    case ZIP_EM_TRAD_PKWARE:
  ------------------
  |  |  208|  4.69k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (40:5): [True: 4.69k, False: 26.9k]
  ------------------
   41|  4.69k|        return operation == ZIP_CODEC_DECODE ? zip_source_pkware_decode : zip_source_pkware_encode;
  ------------------
  |  |  114|  4.69k|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (41:16): [True: 1.21k, False: 3.48k]
  ------------------
   42|       |
   43|      0|#if defined(HAVE_CRYPTO)
   44|  7.15k|    case ZIP_EM_AES_128:
  ------------------
  |  |  220|  7.15k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
  |  Branch (44:5): [True: 7.15k, False: 24.4k]
  ------------------
   45|  7.15k|    case ZIP_EM_AES_192:
  ------------------
  |  |  221|  7.15k|#define ZIP_EM_AES_192 0x0102
  ------------------
  |  Branch (45:5): [True: 0, False: 31.6k]
  ------------------
   46|  26.9k|    case ZIP_EM_AES_256:
  ------------------
  |  |  222|  26.9k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (46:5): [True: 19.7k, False: 11.8k]
  ------------------
   47|  26.9k|        return operation == ZIP_CODEC_DECODE ? zip_source_winzip_aes_decode : zip_source_winzip_aes_encode;
  ------------------
  |  |  114|  26.9k|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (47:16): [True: 8.31k, False: 18.6k]
  ------------------
   48|      0|#endif
   49|       |
   50|      0|    default:
  ------------------
  |  Branch (50:5): [True: 0, False: 31.6k]
  ------------------
   51|       |        return NULL;
   52|  31.6k|    }
   53|  31.6k|}

zip_get_name:
   40|  40.7k|ZIP_EXTERN const char *zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags) {
   41|  40.7k|    return _zip_get_name(za, idx, flags, &za->error);
   42|  40.7k|}
_zip_get_name:
   45|  41.4k|const char *_zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error) {
   46|  41.4k|    zip_dirent_t *de;
   47|  41.4k|    const zip_uint8_t *str;
   48|       |
   49|  41.4k|    if ((de = _zip_get_dirent(za, idx, flags, error)) == NULL) {
  ------------------
  |  Branch (49:9): [True: 272, False: 41.1k]
  ------------------
   50|    272|        return NULL;
   51|    272|    }
   52|       |
   53|  41.1k|    if ((str = _zip_string_get(de->filename, NULL, flags, error)) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 41.1k]
  ------------------
   54|      0|        return NULL;
   55|      0|    }
   56|       |
   57|  41.1k|    return (const char *)str;
   58|  41.1k|}

zip_get_num_entries:
   38|  9.47k|ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *za, zip_flags_t flags) {
   39|  9.47k|    zip_uint64_t n;
   40|       |
   41|  9.47k|    if (za == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 9.47k]
  ------------------
   42|      0|        return -1;
   43|      0|    }
   44|       |
   45|  9.47k|    if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|  9.47k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (45:9): [True: 0, False: 9.47k]
  ------------------
   46|      0|        n = za->nentry;
   47|      0|        while (n > 0 && za->entry[n - 1].orig == NULL) {
  ------------------
  |  Branch (47:16): [True: 0, False: 0]
  |  Branch (47:25): [True: 0, False: 0]
  ------------------
   48|      0|            --n;
   49|      0|        }
   50|      0|        return (zip_int64_t)n;
   51|      0|    }
   52|  9.47k|    return (zip_int64_t)za->nentry;
   53|  9.47k|}

_zip_hash_new:
  162|  9.77k|zip_hash_t *_zip_hash_new(zip_error_t *error) {
  163|  9.77k|    zip_hash_t *hash;
  164|       |
  165|  9.77k|    if ((hash = (zip_hash_t *)malloc(sizeof(zip_hash_t))) == NULL) {
  ------------------
  |  Branch (165:9): [True: 0, False: 9.77k]
  ------------------
  166|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  167|      0|        return NULL;
  168|      0|    }
  169|       |
  170|  9.77k|    hash->table_size = 0;
  171|  9.77k|    hash->nentries = 0;
  172|  9.77k|    hash->table = NULL;
  173|       |
  174|  9.77k|    return hash;
  175|  9.77k|}
_zip_hash_free:
  178|  9.77k|void _zip_hash_free(zip_hash_t *hash) {
  179|  9.77k|    zip_uint32_t i;
  180|       |
  181|  9.77k|    if (hash == NULL) {
  ------------------
  |  Branch (181:9): [True: 0, False: 9.77k]
  ------------------
  182|      0|        return;
  183|      0|    }
  184|       |
  185|  9.77k|    if (hash->table != NULL) {
  ------------------
  |  Branch (185:9): [True: 7.49k, False: 2.27k]
  ------------------
  186|  1.28M|        for (i = 0; i < hash->table_size; i++) {
  ------------------
  |  Branch (186:21): [True: 1.28M, False: 7.49k]
  ------------------
  187|  1.28M|            if (hash->table[i] != NULL) {
  ------------------
  |  Branch (187:17): [True: 34.3k, False: 1.24M]
  ------------------
  188|  34.3k|                free_list(hash->table[i]);
  189|  34.3k|            }
  190|  1.28M|        }
  191|  7.49k|        free(hash->table);
  192|  7.49k|    }
  193|  9.77k|    free(hash);
  194|  9.77k|}
_zip_hash_add:
  198|  40.7k|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) {
  199|  40.7k|    zip_uint32_t hash_value, table_index;
  200|  40.7k|    zip_hash_entry_t *entry;
  201|       |
  202|  40.7k|    if (hash == NULL || name == NULL || index > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  40.7k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (202:9): [True: 0, False: 40.7k]
  |  Branch (202:25): [True: 0, False: 40.7k]
  |  Branch (202:41): [True: 0, False: 40.7k]
  ------------------
  203|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  204|      0|        return false;
  205|      0|    }
  206|       |
  207|  40.7k|    if (hash->table_size == 0) {
  ------------------
  |  Branch (207:9): [True: 4.86k, False: 35.9k]
  ------------------
  208|  4.86k|        if (!hash_resize(hash, HASH_MIN_SIZE, error)) {
  ------------------
  |  |   47|  4.86k|#define HASH_MIN_SIZE 256
  ------------------
  |  Branch (208:13): [True: 0, False: 4.86k]
  ------------------
  209|      0|            return false;
  210|      0|        }
  211|  4.86k|    }
  212|       |
  213|  40.7k|    hash_value = hash_string(name);
  214|  40.7k|    table_index = hash_value % hash->table_size;
  215|       |
  216|  50.4k|    for (entry = hash->table[table_index]; entry != NULL; entry = entry->next) {
  ------------------
  |  Branch (216:44): [True: 9.66k, False: 40.7k]
  ------------------
  217|  9.66k|        if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
  ------------------
  |  Branch (217:13): [True: 779, False: 8.88k]
  |  Branch (217:48): [True: 0, False: 779]
  ------------------
  218|      0|            if (((flags & ZIP_FL_UNCHANGED) && entry->orig_index != -1) || entry->current_index != -1) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (218:18): [True: 0, False: 0]
  |  Branch (218:48): [True: 0, False: 0]
  |  Branch (218:76): [True: 0, False: 0]
  ------------------
  219|      0|                zip_error_set(error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
  220|      0|                return false;
  221|      0|            }
  222|      0|            else {
  223|      0|                break;
  224|      0|            }
  225|      0|        }
  226|  9.66k|    }
  227|       |
  228|  40.7k|    if (entry == NULL) {
  ------------------
  |  Branch (228:9): [True: 40.7k, False: 0]
  ------------------
  229|  40.7k|        if ((entry = (zip_hash_entry_t *)malloc(sizeof(zip_hash_entry_t))) == NULL) {
  ------------------
  |  Branch (229:13): [True: 0, False: 40.7k]
  ------------------
  230|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  231|      0|            return false;
  232|      0|        }
  233|  40.7k|        entry->name = name;
  234|  40.7k|        entry->next = hash->table[table_index];
  235|  40.7k|        hash->table[table_index] = entry;
  236|  40.7k|        entry->hash_value = hash_value;
  237|  40.7k|        entry->orig_index = -1;
  238|  40.7k|        hash->nentries++;
  239|  40.7k|        if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
  ------------------
  |  |   43|  81.5k|#define HASH_MAX_FILL .75
  ------------------
                      if (hash->nentries > hash->table_size * HASH_MAX_FILL && hash->table_size < HASH_MAX_SIZE) {
  ------------------
  |  |   48|  1.58k|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  |  Branch (239:13): [True: 1.58k, False: 39.1k]
  |  Branch (239:66): [True: 1.58k, False: 0]
  ------------------
  240|  1.58k|            if (!hash_resize(hash, hash->table_size * 2, error)) {
  ------------------
  |  Branch (240:17): [True: 0, False: 1.58k]
  ------------------
  241|      0|                return false;
  242|      0|            }
  243|  1.58k|        }
  244|  40.7k|    }
  245|       |
  246|  40.7k|    if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|  40.7k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (246:9): [True: 18.6k, False: 22.1k]
  ------------------
  247|  18.6k|        entry->orig_index = (zip_int64_t)index;
  248|  18.6k|    }
  249|  40.7k|    entry->current_index = (zip_int64_t)index;
  250|       |
  251|       |    return true;
  252|  40.7k|}
_zip_hash_delete:
  256|    938|bool _zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *name, zip_error_t *error) {
  257|    938|    zip_uint32_t hash_value, index;
  258|    938|    zip_hash_entry_t *entry, *previous;
  259|       |
  260|    938|    if (hash == NULL || name == NULL) {
  ------------------
  |  Branch (260:9): [True: 0, False: 938]
  |  Branch (260:25): [True: 0, False: 938]
  ------------------
  261|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  262|      0|        return false;
  263|      0|    }
  264|       |
  265|    938|    if (hash->nentries > 0) {
  ------------------
  |  Branch (265:9): [True: 938, False: 0]
  ------------------
  266|    938|        hash_value = hash_string(name);
  267|    938|        index = hash_value % hash->table_size;
  268|    938|        previous = NULL;
  269|    938|        entry = hash->table[index];
  270|  1.22k|        while (entry) {
  ------------------
  |  Branch (270:16): [True: 1.22k, False: 0]
  ------------------
  271|  1.22k|            if (entry->hash_value == hash_value && strcmp((const char *)name, (const char *)entry->name) == 0) {
  ------------------
  |  Branch (271:17): [True: 1.07k, False: 145]
  |  Branch (271:52): [True: 938, False: 138]
  ------------------
  272|    938|                if (entry->orig_index == -1) {
  ------------------
  |  Branch (272:21): [True: 938, False: 0]
  ------------------
  273|    938|                    if (previous) {
  ------------------
  |  Branch (273:25): [True: 189, False: 749]
  ------------------
  274|    189|                        previous->next = entry->next;
  275|    189|                    }
  276|    749|                    else {
  277|    749|                        hash->table[index] = entry->next;
  278|    749|                    }
  279|    938|                    free(entry);
  280|    938|                    hash->nentries--;
  281|    938|                    if (hash->nentries < hash->table_size * HASH_MIN_FILL && hash->table_size > HASH_MIN_SIZE) {
  ------------------
  |  |   44|  1.87k|#define HASH_MIN_FILL .01
  ------------------
                                  if (hash->nentries < hash->table_size * HASH_MIN_FILL && hash->table_size > HASH_MIN_SIZE) {
  ------------------
  |  |   47|    488|#define HASH_MIN_SIZE 256
  ------------------
  |  Branch (281:25): [True: 488, False: 450]
  |  Branch (281:78): [True: 0, False: 488]
  ------------------
  282|      0|                        if (!hash_resize(hash, hash->table_size / 2, error)) {
  ------------------
  |  Branch (282:29): [True: 0, False: 0]
  ------------------
  283|      0|                            return false;
  284|      0|                        }
  285|      0|                    }
  286|    938|                }
  287|      0|                else {
  288|      0|                    entry->current_index = -1;
  289|      0|                }
  290|    938|                return true;
  291|    938|            }
  292|    283|            previous = entry;
  293|    283|            entry = entry->next;
  294|    283|        }
  295|    938|    }
  296|       |
  297|      0|    zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|      0|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  298|       |    return false;
  299|    938|}
_zip_hash_lookup:
  303|  44.7k|zip_int64_t _zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error) {
  304|  44.7k|    zip_uint32_t hash_value, index;
  305|  44.7k|    zip_hash_entry_t *entry;
  306|       |
  307|  44.7k|    if (hash == NULL || name == NULL) {
  ------------------
  |  Branch (307:9): [True: 0, False: 44.7k]
  |  Branch (307:25): [True: 0, False: 44.7k]
  ------------------
  308|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|  44.7k|    if (hash->nentries > 0) {
  ------------------
  |  Branch (312:9): [True: 36.7k, False: 8.03k]
  ------------------
  313|  36.7k|        hash_value = hash_string(name);
  314|  36.7k|        index = hash_value % hash->table_size;
  315|  40.5k|        for (entry = hash->table[index]; entry != NULL; entry = entry->next) {
  ------------------
  |  Branch (315:42): [True: 11.6k, False: 28.9k]
  ------------------
  316|  11.6k|            if (strcmp((const char *)name, (const char *)entry->name) == 0) {
  ------------------
  |  Branch (316:17): [True: 7.77k, False: 3.85k]
  ------------------
  317|  7.77k|                if (flags & ZIP_FL_UNCHANGED) {
  ------------------
  |  |   98|  7.77k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (317:21): [True: 0, False: 7.77k]
  ------------------
  318|      0|                    if (entry->orig_index != -1) {
  ------------------
  |  Branch (318:25): [True: 0, False: 0]
  ------------------
  319|      0|                        return entry->orig_index;
  320|      0|                    }
  321|      0|                }
  322|  7.77k|                else {
  323|  7.77k|                    if (entry->current_index != -1) {
  ------------------
  |  Branch (323:25): [True: 7.77k, False: 0]
  ------------------
  324|  7.77k|                        return entry->current_index;
  325|  7.77k|                    }
  326|  7.77k|                }
  327|      0|                break;
  328|  7.77k|            }
  329|  11.6k|        }
  330|  36.7k|    }
  331|       |
  332|  36.9k|    zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|  36.9k|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  333|  36.9k|    return -1;
  334|  44.7k|}
_zip_hash_reserve_capacity:
  337|  2.64k|bool _zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error) {
  338|  2.64k|    zip_uint32_t new_size;
  339|       |
  340|  2.64k|    if (capacity == 0) {
  ------------------
  |  Branch (340:9): [True: 7, False: 2.63k]
  ------------------
  341|      7|        return true;
  342|      7|    }
  343|       |
  344|  2.63k|    new_size = size_for_capacity(capacity);
  345|       |
  346|  2.63k|    if (new_size <= hash->table_size) {
  ------------------
  |  Branch (346:9): [True: 0, False: 2.63k]
  ------------------
  347|      0|        return true;
  348|      0|    }
  349|       |
  350|  2.63k|    if (!hash_resize(hash, new_size, error)) {
  ------------------
  |  Branch (350:9): [True: 0, False: 2.63k]
  ------------------
  351|      0|        return false;
  352|      0|    }
  353|       |
  354|  2.63k|    return true;
  355|  2.63k|}
zip_hash.c:free_list:
   67|  34.3k|static void free_list(zip_hash_entry_t *entry) {
   68|  74.1k|    while (entry != NULL) {
  ------------------
  |  Branch (68:12): [True: 39.8k, False: 34.3k]
  ------------------
   69|  39.8k|        zip_hash_entry_t *next = entry->next;
   70|  39.8k|        free(entry);
   71|  39.8k|        entry = next;
   72|  39.8k|    }
   73|  34.3k|}
zip_hash.c:hash_resize:
   94|  9.08k|static bool hash_resize(zip_hash_t *hash, zip_uint32_t new_size, zip_error_t *error) {
   95|  9.08k|    zip_hash_entry_t **new_table;
   96|       |
   97|  9.08k|    if (new_size == hash->table_size) {
  ------------------
  |  Branch (97:9): [True: 0, False: 9.08k]
  ------------------
   98|      0|        return true;
   99|      0|    }
  100|       |
  101|  9.08k|    if ((new_table = (zip_hash_entry_t **)calloc(new_size, sizeof(zip_hash_entry_t *))) == NULL) {
  ------------------
  |  Branch (101:9): [True: 0, False: 9.08k]
  ------------------
  102|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  103|      0|        return false;
  104|      0|    }
  105|       |
  106|  9.08k|    if (hash->nentries > 0) {
  ------------------
  |  Branch (106:9): [True: 1.58k, False: 7.49k]
  ------------------
  107|  1.58k|        zip_uint32_t i;
  108|       |
  109|  3.50k|        for (i = 0; i < hash->table_size; i++) {
  ------------------
  |  Branch (109:21): [True: 1.91k, False: 1.58k]
  ------------------
  110|  1.91k|            zip_hash_entry_t *entry = hash->table[i];
  111|  3.83k|            while (entry) {
  ------------------
  |  Branch (111:20): [True: 1.91k, False: 1.91k]
  ------------------
  112|  1.91k|                zip_hash_entry_t *next = entry->next;
  113|       |
  114|  1.91k|                zip_uint32_t new_index = entry->hash_value % new_size;
  115|       |
  116|  1.91k|                entry->next = new_table[new_index];
  117|  1.91k|                new_table[new_index] = entry;
  118|       |
  119|  1.91k|                entry = next;
  120|  1.91k|            }
  121|  1.91k|        }
  122|  1.58k|    }
  123|       |
  124|  9.08k|    free(hash->table);
  125|  9.08k|    hash->table = new_table;
  126|  9.08k|    hash->table_size = new_size;
  127|       |
  128|       |    return true;
  129|  9.08k|}
zip_hash.c:hash_string:
   77|  78.4k|static zip_uint32_t hash_string(const zip_uint8_t *name) {
   78|  78.4k|    zip_uint64_t value = HASH_START;
  ------------------
  |  |   40|  78.4k|#define HASH_START 5381
  ------------------
   79|       |
   80|  78.4k|    if (name == NULL) {
  ------------------
  |  Branch (80:9): [True: 0, False: 78.4k]
  ------------------
   81|      0|        return 0;
   82|      0|    }
   83|       |
   84|  2.81M|    while (*name != 0) {
  ------------------
  |  Branch (84:12): [True: 2.73M, False: 78.4k]
  ------------------
   85|  2.73M|        value = (zip_uint64_t)(((value * HASH_MULTIPLIER) + (zip_uint8_t)*name) % 0x100000000ul);
  ------------------
  |  |   39|  2.73M|#define HASH_MULTIPLIER 33
  ------------------
   86|  2.73M|        name++;
   87|  2.73M|    }
   88|       |
   89|  78.4k|    return (zip_uint32_t)value;
   90|  78.4k|}
zip_hash.c:size_for_capacity:
  132|  2.63k|static zip_uint32_t size_for_capacity(zip_uint64_t capacity) {
  133|  2.63k|    double needed_size = capacity / HASH_MAX_FILL;
  ------------------
  |  |   43|  2.63k|#define HASH_MAX_FILL .75
  ------------------
  134|  2.63k|    zip_uint32_t v;
  135|       |
  136|  2.63k|    if (needed_size > ZIP_UINT32_MAX) {
  ------------------
  |  |   42|  2.63k|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  |  Branch (136:9): [True: 0, False: 2.63k]
  ------------------
  137|      0|        v = ZIP_UINT32_MAX;
  ------------------
  |  |   42|      0|#define ZIP_UINT32_MAX	 0xffffffffLU
  ------------------
  138|      0|    }
  139|  2.63k|    else {
  140|  2.63k|        v = (zip_uint32_t)needed_size;
  141|  2.63k|    }
  142|       |
  143|  2.63k|    if (v > HASH_MAX_SIZE) {
  ------------------
  |  |   48|  2.63k|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  |  Branch (143:9): [True: 0, False: 2.63k]
  ------------------
  144|      0|        return HASH_MAX_SIZE;
  ------------------
  |  |   48|      0|#define HASH_MAX_SIZE 0x80000000ul
  ------------------
  145|      0|    }
  146|       |
  147|       |    /* From Bit Twiddling Hacks by Sean Eron Anderson <seander@cs.stanford.edu>
  148|       |     (http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2). */
  149|       |
  150|  2.63k|    v--;
  151|  2.63k|    v |= v >> 1;
  152|  2.63k|    v |= v >> 2;
  153|  2.63k|    v |= v >> 4;
  154|  2.63k|    v |= v >> 8;
  155|  2.63k|    v |= v >> 16;
  156|  2.63k|    v++;
  157|       |
  158|  2.63k|    return v;
  159|  2.63k|}

_zip_read:
   41|  16.1k|int _zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *error) {
   42|  16.1k|    zip_int64_t n;
   43|       |
   44|  16.1k|    if (length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  16.1k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (44:9): [True: 0, False: 16.1k]
  ------------------
   45|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|  16.1k|    if ((n = zip_source_read(src, b, length)) < 0) {
  ------------------
  |  Branch (49:9): [True: 0, False: 16.1k]
  ------------------
   50|      0|        zip_error_set_from_source(error, src);
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|  16.1k|    if (n < (zip_int64_t)length) {
  ------------------
  |  Branch (54:9): [True: 0, False: 16.1k]
  ------------------
   55|      0|        zip_error_set(error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
   56|      0|        return -1;
   57|      0|    }
   58|       |
   59|  16.1k|    return 0;
   60|  16.1k|}
_zip_read_data:
   63|  28.0k|zip_uint8_t *_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error) {
   64|  28.0k|    zip_uint8_t *r;
   65|       |
   66|  28.0k|    if (length == 0 && !nulp) {
  ------------------
  |  Branch (66:9): [True: 0, False: 28.0k]
  |  Branch (66:24): [True: 0, False: 0]
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|  28.0k|    r = (zip_uint8_t *)malloc(length + (nulp ? 1 : 0));
  ------------------
  |  Branch (70:41): [True: 18.6k, False: 9.42k]
  ------------------
   71|  28.0k|    if (r == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 28.0k]
  ------------------
   72|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   73|      0|        return NULL;
   74|      0|    }
   75|       |
   76|  28.0k|    if (buffer) {
  ------------------
  |  Branch (76:9): [True: 28.0k, False: 0]
  ------------------
   77|  28.0k|        zip_uint8_t *data = _zip_buffer_get(buffer, length);
   78|       |
   79|  28.0k|        if (data == NULL) {
  ------------------
  |  Branch (79:13): [True: 0, False: 28.0k]
  ------------------
   80|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   81|      0|            free(r);
   82|      0|            return NULL;
   83|      0|        }
   84|  28.0k|        (void)memcpy_s(r, length, data, length);
  ------------------
  |  |  202|  28.0k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
   85|  28.0k|    }
   86|      0|    else {
   87|      0|        if (_zip_read(src, r, length, error) < 0) {
  ------------------
  |  Branch (87:13): [True: 0, False: 0]
  ------------------
   88|      0|            free(r);
   89|      0|            return NULL;
   90|      0|        }
   91|      0|    }
   92|       |
   93|  28.0k|    if (nulp) {
  ------------------
  |  Branch (93:9): [True: 18.6k, False: 9.42k]
  ------------------
   94|  18.6k|        r[length] = 0;
   95|  18.6k|    }
   96|       |
   97|  28.0k|    return r;
   98|  28.0k|}
_zip_read_string:
  101|  19.0k|zip_string_t *_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t len, bool nulp, zip_error_t *error) {
  102|  19.0k|    zip_uint8_t *raw;
  103|  19.0k|    zip_string_t *s;
  104|       |
  105|  19.0k|    if ((raw = _zip_read_data(buffer, src, len, nulp, error)) == NULL) {
  ------------------
  |  Branch (105:9): [True: 0, False: 19.0k]
  ------------------
  106|      0|        return NULL;
  107|      0|    }
  108|       |
  109|  19.0k|    s = _zip_string_new(raw, len, ZIP_FL_ENC_GUESS, error);
  ------------------
  |  |  101|  19.0k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  110|  19.0k|    free(raw);
  111|  19.0k|    return s;
  112|  19.0k|}
_zip_write:
  115|   203k|int _zip_write(zip_t *za, const void *data, zip_uint64_t length) {
  116|   203k|    zip_int64_t n;
  117|       |
  118|   203k|    if ((n = zip_source_write(za->src, data, length)) < 0) {
  ------------------
  |  Branch (118:9): [True: 0, False: 203k]
  ------------------
  119|      0|        zip_error_set_from_source(&za->error, za->src);
  120|      0|        return -1;
  121|      0|    }
  122|   203k|    if ((zip_uint64_t)n != length) {
  ------------------
  |  Branch (122:9): [True: 0, False: 203k]
  ------------------
  123|      0|        zip_error_set(&za->error, ZIP_ER_WRITE, EINTR);
  ------------------
  |  |  137|      0|#define ZIP_ER_WRITE 6            /* S Write error */
  ------------------
  124|      0|        return -1;
  125|      0|    }
  126|       |
  127|   203k|    if (za->write_crc != NULL) {
  ------------------
  |  Branch (127:9): [True: 0, False: 203k]
  ------------------
  128|      0|        zip_uint64_t position = 0;
  129|      0|        while (position < length) {
  ------------------
  |  Branch (129:16): [True: 0, False: 0]
  ------------------
  130|      0|            zip_uint64_t nn = ZIP_MIN(UINT_MAX, length - position);
  ------------------
  |  |  515|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  131|       |
  132|      0|            *za->write_crc = (zip_uint32_t)crc32(*za->write_crc, (const Bytef *)data + position, (uInt)nn);
  133|      0|            position += nn;
  134|      0|        }
  135|      0|    }
  136|       |
  137|   203k|    return 0;
  138|   203k|}

_zip_memdup:
   40|  36.0k|void *_zip_memdup(const void *mem, size_t len, zip_error_t *error) {
   41|  36.0k|    void *ret;
   42|       |
   43|  36.0k|    if (len == 0) {
  ------------------
  |  Branch (43:9): [True: 0, False: 36.0k]
  ------------------
   44|      0|        return NULL;
   45|      0|    }
   46|       |
   47|  36.0k|    ret = malloc(len);
   48|  36.0k|    if (ret == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 36.0k]
  ------------------
   49|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|       |
   53|  36.0k|    (void)memcpy_s(ret, len, mem, len);
  ------------------
  |  |  202|  36.0k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
   54|       |
   55|  36.0k|    return ret;
   56|  36.0k|}

_zip_name_locate:
   48|  44.7k|zip_int64_t _zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error) {
   49|  44.7k|    int (*cmp)(const char *, const char *);
   50|  44.7k|    size_t fname_length;
   51|  44.7k|    zip_string_t *str = NULL;
   52|  44.7k|    const char *fn, *p;
   53|  44.7k|    zip_uint64_t i;
   54|       |
   55|  44.7k|    if (za == NULL) {
  ------------------
  |  Branch (55:9): [True: 0, False: 44.7k]
  ------------------
   56|      0|        return -1;
   57|      0|    }
   58|       |
   59|  44.7k|    if (fname == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 44.7k]
  ------------------
   60|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|  44.7k|    fname_length = strlen(fname);
   65|       |
   66|  44.7k|    if (fname_length > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  44.7k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (66:9): [True: 0, False: 44.7k]
  ------------------
   67|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   68|      0|        return -1;
   69|      0|    }
   70|       |
   71|  44.7k|    if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
  ------------------
  |  |  107|  44.7k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
                  if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
  ------------------
  |  |  102|  44.7k|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
  |  Branch (71:9): [True: 44.7k, False: 0]
  |  Branch (71:63): [True: 44.7k, False: 0]
  ------------------
   72|  44.7k|        if ((str = _zip_string_new((const zip_uint8_t *)fname, (zip_uint16_t)strlen(fname), flags, error)) == NULL) {
  ------------------
  |  Branch (72:13): [True: 0, False: 44.7k]
  ------------------
   73|      0|            return -1;
   74|      0|        }
   75|  44.7k|        if ((fname = (const char *)_zip_string_get(str, NULL, 0, error)) == NULL) {
  ------------------
  |  Branch (75:13): [True: 0, False: 44.7k]
  ------------------
   76|      0|            _zip_string_free(str);
   77|      0|            return -1;
   78|      0|        }
   79|  44.7k|    }
   80|       |
   81|  44.7k|    if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |   95|  44.7k|#define ZIP_FL_NOCASE 1u     /* ignore case on name lookup */
  ------------------
                  if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |   96|  44.7k|#define ZIP_FL_NODIR 2u      /* ignore directory component */
  ------------------
                  if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |  102|  44.7k|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
                  if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
  ------------------
  |  |  103|  44.7k|#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
  ------------------
  |  Branch (81:9): [True: 0, False: 44.7k]
  ------------------
   82|       |        /* can't use hash table */
   83|      0|        cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
  ------------------
  |  |   95|      0|#define ZIP_FL_NOCASE 1u     /* ignore case on name lookup */
  ------------------
  |  Branch (83:15): [True: 0, False: 0]
  ------------------
   84|       |
   85|      0|        for (i = 0; i < za->nentry; i++) {
  ------------------
  |  Branch (85:21): [True: 0, False: 0]
  ------------------
   86|      0|            fn = _zip_get_name(za, i, flags, error);
   87|       |
   88|       |            /* newly added (partially filled) entry or error */
   89|      0|            if (fn == NULL) {
  ------------------
  |  Branch (89:17): [True: 0, False: 0]
  ------------------
   90|      0|                continue;
   91|      0|            }
   92|       |
   93|      0|            if (flags & ZIP_FL_NODIR) {
  ------------------
  |  |   96|      0|#define ZIP_FL_NODIR 2u      /* ignore directory component */
  ------------------
  |  Branch (93:17): [True: 0, False: 0]
  ------------------
   94|      0|                p = strrchr(fn, '/');
   95|      0|                if (p) {
  ------------------
  |  Branch (95:21): [True: 0, False: 0]
  ------------------
   96|      0|                    fn = p + 1;
   97|      0|                }
   98|      0|            }
   99|       |
  100|      0|            if (cmp(fname, fn) == 0) {
  ------------------
  |  Branch (100:17): [True: 0, False: 0]
  ------------------
  101|      0|                _zip_error_clear(error);
  102|      0|                _zip_string_free(str);
  103|      0|                return (zip_int64_t)i;
  104|      0|            }
  105|      0|        }
  106|       |
  107|      0|        zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|      0|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  108|      0|        _zip_string_free(str);
  109|      0|        return -1;
  110|      0|    }
  111|  44.7k|    else {
  112|  44.7k|        zip_int64_t ret = _zip_hash_lookup(za->names, (const zip_uint8_t *)fname, flags, error);
  113|  44.7k|        _zip_string_free(str);
  114|  44.7k|        return ret;
  115|  44.7k|    }
  116|  44.7k|}

_zip_new:
   44|  9.77k|zip_t *_zip_new(zip_error_t *error) {
   45|  9.77k|    zip_t *za;
   46|       |
   47|  9.77k|    za = (zip_t *)malloc(sizeof(struct zip));
   48|  9.77k|    if (za == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 9.77k]
  ------------------
   49|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|       |
   53|  9.77k|    if ((za->names = _zip_hash_new(error)) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 9.77k]
  ------------------
   54|      0|        free(za);
   55|      0|        return NULL;
   56|      0|    }
   57|       |
   58|  9.77k|    za->src = NULL;
   59|  9.77k|    za->open_flags = 0;
   60|  9.77k|    zip_error_init(&za->error);
   61|  9.77k|    za->flags = za->ch_flags = 0;
   62|  9.77k|    za->default_password = NULL;
   63|  9.77k|    za->comment_orig = za->comment_changes = NULL;
   64|  9.77k|    za->comment_changed = 0;
   65|  9.77k|    za->nentry = za->nentry_alloc = 0;
   66|  9.77k|    za->entry = NULL;
   67|  9.77k|    za->nopen_source = za->nopen_source_alloc = 0;
   68|  9.77k|    za->open_source = NULL;
   69|  9.77k|    za->progress = NULL;
   70|  9.77k|    za->torrent_mtime = 0;
   71|       |
   72|  9.77k|    return za;
   73|  9.77k|}

zip_open_from_source:
   91|  9.97k|ZIP_EXTERN zip_t *zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
   92|  9.97k|    unsigned int flags;
   93|  9.97k|    zip_int64_t supported;
   94|  9.97k|    exists_t exists;
   95|       |
   96|  9.97k|    if (_flags < 0 || src == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 9.97k]
  |  Branch (96:23): [True: 0, False: 9.97k]
  ------------------
   97|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   98|      0|        return NULL;
   99|      0|    }
  100|  9.97k|    flags = (unsigned int)_flags;
  101|       |
  102|  9.97k|    supported = zip_source_supports(src);
  103|  9.97k|    if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
  ------------------
  |  |  289|  9.97k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|  9.97k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
  ------------------
  |  |  289|  9.97k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|  9.97k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  |  Branch (103:9): [True: 0, False: 9.97k]
  ------------------
  104|      0|        zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
  105|      0|        return NULL;
  106|      0|    }
  107|  9.97k|    if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
  ------------------
  |  |  294|  9.97k|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  289|  9.97k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  282|  9.97k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  287|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  290|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  292|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  295|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  301|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
  ------------------
  |  |  294|  9.97k|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  289|  9.97k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  282|  9.97k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  287|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  290|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  292|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  295|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  301|  9.97k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  276|  9.97k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  |  Branch (107:9): [True: 0, False: 9.97k]
  ------------------
  108|      0|        flags |= ZIP_RDONLY;
  ------------------
  |  |   90|      0|#define ZIP_RDONLY 16
  ------------------
  109|      0|    }
  110|       |
  111|  9.97k|    if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   90|  9.97k|#define ZIP_RDONLY 16
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   89|  9.97k|#define ZIP_TRUNCATE 8
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   90|  9.97k|#define ZIP_RDONLY 16
  ------------------
                  if ((flags & (ZIP_RDONLY | ZIP_TRUNCATE)) == (ZIP_RDONLY | ZIP_TRUNCATE)) {
  ------------------
  |  |   89|  9.97k|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (111:9): [True: 0, False: 9.97k]
  ------------------
  112|      0|        zip_error_set(error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
  113|      0|        return NULL;
  114|      0|    }
  115|       |
  116|  9.97k|    exists = _zip_file_exists(src, error);
  117|  9.97k|    switch (exists) {
  118|      0|    case EXISTS_ERROR:
  ------------------
  |  Branch (118:5): [True: 0, False: 9.97k]
  ------------------
  119|      0|        return NULL;
  120|       |
  121|      0|    case EXISTS_NOT:
  ------------------
  |  Branch (121:5): [True: 0, False: 9.97k]
  ------------------
  122|      0|        if ((flags & ZIP_CREATE) == 0) {
  ------------------
  |  |   86|      0|#define ZIP_CREATE 1
  ------------------
  |  Branch (122:13): [True: 0, False: 0]
  ------------------
  123|      0|            zip_error_set(error, ZIP_ER_NOENT, 0);
  ------------------
  |  |  140|      0|#define ZIP_ER_NOENT 9            /* N No such file */
  ------------------
  124|      0|            return NULL;
  125|      0|        }
  126|      0|        return _zip_allocate_new(src, flags, error);
  127|       |
  128|  9.97k|    default: {
  ------------------
  |  Branch (128:5): [True: 9.97k, False: 0]
  ------------------
  129|  9.97k|        zip_t *za;
  130|  9.97k|        if (flags & ZIP_EXCL) {
  ------------------
  |  |   87|  9.97k|#define ZIP_EXCL 2
  ------------------
  |  Branch (130:13): [True: 0, False: 9.97k]
  ------------------
  131|      0|            zip_error_set(error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
  132|      0|            return NULL;
  133|      0|        }
  134|  9.97k|        if (zip_source_open(src) < 0) {
  ------------------
  |  Branch (134:13): [True: 198, False: 9.77k]
  ------------------
  135|    198|            zip_error_set_from_source(error, src);
  136|    198|            return NULL;
  137|    198|        }
  138|       |
  139|  9.77k|        if (flags & ZIP_TRUNCATE) {
  ------------------
  |  |   89|  9.77k|#define ZIP_TRUNCATE 8
  ------------------
  |  Branch (139:13): [True: 4.98k, False: 4.78k]
  ------------------
  140|  4.98k|            za = _zip_allocate_new(src, flags, error);
  141|  4.98k|        }
  142|  4.78k|        else {
  143|       |            /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL, just like open() */
  144|  4.78k|            za = _zip_open(src, flags, error);
  145|  4.78k|        }
  146|       |
  147|  9.77k|        if (za == NULL) {
  ------------------
  |  Branch (147:13): [True: 2.14k, False: 7.62k]
  ------------------
  148|  2.14k|            zip_source_close(src);
  149|  2.14k|            return NULL;
  150|  2.14k|        }
  151|  7.62k|        return za;
  152|  9.77k|    }
  153|  9.97k|    }
  154|  9.97k|}
_zip_open:
  177|  4.78k|zip_t *_zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error) {
  178|  4.78k|    zip_t *za;
  179|  4.78k|    zip_cdir_t *cdir;
  180|  4.78k|    struct zip_stat st;
  181|  4.78k|    zip_uint64_t len, idx;
  182|       |
  183|  4.78k|    zip_stat_init(&st);
  184|  4.78k|    if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (184:9): [True: 0, False: 4.78k]
  ------------------
  185|      0|        zip_error_set_from_source(error, src);
  186|      0|        return NULL;
  187|      0|    }
  188|  4.78k|    if ((st.valid & ZIP_STAT_SIZE) == 0) {
  ------------------
  |  |  325|  4.78k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (188:9): [True: 0, False: 4.78k]
  ------------------
  189|      0|        zip_error_set(error, ZIP_ER_SEEK, EOPNOTSUPP);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  190|      0|        return NULL;
  191|      0|    }
  192|  4.78k|    len = st.size;
  193|       |
  194|       |
  195|  4.78k|    if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
  ------------------
  |  Branch (195:9): [True: 0, False: 4.78k]
  ------------------
  196|      0|        return NULL;
  197|      0|    }
  198|       |
  199|       |    /* treat empty files as empty archives */
  200|  4.78k|    if (len == 0 && zip_source_accept_empty(src)) {
  ------------------
  |  Branch (200:9): [True: 0, False: 4.78k]
  |  Branch (200:21): [True: 0, False: 0]
  ------------------
  201|      0|        return za;
  202|      0|    }
  203|       |
  204|  4.78k|    if ((cdir = _zip_find_central_dir(za, len)) == NULL) {
  ------------------
  |  Branch (204:9): [True: 2.14k, False: 2.64k]
  ------------------
  205|  2.14k|        _zip_error_copy(error, &za->error);
  206|  2.14k|        if (zip_error_code_zip(&za->error) == ZIP_ER_NOZIP) {
  ------------------
  |  |  150|  2.14k|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  |  Branch (206:13): [True: 390, False: 1.75k]
  ------------------
  207|       |            /* not a zip - find out if it's truncated */
  208|    390|            if (_is_truncated_zip(src)) {
  ------------------
  |  Branch (208:17): [True: 390, False: 0]
  ------------------
  209|    390|                zip_error_set(error, ZIP_ER_TRUNCATED_ZIP, 0);
  ------------------
  |  |  166|    390|#define ZIP_ER_TRUNCATED_ZIP 35   /* N Possibly truncated or corrupted zip archive */
  ------------------
  210|    390|            }
  211|    390|        }
  212|       |        /* keep src so discard does not get rid of it */
  213|  2.14k|        zip_source_keep(src);
  214|  2.14k|        zip_discard(za);
  215|  2.14k|        return NULL;
  216|  2.14k|    }
  217|       |
  218|  2.64k|    za->entry = cdir->entry;
  219|  2.64k|    za->nentry = cdir->nentry;
  220|  2.64k|    za->nentry_alloc = cdir->nentry_alloc;
  221|       |
  222|  2.64k|    zip_check_torrentzip(za, cdir);
  223|       |
  224|  2.64k|    if (ZIP_IS_TORRENTZIP(za)) {
  ------------------
  |  |  522|  2.64k|#define ZIP_IS_TORRENTZIP(za) ((za)->flags & ZIP_AFL_IS_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  114|  2.64k|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  |  |  ------------------
  |  |  |  Branch (522:31): [True: 0, False: 2.64k]
  |  |  ------------------
  ------------------
  225|       |        /* Torrentzip uses the archive comment to detect changes by tools that are not torrentzip aware. */
  226|      0|        _zip_string_free(cdir->comment);
  227|      0|    }
  228|  2.64k|    else {
  229|  2.64k|        za->comment_orig = cdir->comment;
  230|  2.64k|    }
  231|       |
  232|  2.64k|    free(cdir);
  233|       |
  234|  2.64k|    _zip_hash_reserve_capacity(za->names, za->nentry, &za->error);
  235|       |
  236|  21.2k|    for (idx = 0; idx < za->nentry; idx++) {
  ------------------
  |  Branch (236:19): [True: 18.6k, False: 2.64k]
  ------------------
  237|  18.6k|        const zip_uint8_t *name = _zip_string_get(za->entry[idx].orig->filename, NULL, 0, error);
  238|  18.6k|        if (name == NULL) {
  ------------------
  |  Branch (238:13): [True: 0, False: 18.6k]
  ------------------
  239|       |            /* keep src so discard does not get rid of it */
  240|      0|            zip_source_keep(src);
  241|      0|            zip_discard(za);
  242|      0|            return NULL;
  243|      0|        }
  244|       |
  245|  18.6k|        if (_zip_hash_add(za->names, name, idx, ZIP_FL_UNCHANGED, &za->error) == false) {
  ------------------
  |  |   98|  18.6k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (245:13): [True: 0, False: 18.6k]
  ------------------
  246|      0|            if (za->error.zip_err != ZIP_ER_EXISTS || (flags & ZIP_CHECKCONS)) {
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
                          if (za->error.zip_err != ZIP_ER_EXISTS || (flags & ZIP_CHECKCONS)) {
  ------------------
  |  |   88|      0|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (246:17): [True: 0, False: 0]
  |  Branch (246:55): [True: 0, False: 0]
  ------------------
  247|      0|                _zip_error_copy(error, &za->error);
  248|       |                /* keep src so discard does not get rid of it */
  249|      0|                zip_source_keep(src);
  250|      0|                zip_discard(za);
  251|      0|                return NULL;
  252|      0|            }
  253|      0|        }
  254|  18.6k|    }
  255|       |
  256|  2.64k|    za->ch_flags = za->flags;
  257|       |
  258|  2.64k|    return za;
  259|  2.64k|}
zip_open.c:_is_truncated_zip:
  157|    390|static bool _is_truncated_zip(zip_source_t *src) {
  158|    390|    unsigned char data[4];
  159|       |    /* check if the source is a truncated zip archive: true if yes, no
  160|       |       if not or can't be determined */
  161|    390|    if (zip_source_seek(src, 0, SEEK_SET) < 0) {
  ------------------
  |  Branch (161:9): [True: 0, False: 390]
  ------------------
  162|      0|        return false;
  163|      0|    }
  164|       |
  165|    390|    if (zip_source_read(src, data, 4) != 4) {
  ------------------
  |  Branch (165:9): [True: 0, False: 390]
  ------------------
  166|      0|        return false;
  167|      0|    }
  168|       |
  169|    390|    if (memcmp(data, LOCAL_MAGIC, 4) == 0) {
  ------------------
  |  |   52|    390|#define LOCAL_MAGIC "PK\3\4"
  ------------------
  |  Branch (169:9): [True: 390, False: 0]
  ------------------
  170|       |        /* file starts with a ZIP local header signature */
  171|    390|        return true;
  172|    390|    }
  173|      0|    return false;
  174|    390|}
zip_open.c:_zip_allocate_new:
  643|  9.77k|static zip_t *_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error) {
  644|  9.77k|    zip_t *za;
  645|       |
  646|  9.77k|    if ((za = _zip_new(error)) == NULL) {
  ------------------
  |  Branch (646:9): [True: 0, False: 9.77k]
  ------------------
  647|      0|        return NULL;
  648|      0|    }
  649|       |
  650|  9.77k|    za->src = src;
  651|  9.77k|    za->open_flags = flags;
  652|  9.77k|    za->flags = 0;
  653|  9.77k|    za->ch_flags = 0;
  654|  9.77k|    za->write_crc = NULL;
  655|       |
  656|  9.77k|    if (flags & ZIP_RDONLY) {
  ------------------
  |  |   90|  9.77k|#define ZIP_RDONLY 16
  ------------------
  |  Branch (656:9): [True: 0, False: 9.77k]
  ------------------
  657|      0|        za->flags |= ZIP_AFL_RDONLY;
  ------------------
  |  |  113|      0|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  ------------------
  658|      0|        za->ch_flags |= ZIP_AFL_RDONLY;
  ------------------
  |  |  113|      0|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  ------------------
  659|      0|    }
  660|       |
  661|  9.77k|    return za;
  662|  9.77k|}
zip_open.c:_zip_file_exists:
  668|  9.97k|static exists_t _zip_file_exists(zip_source_t *src, zip_error_t *error) {
  669|  9.97k|    struct zip_stat st;
  670|       |
  671|  9.97k|    zip_stat_init(&st);
  672|  9.97k|    if (zip_source_stat(src, &st) != 0) {
  ------------------
  |  Branch (672:9): [True: 0, False: 9.97k]
  ------------------
  673|      0|        zip_error_t *src_error = zip_source_error(src);
  674|      0|        if (zip_error_code_zip(src_error) == ZIP_ER_READ && zip_error_code_system(src_error) == ENOENT) {
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
  |  Branch (674:13): [True: 0, False: 0]
  |  Branch (674:61): [True: 0, False: 0]
  ------------------
  675|      0|            return EXISTS_NOT;
  676|      0|        }
  677|      0|        _zip_error_copy(error, src_error);
  678|      0|        return EXISTS_ERROR;
  679|      0|    }
  680|       |
  681|  9.97k|    return EXISTS_OK;
  682|  9.97k|}
zip_open.c:_zip_find_central_dir:
  685|  4.78k|static zip_cdir_t *_zip_find_central_dir(zip_t *za, zip_uint64_t len) {
  686|  4.78k|    zip_cdir_t *cdir;
  687|  4.78k|    const zip_uint8_t *match;
  688|  4.78k|    zip_int64_t buf_offset;
  689|  4.78k|    zip_uint64_t buflen;
  690|  4.78k|    zip_error_t error;
  691|  4.78k|    zip_buffer_t *buffer;
  692|       |
  693|  4.78k|    if (len < EOCDLEN) {
  ------------------
  |  |   62|  4.78k|#define EOCDLEN 22
  ------------------
  |  Branch (693:9): [True: 0, False: 4.78k]
  ------------------
  694|      0|        zip_error_set(&za->error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|      0|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  695|      0|        return NULL;
  696|      0|    }
  697|       |
  698|  4.78k|    buflen = (len < CDBUFSIZE ? len : CDBUFSIZE);
  ------------------
  |  |   65|  4.78k|#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   60|  4.78k|#define MAXCOMLEN 65536
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   62|  4.78k|#define EOCDLEN 22
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   63|  4.78k|#define EOCD64LOCLEN 20
  |  |  ------------------
  ------------------
                  buflen = (len < CDBUFSIZE ? len : CDBUFSIZE);
  ------------------
  |  |   65|    125|#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   60|    125|#define MAXCOMLEN 65536
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   62|    125|#define EOCDLEN 22
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   63|    125|#define EOCD64LOCLEN 20
  |  |  ------------------
  ------------------
  |  Branch (698:15): [True: 4.66k, False: 125]
  ------------------
  699|  4.78k|    if (zip_source_seek(za->src, -(zip_int64_t)buflen, SEEK_END) < 0) {
  ------------------
  |  Branch (699:9): [True: 0, False: 4.78k]
  ------------------
  700|      0|        zip_error_t *src_error = zip_source_error(za->src);
  701|      0|        if (zip_error_code_zip(src_error) != ZIP_ER_SEEK || zip_error_code_system(src_error) != EFBIG) {
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  |  Branch (701:13): [True: 0, False: 0]
  |  Branch (701:61): [True: 0, False: 0]
  ------------------
  702|       |            /* seek before start of file on my machine */
  703|      0|            _zip_error_copy(&za->error, src_error);
  704|      0|            return NULL;
  705|      0|        }
  706|      0|    }
  707|  4.78k|    if ((buf_offset = zip_source_tell(za->src)) < 0) {
  ------------------
  |  Branch (707:9): [True: 0, False: 4.78k]
  ------------------
  708|      0|        zip_error_set_from_source(&za->error, za->src);
  709|      0|        return NULL;
  710|      0|    }
  711|       |
  712|  4.78k|    if ((buffer = _zip_buffer_new_from_source(za->src, buflen, NULL, &za->error)) == NULL) {
  ------------------
  |  Branch (712:9): [True: 0, False: 4.78k]
  ------------------
  713|      0|        return NULL;
  714|      0|    }
  715|       |
  716|  4.78k|    cdir = NULL;
  717|  4.78k|    if (buflen >= CDBUFSIZE) {
  ------------------
  |  |   65|  4.78k|#define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   60|  4.78k|#define MAXCOMLEN 65536
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   62|  4.78k|#define EOCDLEN 22
  |  |  ------------------
  |  |               #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN)
  |  |  ------------------
  |  |  |  |   63|  4.78k|#define EOCD64LOCLEN 20
  |  |  ------------------
  ------------------
  |  Branch (717:9): [True: 125, False: 4.66k]
  ------------------
  718|       |        /* EOCD64 locator is before EOCD, so leave place for it */
  719|    125|        _zip_buffer_set_offset(buffer, EOCD64LOCLEN);
  ------------------
  |  |   63|    125|#define EOCD64LOCLEN 20
  ------------------
  720|    125|    }
  721|  4.78k|    zip_error_set(&error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|  4.78k|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  722|       |
  723|  4.78k|    match = NULL;
  724|  11.6k|    while ((match = find_eocd(buffer, match)) != NULL) {
  ------------------
  |  Branch (724:12): [True: 11.4k, False: 210]
  ------------------
  725|  11.4k|        _zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
  726|  11.4k|        if (_zip_read_cdir(za, buffer, (zip_uint64_t)buf_offset, &cdir, &error)) {
  ------------------
  |  Branch (726:13): [True: 4.57k, False: 6.90k]
  ------------------
  727|  4.57k|            if (cdir != NULL && (za->open_flags & ZIP_CHECKCONS) && _zip_checkcons(za, cdir, &error) < 0) {
  ------------------
  |  |   88|  2.64k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (727:17): [True: 2.64k, False: 1.93k]
  |  Branch (727:33): [True: 0, False: 2.64k]
  |  Branch (727:69): [True: 0, False: 0]
  ------------------
  728|      0|                _zip_cdir_free(cdir);
  729|      0|                cdir = NULL;
  730|      0|            }
  731|  4.57k|            break;
  732|  4.57k|        }
  733|  11.4k|    }
  734|       |
  735|  4.78k|    _zip_buffer_free(buffer);
  736|       |
  737|  4.78k|    if (cdir == NULL) {
  ------------------
  |  Branch (737:9): [True: 2.14k, False: 2.64k]
  ------------------
  738|  2.14k|        _zip_error_copy(&za->error, &error);
  739|  2.14k|    }
  740|  4.78k|    return cdir;
  741|  4.78k|}
zip_open.c:find_eocd:
  744|  11.6k|static const unsigned char *find_eocd(zip_buffer_t *buffer, const unsigned char *last) {
  745|  11.6k|    const unsigned char *data = _zip_buffer_data(buffer);
  746|  11.6k|    const unsigned char *p;
  747|       |
  748|  11.6k|    if (last == NULL) {
  ------------------
  |  Branch (748:9): [True: 4.78k, False: 6.90k]
  ------------------
  749|  4.78k|        if (_zip_buffer_size(buffer) < MAGIC_LEN) {
  ------------------
  |  |   57|  4.78k|#define MAGIC_LEN 4
  ------------------
  |  Branch (749:13): [True: 0, False: 4.78k]
  ------------------
  750|      0|            return NULL;
  751|      0|        }
  752|  4.78k|        last = data + _zip_buffer_size(buffer) - MAGIC_LEN;
  ------------------
  |  |   57|  4.78k|#define MAGIC_LEN 4
  ------------------
  753|  4.78k|    }
  754|  6.90k|    else {
  755|  6.90k|        if (last == _zip_buffer_data(buffer)) {
  ------------------
  |  Branch (755:13): [True: 0, False: 6.90k]
  ------------------
  756|      0|            return NULL;
  757|      0|        }
  758|  6.90k|        last -= 1;
  759|  6.90k|    }
  760|       |
  761|   530k|    for (p = last; p >= data; p -= 1) {
  ------------------
  |  Branch (761:20): [True: 530k, False: 0]
  ------------------
  762|   530k|        if (*p == EOCD_MAGIC[0]) {
  ------------------
  |  |   53|   530k|#define EOCD_MAGIC "PK\5\6"
  ------------------
  |  Branch (762:13): [True: 18.0k, False: 512k]
  ------------------
  763|  18.0k|            if (memcmp(p, EOCD_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   53|  18.0k|#define EOCD_MAGIC "PK\5\6"
  ------------------
                          if (memcmp(p, EOCD_MAGIC, MAGIC_LEN) == 0) {
  ------------------
  |  |   57|  18.0k|#define MAGIC_LEN 4
  ------------------
  |  Branch (763:17): [True: 11.4k, False: 6.62k]
  ------------------
  764|  11.4k|                return p;
  765|  11.4k|            }
  766|  18.0k|        }
  767|   518k|        if (p == data) {
  ------------------
  |  Branch (767:13): [True: 210, False: 518k]
  ------------------
  768|       |            /* Avoid undefined behavior by creating pointer outside buffer */
  769|    210|            break;
  770|    210|        }
  771|   518k|    }
  772|       |
  773|    210|    return NULL;
  774|  11.6k|}
zip_open.c:_zip_read_cdir:
  288|  11.4k|static bool _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_cdir_t **cdirp, zip_error_t *error) {
  289|  11.4k|    zip_cdir_t *cd;
  290|  11.4k|    zip_uint16_t comment_len;
  291|  11.4k|    zip_uint64_t i, left;
  292|  11.4k|    zip_uint64_t eocd_offset = _zip_buffer_offset(buffer);
  293|  11.4k|    zip_buffer_t *cd_buffer;
  294|  11.4k|    bool eocd64_found = false;
  295|       |
  296|  11.4k|    *cdirp = NULL;
  297|       |
  298|  11.4k|    if ((cd = _zip_read_eocd(buffer, buf_offset, error)) == NULL) {
  ------------------
  |  Branch (298:9): [True: 61, False: 11.4k]
  ------------------
  299|     61|        return false;
  300|     61|    }
  301|       |
  302|  11.4k|    if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
  ------------------
  |  |   63|  22.8k|#define EOCD64LOCLEN 20
  ------------------
                  if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
  ------------------
  |  |   63|  11.4k|#define EOCD64LOCLEN 20
  ------------------
                  if (eocd_offset >= EOCD64LOCLEN && memcmp(_zip_buffer_data(buffer) + eocd_offset - EOCD64LOCLEN, EOCD64LOC_MAGIC, 4) == 0) {
  ------------------
  |  |   55|  11.4k|#define EOCD64LOC_MAGIC "PK\6\7"
  ------------------
  |  Branch (302:9): [True: 11.4k, False: 0]
  |  Branch (302:40): [True: 2.63k, False: 8.77k]
  ------------------
  303|  2.63k|        eocd64_found = true;
  304|  2.63k|        _zip_buffer_set_offset(buffer, eocd_offset - EOCD64LOCLEN);
  ------------------
  |  |   63|  2.63k|#define EOCD64LOCLEN 20
  ------------------
  305|  2.63k|        switch (_zip_read_eocd64(cd, za->src, buffer, buf_offset, za->open_flags, error)) {
  ------------------
  |  Branch (305:17): [True: 2.63k, False: 0]
  ------------------
  306|    139|        case CDIR_OK:
  ------------------
  |  Branch (306:9): [True: 139, False: 2.49k]
  ------------------
  307|    139|            break;
  308|       |
  309|    875|        case CDIR_INVALID:
  ------------------
  |  Branch (309:9): [True: 875, False: 1.76k]
  ------------------
  310|    875|            _zip_cdir_free(cd);
  311|    875|            return true;
  312|       |
  313|  1.62k|        case CDIR_NOT_FOUND:
  ------------------
  |  Branch (313:9): [True: 1.62k, False: 1.01k]
  ------------------
  314|  1.62k|            _zip_cdir_free(cd);
  315|  1.62k|            return false;
  316|  2.63k|        }
  317|  2.63k|    }
  318|       |
  319|  8.91k|    if ((cd->eocd_disk != 0 || cd->this_disk != 0) && !eocd64_found && cd->eocd_disk != cd->this_disk) {
  ------------------
  |  Branch (319:10): [True: 3.73k, False: 5.18k]
  |  Branch (319:32): [True: 1.02k, False: 4.16k]
  |  Branch (319:55): [True: 4.71k, False: 38]
  |  Branch (319:72): [True: 4.49k, False: 225]
  ------------------
  320|       |        /* If the central directory doesn't start on this disk, we can't check that offset is valid. Check as much as we can instead. */
  321|  4.49k|        if (cd->this_disk < cd->eocd_disk) {
  ------------------
  |  Branch (321:13): [True: 623, False: 3.86k]
  ------------------
  322|       |            /* Disks before the start of the central directory don't contain an EOCD. */
  323|    623|            _zip_cdir_free(cd);
  324|    623|            return false;
  325|    623|        }
  326|  3.86k|        if (cd->size <= cd->eocd_offset) {
  ------------------
  |  Branch (326:13): [True: 275, False: 3.59k]
  ------------------
  327|       |            /* The complete central directory would fit on this disk. */
  328|    275|            _zip_cdir_free(cd);
  329|    275|            return false;
  330|    275|        }
  331|  3.86k|    }
  332|       |
  333|  8.02k|    if (!eocd64_found) {
  ------------------
  |  Branch (333:9): [True: 7.88k, False: 139]
  ------------------
  334|  7.88k|        if (cd->this_disk == 0 && cd->eocd_disk == 0 && cd->eocd_offset == 0 && cd->offset == 0 && cd->num_entries == 0) {
  ------------------
  |  Branch (334:13): [True: 4.06k, False: 3.81k]
  |  Branch (334:35): [True: 4.06k, False: 0]
  |  Branch (334:57): [True: 0, False: 4.06k]
  |  Branch (334:81): [True: 0, False: 0]
  |  Branch (334:100): [True: 0, False: 0]
  ------------------
  335|       |            /* An empty archive doesn't contain central directory entries. */
  336|      0|        }
  337|  7.88k|        else if (!check_magic(cd->offset, buffer, buf_offset, za->src, CENTRAL_MAGIC)) {
  ------------------
  |  |   51|  7.88k|#define CENTRAL_MAGIC "PK\1\2"
  ------------------
  |  Branch (337:18): [True: 4.31k, False: 3.56k]
  ------------------
  338|  4.31k|            _zip_cdir_free(cd);
  339|  4.31k|            return false;
  340|  4.31k|        }
  341|  7.88k|    }
  342|       |
  343|       |    /* We accept this EOCD as valid and won't search for an earlier one if it is unusable. */
  344|       |
  345|  3.70k|    if (!check_eocd(cd, za->flags, error)) {
  ------------------
  |  Branch (345:9): [True: 83, False: 3.61k]
  ------------------
  346|     83|        _zip_cdir_free(cd);
  347|     83|        return true;
  348|     83|    }
  349|       |
  350|  3.61k|    _zip_buffer_set_offset(buffer, eocd_offset + 20);
  351|  3.61k|    comment_len = _zip_buffer_get_16(buffer);
  352|       |
  353|  3.61k|    if (cd->offset + cd->size > buf_offset + eocd_offset) {
  ------------------
  |  Branch (353:9): [True: 144, False: 3.47k]
  ------------------
  354|       |        /* cdir spans past EOCD record */
  355|    144|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD);
  ------------------
  |  |  152|    144|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD);
  ------------------
  |  |  222|    144|#define ZIP_ER_DETAIL_CDIR_OVERLAPS_EOCD 1                /* G central directory overlaps EOCD, or there is space between them */
  ------------------
  356|    144|        _zip_cdir_free(cd);
  357|    144|        return true;
  358|    144|    }
  359|       |
  360|  3.47k|    if (comment_len || (za->open_flags & ZIP_CHECKCONS)) {
  ------------------
  |  |   88|  2.22k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (360:9): [True: 1.25k, False: 2.22k]
  |  Branch (360:24): [True: 0, False: 2.22k]
  ------------------
  361|  1.25k|        zip_uint64_t tail_len;
  362|       |
  363|  1.25k|        _zip_buffer_set_offset(buffer, eocd_offset + EOCDLEN);
  ------------------
  |  |   62|  1.25k|#define EOCDLEN 22
  ------------------
  364|  1.25k|        tail_len = _zip_buffer_left(buffer);
  365|       |
  366|  1.25k|        if (tail_len != comment_len) {
  ------------------
  |  Branch (366:13): [True: 842, False: 408]
  ------------------
  367|    842|            if (za->open_flags & ZIP_CHECKCONS) {
  ------------------
  |  |   88|    842|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (367:17): [True: 0, False: 842]
  ------------------
  368|      0|                zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID);
  ------------------
  |  |  223|      0|#define ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID 2            /* G archive comment length incorrect */
  ------------------
  369|      0|                _zip_cdir_free(cd);
  370|      0|                return true;
  371|      0|            }
  372|    842|            if (tail_len < comment_len) {
  ------------------
  |  Branch (372:17): [True: 824, False: 18]
  ------------------
  373|    824|                comment_len = tail_len;
  374|    824|            }
  375|    842|        }
  376|       |
  377|  1.25k|        if (comment_len) {
  ------------------
  |  Branch (377:13): [True: 1.22k, False: 26]
  ------------------
  378|  1.22k|            if ((cd->comment = _zip_string_new(_zip_buffer_get(buffer, comment_len), comment_len, ZIP_FL_ENC_GUESS, error)) == NULL) {
  ------------------
  |  |  101|  1.22k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (378:17): [True: 0, False: 1.22k]
  ------------------
  379|      0|                _zip_cdir_free(cd);
  380|      0|                return true;
  381|      0|            }
  382|  1.22k|        }
  383|  1.25k|    }
  384|       |
  385|  3.47k|    if (cd->offset >= buf_offset) {
  ------------------
  |  Branch (385:9): [True: 3.47k, False: 0]
  ------------------
  386|  3.47k|        zip_uint8_t *data;
  387|       |        /* if buffer already read in, use it */
  388|  3.47k|        _zip_buffer_set_offset(buffer, cd->offset - buf_offset);
  389|       |
  390|  3.47k|        if ((data = _zip_buffer_get(buffer, cd->size)) == NULL) {
  ------------------
  |  Branch (390:13): [True: 0, False: 3.47k]
  ------------------
  391|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  224|      0|#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID 3               /* G central directory length invalid */
  ------------------
  392|      0|            _zip_cdir_free(cd);
  393|      0|            return true;
  394|      0|        }
  395|  3.47k|        if ((cd_buffer = _zip_buffer_new(data, cd->size)) == NULL) {
  ------------------
  |  Branch (395:13): [True: 0, False: 3.47k]
  ------------------
  396|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  397|      0|            _zip_cdir_free(cd);
  398|      0|            return true;
  399|      0|        }
  400|  3.47k|    }
  401|      0|    else {
  402|      0|        cd_buffer = NULL;
  403|       |
  404|      0|        if (zip_source_seek(za->src, (zip_int64_t)cd->offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (404:13): [True: 0, False: 0]
  ------------------
  405|      0|            zip_error_set_from_source(error, za->src);
  406|      0|            _zip_cdir_free(cd);
  407|      0|            return true;
  408|      0|        }
  409|       |
  410|       |        /* possible consistency check: cd->offset = len-(cd->size+cd->comment_len+EOCDLEN) ? */
  411|      0|        if (zip_source_tell(za->src) != (zip_int64_t)cd->offset) {
  ------------------
  |  Branch (411:13): [True: 0, False: 0]
  ------------------
  412|      0|            zip_error_set(error, ZIP_ER_NOZIP, 0);
  ------------------
  |  |  150|      0|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  413|      0|            _zip_cdir_free(cd);
  414|      0|            return true;
  415|      0|        }
  416|      0|    }
  417|       |
  418|  3.47k|    if (!_zip_cdir_grow(cd, cd->num_entries, error)) {
  ------------------
  |  Branch (418:9): [True: 0, False: 3.47k]
  ------------------
  419|      0|        _zip_cdir_free(cd);
  420|      0|        _zip_buffer_free(cd_buffer);
  421|      0|        return true;
  422|      0|    }
  423|  3.47k|    left = (zip_uint64_t)cd->size;
  424|  3.47k|    i = 0;
  425|  22.3k|    while (left > 0) {
  ------------------
  |  Branch (425:12): [True: 19.6k, False: 2.69k]
  ------------------
  426|  19.6k|        bool grown = false;
  427|  19.6k|        zip_int64_t entry_size;
  428|       |
  429|  19.6k|        if (i == cd->nentry) {
  ------------------
  |  Branch (429:13): [True: 694, False: 18.9k]
  ------------------
  430|       |            /* InfoZIP has a hack to avoid using Zip64: it stores nentries % 0x10000 */
  431|       |            /* This hack isn't applicable if we're using Zip64, or if there is no central directory entry following. */
  432|       |
  433|    694|            if (cd->is_zip64 || left < CDENTRYSIZE) {
  ------------------
  |  |   58|    691|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (433:17): [True: 3, False: 691]
  |  Branch (433:33): [True: 12, False: 679]
  ------------------
  434|     15|                break;
  435|     15|            }
  436|       |
  437|    679|            if (!_zip_cdir_grow(cd, 0x10000, error)) {
  ------------------
  |  Branch (437:17): [True: 0, False: 679]
  ------------------
  438|      0|                _zip_cdir_free(cd);
  439|      0|                _zip_buffer_free(cd_buffer);
  440|      0|                return true;
  441|      0|            }
  442|    679|            grown = true;
  443|    679|        }
  444|       |
  445|  19.6k|        if ((cd->entry[i].orig = _zip_dirent_new()) == NULL || (entry_size = _zip_dirent_read(cd->entry[i].orig, za->src, cd_buffer, false, cd->is_zip64, 0, za->open_flags & ZIP_CHECKCONS, error)) < 0) {
  ------------------
  |  |   88|  19.6k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (445:13): [True: 0, False: 19.6k]
  |  Branch (445:64): [True: 765, False: 18.8k]
  ------------------
  446|    765|            if (zip_error_code_zip(error) == ZIP_ER_INCONS) {
  ------------------
  |  |  152|    765|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
  |  Branch (446:17): [True: 508, False: 257]
  ------------------
  447|    508|                zip_error_set(error, ZIP_ER_INCONS, ADD_INDEX_TO_DETAIL(zip_error_code_system(error), i));
  ------------------
  |  |  152|    508|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, ADD_INDEX_TO_DETAIL(zip_error_code_system(error), i));
  ------------------
  |  |  218|    508|#define ADD_INDEX_TO_DETAIL(error, index) MAKE_DETAIL_WITH_INDEX(GET_ERROR_FROM_DETAIL(error), (index))
  |  |  ------------------
  |  |  |  |  215|    508|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  |  |  ------------------
  |  |  |  |  |  |  214|    508|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  |  |  ------------------
  |  |  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  |  |  ------------------
  |  |  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (215:48): [True: 0, False: 508]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  448|    508|            }
  449|    257|            else if (grown && zip_error_code_zip(error) == ZIP_ER_NOZIP) {
  ------------------
  |  |  150|     75|#define ZIP_ER_NOZIP 19           /* N Not a zip archive */
  ------------------
  |  Branch (449:22): [True: 75, False: 182]
  |  Branch (449:31): [True: 1, False: 74]
  ------------------
  450|      1|                zip_error_set(error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, i));
  ------------------
  |  |  152|      1|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                              zip_error_set(error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, i));
  ------------------
  |  |  215|      1|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      1|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |  |  Branch (215:48): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  451|      1|            }
  452|    765|            _zip_cdir_free(cd);
  453|    765|            _zip_buffer_free(cd_buffer);
  454|    765|            return true;
  455|    765|        }
  456|  18.8k|        i++;
  457|  18.8k|        left -= (zip_uint64_t)entry_size;
  458|  18.8k|    }
  459|       |
  460|       |    /* If we didn't fill all we grew, cd->num_entries was wrong. */
  461|  2.71k|    if (i != cd->nentry || left > 0) {
  ------------------
  |  Branch (461:9): [True: 55, False: 2.65k]
  |  Branch (461:28): [True: 15, False: 2.64k]
  ------------------
  462|     70|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT);
  ------------------
  |  |  152|     70|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT);
  ------------------
  |  |  226|     70|#define ZIP_ER_DETAIL_CDIR_WRONG_ENTRIES_COUNT 5          /* G central directory count of entries is incorrect */
  ------------------
  463|     70|        _zip_buffer_free(cd_buffer);
  464|     70|        _zip_cdir_free(cd);
  465|     70|        return true;
  466|     70|    }
  467|       |
  468|  2.64k|    if (za->open_flags & ZIP_CHECKCONS) {
  ------------------
  |  |   88|  2.64k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (468:9): [True: 0, False: 2.64k]
  ------------------
  469|      0|        bool ok;
  470|       |
  471|      0|        if (cd_buffer) {
  ------------------
  |  Branch (471:13): [True: 0, False: 0]
  ------------------
  472|      0|            ok = _zip_buffer_eof(cd_buffer);
  473|      0|        }
  474|      0|        else {
  475|      0|            zip_int64_t offset = zip_source_tell(za->src);
  476|       |
  477|      0|            if (offset < 0) {
  ------------------
  |  Branch (477:17): [True: 0, False: 0]
  ------------------
  478|      0|                zip_error_set_from_source(error, za->src);
  479|      0|                _zip_cdir_free(cd);
  480|      0|                return true;
  481|      0|            }
  482|      0|            ok = ((zip_uint64_t)offset == cd->offset + cd->size);
  483|      0|        }
  484|       |
  485|      0|        if (!ok) {
  ------------------
  |  Branch (485:13): [True: 0, False: 0]
  ------------------
  486|      0|            zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  224|      0|#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID 3               /* G central directory length invalid */
  ------------------
  487|      0|            _zip_buffer_free(cd_buffer);
  488|      0|            _zip_cdir_free(cd);
  489|      0|            return true;
  490|      0|        }
  491|      0|    }
  492|       |
  493|  2.64k|    _zip_buffer_free(cd_buffer);
  494|  2.64k|    *cdirp = cd;
  495|       |    return true;
  496|  2.64k|}
zip_open.c:_zip_read_eocd:
  777|  11.4k|static zip_cdir_t *_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error) {
  778|  11.4k|    zip_cdir_t *cd;
  779|       |
  780|  11.4k|    if (_zip_buffer_left(buffer) < EOCDLEN) {
  ------------------
  |  |   62|  11.4k|#define EOCDLEN 22
  ------------------
  |  Branch (780:9): [True: 61, False: 11.4k]
  ------------------
  781|     61|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD_LENGTH_INVALID);
  ------------------
  |  |  152|     61|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD_LENGTH_INVALID);
  ------------------
  |  |  228|     61|#define ZIP_ER_DETAIL_EOCD_LENGTH_INVALID 7               /* G wrong EOCD length */
  ------------------
  782|     61|        return NULL;
  783|     61|    }
  784|       |
  785|  11.4k|    if ((cd = _zip_cdir_new(error)) == NULL) {
  ------------------
  |  Branch (785:9): [True: 0, False: 11.4k]
  ------------------
  786|      0|        return NULL;
  787|      0|    }
  788|       |
  789|  11.4k|    cd->eocd_offset = buf_offset + _zip_buffer_offset(buffer);
  790|       |    /* This function is only called where EOCD magic was found, so no need to check that here. */
  791|  11.4k|    _zip_buffer_skip(buffer, MAGIC_LEN);
  ------------------
  |  |   57|  11.4k|#define MAGIC_LEN 4
  ------------------
  792|  11.4k|    cd->is_zip64 = false;
  793|  11.4k|    cd->this_disk = _zip_buffer_get_16(buffer);
  794|  11.4k|    cd->eocd_disk = _zip_buffer_get_16(buffer);
  795|       |
  796|       |    /* number of cdir-entries on this disk */
  797|  11.4k|    cd->disk_entries = _zip_buffer_get_16(buffer);
  798|       |    /* number of cdir-entries */
  799|  11.4k|    cd->num_entries = _zip_buffer_get_16(buffer);
  800|  11.4k|    cd->size = _zip_buffer_get_32(buffer);
  801|  11.4k|    cd->offset = _zip_buffer_get_32(buffer);
  802|       |
  803|  11.4k|    return cd;
  804|  11.4k|}
zip_open.c:_zip_read_eocd64:
  825|  2.63k|cdir_status_t _zip_read_eocd64(zip_cdir_t *cdir, zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error) {
  826|  2.63k|    zip_uint64_t offset;
  827|  2.63k|    zip_uint8_t eocd[EOCD64LEN];
  828|  2.63k|    zip_uint64_t eocd_offset;
  829|  2.63k|    zip_uint64_t size, nentry, i, eocdloc_offset;
  830|  2.63k|    bool free_buffer;
  831|  2.63k|    zip_uint32_t num_disks, eocd_disk, this_disk;
  832|       |
  833|       |    /* The offset of the end of the buffer is less than ZIP_UINT64_MAX, so this can't overflow. */
  834|  2.63k|    eocdloc_offset = buf_offset + _zip_buffer_offset(buffer);
  835|       |
  836|  2.63k|    _zip_buffer_get(buffer, 4); /* magic already verified */
  837|       |
  838|  2.63k|    eocd_disk = _zip_buffer_get_32(buffer);
  839|  2.63k|    eocd_offset = _zip_buffer_get_64(buffer);
  840|  2.63k|    num_disks = _zip_buffer_get_32(buffer);
  841|       |
  842|  2.63k|    if (!check_magic(eocd_offset, buffer, buf_offset, src, EOCD64_MAGIC)) {
  ------------------
  |  |   56|  2.63k|#define EOCD64_MAGIC "PK\6\6"
  ------------------
  |  Branch (842:9): [True: 1.62k, False: 1.01k]
  ------------------
  843|  1.62k|        return CDIR_NOT_FOUND;
  844|  1.62k|    }
  845|       |
  846|  1.01k|    if (num_disks != 1) {
  ------------------
  |  Branch (846:9): [True: 48, False: 966]
  ------------------
  847|     48|        zip_error_set(error, ZIP_ER_MULTIDISK, 0);
  ------------------
  |  |  132|     48|#define ZIP_ER_MULTIDISK 1        /* N Multi-disk zip archives not supported */
  ------------------
  848|     48|        return CDIR_INVALID;
  849|     48|    }
  850|       |
  851|       |    /* valid seek value for start of EOCD */
  852|    966|    if (eocd_offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|    966|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (852:9): [True: 0, False: 966]
  ------------------
  853|      0|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  854|      0|        return CDIR_INVALID;
  855|      0|    }
  856|       |
  857|       |    /* does EOCD fit before EOCD locator? */
  858|    966|    if (eocd_offset + EOCD64LEN > eocdloc_offset) {
  ------------------
  |  |   64|    966|#define EOCD64LEN 56
  ------------------
  |  Branch (858:9): [True: 8, False: 958]
  ------------------
  859|      8|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  152|      8|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  229|      8|#define ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD 8              /* G EOCD64 overlaps EOCD, or there is space between them */
  ------------------
  860|      8|        return CDIR_INVALID;
  861|      8|    }
  862|       |
  863|       |    /* make sure current position of buffer is beginning of EOCD */
  864|    958|    if (eocd_offset >= buf_offset && eocd_offset + EOCD64LEN <= buf_offset + _zip_buffer_size(buffer)) {
  ------------------
  |  |   64|    958|#define EOCD64LEN 56
  ------------------
  |  Branch (864:9): [True: 958, False: 0]
  |  Branch (864:38): [True: 958, False: 0]
  ------------------
  865|    958|        _zip_buffer_set_offset(buffer, eocd_offset - buf_offset);
  866|    958|        free_buffer = false;
  867|    958|    }
  868|      0|    else {
  869|      0|        if (zip_source_seek(src, (zip_int64_t)eocd_offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (869:13): [True: 0, False: 0]
  ------------------
  870|      0|            zip_error_set_from_source(error, src);
  871|      0|            return CDIR_INVALID;
  872|      0|        }
  873|      0|        if ((buffer = _zip_buffer_new_from_source(src, EOCD64LEN, eocd, error)) == NULL) {
  ------------------
  |  |   64|      0|#define EOCD64LEN 56
  ------------------
  |  Branch (873:13): [True: 0, False: 0]
  ------------------
  874|      0|            return CDIR_INVALID;
  875|      0|        }
  876|      0|        free_buffer = true;
  877|      0|    }
  878|       |
  879|    958|    if (memcmp(_zip_buffer_get(buffer, 4), EOCD64_MAGIC, 4) != 0) {
  ------------------
  |  |   56|    958|#define EOCD64_MAGIC "PK\6\6"
  ------------------
  |  Branch (879:9): [True: 0, False: 958]
  ------------------
  880|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC);
  ------------------
  |  |  230|      0|#define ZIP_ER_DETAIL_EOCD64_WRONG_MAGIC 9                /* G EOCD64 magic incorrect */
  ------------------
  881|      0|        if (free_buffer) {
  ------------------
  |  Branch (881:13): [True: 0, False: 0]
  ------------------
  882|      0|            _zip_buffer_free(buffer);
  883|      0|        }
  884|      0|        return CDIR_INVALID;
  885|      0|    }
  886|       |
  887|       |    /* size of EOCD */
  888|    958|    size = _zip_buffer_get_64(buffer);
  889|       |
  890|       |    /* Is there a hole between EOCD and EOCD locator, or do they overlap? Also check for overflow. */
  891|    958|    if ((flags & ZIP_CHECKCONS) && (ZIP_CHECK_ADD_OVERFLOW(size, eocd_offset + 12) || size + eocd_offset + 12 != eocdloc_offset)) {
  ------------------
  |  |   88|    958|#define ZIP_CHECKCONS 4
  ------------------
                  if ((flags & ZIP_CHECKCONS) && (ZIP_CHECK_ADD_OVERFLOW(size, eocd_offset + 12) || size + eocd_offset + 12 != eocdloc_offset)) {
  ------------------
  |  |  511|      0|#define ZIP_CHECK_ADD_OVERFLOW(a, b) ((a) + (b) < (a))
  |  |  ------------------
  |  |  |  Branch (511:38): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (891:9): [True: 0, False: 958]
  |  Branch (891:87): [True: 0, False: 0]
  ------------------
  892|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD);
  ------------------
  |  |  229|      0|#define ZIP_ER_DETAIL_EOCD64_OVERLAPS_EOCD 8              /* G EOCD64 overlaps EOCD, or there is space between them */
  ------------------
  893|      0|        if (free_buffer) {
  ------------------
  |  Branch (893:13): [True: 0, False: 0]
  ------------------
  894|      0|            _zip_buffer_free(buffer);
  895|      0|        }
  896|      0|        return CDIR_INVALID;
  897|      0|    }
  898|       |
  899|    958|    _zip_buffer_get(buffer, 4); /* skip version made by/needed */
  900|       |
  901|    958|    this_disk = _zip_buffer_get_32(buffer);
  902|    958|    if (_zip_buffer_get_32(buffer) != eocd_disk) {
  ------------------
  |  Branch (902:9): [True: 61, False: 897]
  ------------------
  903|     61|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_LOCATOR_MISMATCH);
  ------------------
  |  |  152|     61|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_LOCATOR_MISMATCH);
  ------------------
  |  |  243|     61|#define ZIP_ER_DETAIL_EOCD64_LOCATOR_MISMATCH 22          /* G EOCD64 and EOCD64 locator do not match */
  ------------------
  904|     61|        if (free_buffer) {
  ------------------
  |  Branch (904:13): [True: 0, False: 61]
  ------------------
  905|      0|            _zip_buffer_free(buffer);
  906|      0|        }
  907|     61|        return CDIR_INVALID;
  908|     61|    }
  909|       |
  910|    897|    i = _zip_buffer_get_64(buffer);
  911|    897|    nentry = _zip_buffer_get_64(buffer);
  912|       |
  913|    897|    if (nentry != i) {
  ------------------
  |  Branch (913:9): [True: 104, False: 793]
  ------------------
  914|    104|        zip_error_set(error, ZIP_ER_MULTIDISK, 0);
  ------------------
  |  |  132|    104|#define ZIP_ER_MULTIDISK 1        /* N Multi-disk zip archives not supported */
  ------------------
  915|    104|        if (free_buffer) {
  ------------------
  |  Branch (915:13): [True: 0, False: 104]
  ------------------
  916|      0|            _zip_buffer_free(buffer);
  917|      0|        }
  918|    104|        return CDIR_INVALID;
  919|    104|    }
  920|       |
  921|    793|    size = _zip_buffer_get_64(buffer);
  922|    793|    offset = _zip_buffer_get_64(buffer);
  923|       |
  924|       |    /* did we read past the end of the buffer? */
  925|    793|    if (!_zip_buffer_ok(buffer)) {
  ------------------
  |  Branch (925:9): [True: 0, False: 793]
  ------------------
  926|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  927|      0|        if (free_buffer) {
  ------------------
  |  Branch (927:13): [True: 0, False: 0]
  ------------------
  928|      0|            _zip_buffer_free(buffer);
  929|      0|        }
  930|      0|        return CDIR_INVALID;
  931|      0|    }
  932|       |
  933|    793|    if (free_buffer) {
  ------------------
  |  Branch (933:9): [True: 0, False: 793]
  ------------------
  934|      0|        _zip_buffer_free(buffer);
  935|      0|    }
  936|       |
  937|    793|    if (offset > ZIP_INT64_MAX || offset + size < offset) {
  ------------------
  |  |   45|  1.58k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (937:9): [True: 67, False: 726]
  |  Branch (937:35): [True: 15, False: 711]
  ------------------
  938|     82|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|     82|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  939|     82|        return CDIR_INVALID;
  940|     82|    }
  941|       |
  942|    711|    if (nentry > size / CDENTRYSIZE) {
  ------------------
  |  |   58|    711|#define CDENTRYSIZE 46u
  ------------------
  |  Branch (942:9): [True: 77, False: 634]
  ------------------
  943|     77|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_INVALID);
  ------------------
  |  |  152|     77|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_INVALID);
  ------------------
  |  |  232|     77|#define ZIP_ER_DETAIL_CDIR_INVALID 11                     /* G invalid value in central directory */
  ------------------
  944|     77|        return CDIR_INVALID;
  945|     77|    }
  946|       |
  947|    634|    if ((cdir->size != 0xffffffff && cdir->size != size) || (cdir->offset != 0xffffffff && cdir->offset != offset) || (cdir->num_entries != 0xffff && cdir->num_entries != nentry) || (cdir->disk_entries != 0xffff && cdir->disk_entries != i) || (cdir->this_disk != 0xffff && cdir->this_disk != this_disk) || (cdir->eocd_disk != 0xffff && cdir->eocd_disk != eocd_disk)) {
  ------------------
  |  Branch (947:10): [True: 332, False: 302]
  |  Branch (947:38): [True: 198, False: 134]
  |  Branch (947:62): [True: 171, False: 265]
  |  Branch (947:92): [True: 128, False: 43]
  |  Branch (947:120): [True: 108, False: 200]
  |  Branch (947:151): [True: 31, False: 77]
  |  Branch (947:184): [True: 92, False: 185]
  |  Branch (947:216): [True: 32, False: 60]
  |  Branch (947:245): [True: 100, False: 145]
  |  Branch (947:274): [True: 64, False: 36]
  |  Branch (947:308): [True: 64, False: 117]
  |  Branch (947:337): [True: 42, False: 22]
  ------------------
  948|    495|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_MISMATCH);
  ------------------
  |  |  152|    495|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EOCD64_MISMATCH);
  ------------------
  |  |  231|    495|#define ZIP_ER_DETAIL_EOCD64_MISMATCH 10                  /* G EOCD64 and EOCD do not match */
  ------------------
  949|    495|        return CDIR_INVALID;
  950|    495|    }
  951|       |
  952|    139|    cdir->is_zip64 = true;
  953|    139|    cdir->size = size;
  954|    139|    cdir->offset = offset;
  955|    139|    cdir->disk_entries = i;
  956|    139|    cdir->num_entries = nentry;
  957|    139|    cdir->this_disk = this_disk;
  958|    139|    cdir->eocd_disk = eocd_disk;
  959|       |
  960|    139|    return CDIR_OK;
  961|    634|}
zip_open.c:check_magic:
  499|  10.5k|static bool check_magic(zip_uint64_t offset, zip_buffer_t *buffer, zip_uint64_t buffer_offset, zip_source_t *src, const char *magic) {
  500|  10.5k|    if (buffer_offset <= offset) {
  ------------------
  |  Branch (500:9): [True: 10.4k, False: 34]
  ------------------
  501|  10.4k|        zip_uint8_t *data;
  502|  10.4k|        if (_zip_buffer_set_offset(buffer, offset - buffer_offset) < 0 || (data = _zip_buffer_get(buffer, MAGIC_LEN)) == NULL) {
  ------------------
  |  |   57|  5.44k|#define MAGIC_LEN 4
  ------------------
  |  Branch (502:13): [True: 5.03k, False: 5.44k]
  |  Branch (502:75): [True: 84, False: 5.36k]
  ------------------
  503|  5.12k|            return false;
  504|  5.12k|        }
  505|  5.36k|        return memcmp(data, magic, MAGIC_LEN) == 0;
  ------------------
  |  |   57|  5.36k|#define MAGIC_LEN 4
  ------------------
  506|  10.4k|    }
  507|     34|    else {
  508|     34|        zip_uint8_t data[MAGIC_LEN];
  509|       |
  510|     34|        if (zip_source_seek(src, offset, SEEK_SET) < 0 || zip_source_read(src, data, MAGIC_LEN) != MAGIC_LEN) {
  ------------------
  |  |   57|     34|#define MAGIC_LEN 4
  ------------------
                      if (zip_source_seek(src, offset, SEEK_SET) < 0 || zip_source_read(src, data, MAGIC_LEN) != MAGIC_LEN) {
  ------------------
  |  |   57|     34|#define MAGIC_LEN 4
  ------------------
  |  Branch (510:13): [True: 0, False: 34]
  |  Branch (510:59): [True: 0, False: 34]
  ------------------
  511|      0|            return false;
  512|      0|        }
  513|     34|        return memcmp(data, magic, MAGIC_LEN) == 0;
  ------------------
  |  |   57|     34|#define MAGIC_LEN 4
  ------------------
  514|     34|    }
  515|  10.5k|}
zip_open.c:check_eocd:
  806|  3.70k|static bool check_eocd(zip_cdir_t *cd, unsigned int flags, zip_error_t *error) {
  807|  3.70k|    if (cd->disk_entries != cd->num_entries || cd->this_disk != 0 || cd->eocd_disk != 0) {
  ------------------
  |  Branch (807:9): [True: 31, False: 3.67k]
  |  Branch (807:48): [True: 51, False: 3.62k]
  |  Branch (807:70): [True: 1, False: 3.61k]
  ------------------
  808|     83|        zip_error_set(error, ZIP_ER_MULTIDISK, 0);
  ------------------
  |  |  132|     83|#define ZIP_ER_MULTIDISK 1        /* N Multi-disk zip archives not supported */
  ------------------
  809|     83|        return false;
  810|     83|    }
  811|       |
  812|  3.61k|    if (cd->offset + cd->size < cd->offset) {
  ------------------
  |  Branch (812:9): [True: 0, False: 3.61k]
  ------------------
  813|      0|        zip_error_set(error, ZIP_ER_SEEK, EFBIG);
  ------------------
  |  |  135|      0|#define ZIP_ER_SEEK 4             /* S Seek error */
  ------------------
  814|      0|        return false;
  815|      0|    }
  816|  3.61k|    if ((flags & ZIP_CHECKCONS) && cd->offset + cd->size != cd->eocd_offset) {
  ------------------
  |  |   88|  3.61k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (816:9): [True: 0, False: 3.61k]
  |  Branch (816:36): [True: 0, False: 0]
  ------------------
  817|      0|        zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                      zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_CDIR_LENGTH_INVALID);
  ------------------
  |  |  224|      0|#define ZIP_ER_DETAIL_CDIR_LENGTH_INVALID 3               /* G central directory length invalid */
  ------------------
  818|      0|        return false;
  819|      0|    }
  820|       |
  821|  3.61k|    return true;
  822|  3.61k|}
zip_open.c:zip_check_torrentzip:
  979|  2.64k|static void zip_check_torrentzip(zip_t *za, const zip_cdir_t *cdir) {
  980|  2.64k|    zip_uint32_t crc_should;
  981|  2.64k|    char buf[8 + 1];
  982|  2.64k|    size_t i;
  983|       |
  984|  2.64k|    if (cdir == NULL) {
  ------------------
  |  Branch (984:9): [True: 0, False: 2.64k]
  ------------------
  985|      0|        return;
  986|      0|    }
  987|       |
  988|  2.64k|    if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   72|  2.64k|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
                  if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   73|  5.28k|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
                  if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   71|    270|#define TORRENTZIP_SIGNATURE "TORRENTZIPPED-"
  ------------------
                  if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH || strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0) {
  ------------------
  |  |   72|    270|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
  |  Branch (988:9): [True: 2.37k, False: 270]
  |  Branch (988:101): [True: 125, False: 145]
  ------------------
  989|  2.49k|        return;
  990|  2.49k|    }
  991|       |
  992|    145|    memcpy(buf, cdir->comment->raw + TORRENTZIP_SIGNATURE_LENGTH, TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   72|    145|#define TORRENTZIP_SIGNATURE_LENGTH 14
  ------------------
                  memcpy(buf, cdir->comment->raw + TORRENTZIP_SIGNATURE_LENGTH, TORRENTZIP_CRC_LENGTH);
  ------------------
  |  |   73|    145|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  993|    145|    buf[TORRENTZIP_CRC_LENGTH] = '\0';
  ------------------
  |  |   73|    145|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  994|    145|    crc_should = 0;
  995|    647|    for (i = 0; i < TORRENTZIP_CRC_LENGTH; i += 2) {
  ------------------
  |  |   73|    647|#define TORRENTZIP_CRC_LENGTH 8
  ------------------
  |  Branch (995:17): [True: 531, False: 116]
  ------------------
  996|    531|        int low, high;
  997|    531|        high = decode_hex((buf[i]));
  998|    531|        low = decode_hex(buf[i + 1]);
  999|    531|        if (high < 0 || low < 0) {
  ------------------
  |  Branch (999:13): [True: 20, False: 511]
  |  Branch (999:25): [True: 9, False: 502]
  ------------------
 1000|     29|            return;
 1001|     29|        }
 1002|    502|        crc_should = (crc_should << 8) + (high << 4) + low;
 1003|    502|    }
 1004|       |
 1005|    116|    {
 1006|    116|        zip_stat_t st;
 1007|    116|        zip_source_t *src_window;
 1008|    116|        zip_source_t *src_crc;
 1009|    116|        zip_uint8_t buffer[512];
 1010|    116|        zip_int64_t ret;
 1011|       |
 1012|    116|        zip_stat_init(&st);
 1013|    116|        st.valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC;
  ------------------
  |  |  325|    116|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      st.valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC;
  ------------------
  |  |  328|    116|#define ZIP_STAT_CRC 0x0020u
  ------------------
 1014|    116|        st.size = cdir->size;
 1015|    116|        st.crc = crc_should;
 1016|    116|        if ((src_window = _zip_source_window_new(za->src, cdir->offset, cdir->size, &st, 0, NULL, NULL, NULL, 0, false, NULL)) == NULL) {
  ------------------
  |  Branch (1016:13): [True: 0, False: 116]
  ------------------
 1017|      0|            return;
 1018|      0|        }
 1019|    116|        if ((src_crc = zip_source_crc_create(src_window, 1, NULL)) == NULL) {
  ------------------
  |  Branch (1019:13): [True: 0, False: 116]
  ------------------
 1020|      0|            zip_source_free(src_window);
 1021|      0|            return;
 1022|      0|        }
 1023|    116|        if (zip_source_open(src_crc) != 0) {
  ------------------
  |  Branch (1023:13): [True: 0, False: 116]
  ------------------
 1024|      0|            zip_source_free(src_crc);
 1025|      0|            return;
 1026|      0|        }
 1027|    505|        while ((ret = zip_source_read(src_crc, buffer, sizeof(buffer))) > 0) {
  ------------------
  |  Branch (1027:16): [True: 389, False: 116]
  ------------------
 1028|    389|        }
 1029|    116|        zip_source_free(src_crc);
 1030|    116|        if (ret < 0) {
  ------------------
  |  Branch (1030:13): [True: 116, False: 0]
  ------------------
 1031|    116|            return;
 1032|    116|        }
 1033|    116|    }
 1034|       |
 1035|       |    /* TODO: if check consistency, check cdir entries for valid values */
 1036|      0|    za->flags |= ZIP_AFL_IS_TORRENTZIP;
  ------------------
  |  |  114|      0|#define ZIP_AFL_IS_TORRENTZIP 4u                          /* current archive is torrentzipped */
  ------------------
 1037|      0|}
zip_open.c:decode_hex:
  964|  1.06k|static int decode_hex(char c) {
  965|  1.06k|    if (c >= '0' && c <= '9') {
  ------------------
  |  Branch (965:9): [True: 1.04k, False: 21]
  |  Branch (965:21): [True: 801, False: 240]
  ------------------
  966|    801|        return c - '0';
  967|    801|    }
  968|    261|    else if (c >= 'A' && c <= 'F') {
  ------------------
  |  Branch (968:14): [True: 235, False: 26]
  |  Branch (968:26): [True: 223, False: 12]
  ------------------
  969|    223|        return c - 'A' + 10;
  970|    223|    }
  971|     38|    else {
  972|     38|        return -1;
  973|     38|    }
  974|  1.06k|}

_zip_pkware_keys_reset:
   61|  2.55k|void _zip_pkware_keys_reset(zip_pkware_keys_t *keys) {
   62|  2.55k|    keys->key[0] = PKWARE_KEY0;
  ------------------
  |  |   40|  2.55k|#define PKWARE_KEY0 305419896
  ------------------
   63|  2.55k|    keys->key[1] = PKWARE_KEY1;
  ------------------
  |  |   41|  2.55k|#define PKWARE_KEY1 591751049
  ------------------
   64|  2.55k|    keys->key[2] = PKWARE_KEY2;
  ------------------
  |  |   42|  2.55k|#define PKWARE_KEY2 878082192
  ------------------
   65|  2.55k|}
_zip_pkware_encrypt:
   68|  4.02k|void _zip_pkware_encrypt(zip_pkware_keys_t *keys, zip_uint8_t *out, const zip_uint8_t *in, zip_uint64_t len) {
   69|  4.02k|    zip_uint64_t i;
   70|  4.02k|    zip_uint8_t b;
   71|  4.02k|    zip_uint8_t tmp;
   72|       |
   73|   760k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (73:17): [True: 756k, False: 4.02k]
  ------------------
   74|   756k|        b = in[i];
   75|       |
   76|   756k|        if (out != NULL) {
  ------------------
  |  Branch (76:13): [True: 748k, False: 8.05k]
  ------------------
   77|   748k|            tmp = crypt_byte(keys);
   78|   748k|            update_keys(keys, b);
   79|   748k|            b ^= tmp;
   80|   748k|            out[i] = b;
   81|   748k|        }
   82|  8.05k|        else {
   83|       |            /* during initialization, we're only interested in key updates */
   84|  8.05k|            update_keys(keys, b);
   85|  8.05k|        }
   86|   756k|    }
   87|  4.02k|}
_zip_pkware_decrypt:
   90|  4.61k|void _zip_pkware_decrypt(zip_pkware_keys_t *keys, zip_uint8_t *out, const zip_uint8_t *in, zip_uint64_t len) {
   91|  4.61k|    zip_uint64_t i;
   92|  4.61k|    zip_uint8_t b;
   93|  4.61k|    zip_uint8_t tmp;
   94|       |
   95|   752k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (95:17): [True: 748k, False: 4.61k]
  ------------------
   96|   748k|        b = in[i];
   97|       |
   98|       |        /* during initialization, we're only interested in key updates */
   99|   748k|        if (out != NULL) {
  ------------------
  |  Branch (99:13): [True: 741k, False: 7.28k]
  ------------------
  100|   741k|            tmp = crypt_byte(keys);
  101|   741k|            b ^= tmp;
  102|   741k|            out[i] = b;
  103|   741k|        }
  104|       |
  105|   748k|        update_keys(keys, b);
  106|   748k|    }
  107|  4.61k|}
zip_pkware.c:crypt_byte:
   53|  1.48M|static zip_uint8_t crypt_byte(zip_pkware_keys_t *keys) {
   54|  1.48M|    zip_uint16_t tmp;
   55|  1.48M|    tmp = (zip_uint16_t)(keys->key[2] | 2);
   56|  1.48M|    tmp = (zip_uint16_t)(((zip_uint32_t)tmp * (tmp ^ 1)) >> 8);
   57|  1.48M|    return (zip_uint8_t)tmp;
   58|  1.48M|}
zip_pkware.c:update_keys:
   45|  1.50M|static void update_keys(zip_pkware_keys_t *keys, zip_uint8_t b) {
   46|  1.50M|    keys->key[0] = (zip_uint32_t)crc32(keys->key[0] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL;
   47|  1.50M|    keys->key[1] = (keys->key[1] + (keys->key[0] & 0xff)) * 134775813 + 1;
   48|  1.50M|    b = (zip_uint8_t)(keys->key[1] >> 24);
   49|  1.50M|    keys->key[2] = (zip_uint32_t)crc32(keys->key[2] ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL;
   50|  1.50M|}

_zip_progress_end:
   67|  4.78k|void _zip_progress_end(zip_progress_t *progress) {
   68|  4.78k|    _zip_progress_update(progress, 1.0);
   69|  4.78k|}
_zip_progress_free:
   72|  9.77k|void _zip_progress_free(zip_progress_t *progress) {
   73|  9.77k|    if (progress == NULL) {
  ------------------
  |  Branch (73:9): [True: 9.77k, False: 0]
  ------------------
   74|  9.77k|        return;
   75|  9.77k|    }
   76|       |
   77|      0|    _zip_progress_free_progress_callback(progress);
   78|      0|    _zip_progress_free_cancel_callback(progress);
   79|       |
   80|      0|    free(progress);
   81|      0|}
_zip_progress_start:
  143|  4.78k|int _zip_progress_start(zip_progress_t *progress) {
  144|  4.78k|    if (progress == NULL) {
  ------------------
  |  Branch (144:9): [True: 4.78k, False: 0]
  ------------------
  145|  4.78k|        return 0;
  146|  4.78k|    }
  147|       |
  148|      0|    if (progress->callback_progress != NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 0]
  ------------------
  149|      0|        progress->last_update = 0.0;
  150|      0|        progress->callback_progress(progress->za, 0.0, progress->ud_progress);
  151|      0|    }
  152|       |
  153|      0|    if (progress->callback_cancel != NULL) {
  ------------------
  |  Branch (153:9): [True: 0, False: 0]
  ------------------
  154|      0|        if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
  ------------------
  |  Branch (154:13): [True: 0, False: 0]
  ------------------
  155|      0|            return -1;
  156|      0|        }
  157|      0|    }
  158|       |
  159|      0|    return 0;
  160|      0|}
_zip_progress_subrange:
  163|  21.2k|int _zip_progress_subrange(zip_progress_t *progress, double start, double end) {
  164|  21.2k|    if (progress == NULL) {
  ------------------
  |  Branch (164:9): [True: 21.2k, False: 0]
  ------------------
  165|  21.2k|        return 0;
  166|  21.2k|    }
  167|       |
  168|      0|    progress->start = start;
  169|      0|    progress->end = end;
  170|       |
  171|      0|    return _zip_progress_update(progress, 0.0);
  172|  21.2k|}
_zip_progress_update:
  174|  4.78k|int _zip_progress_update(zip_progress_t *progress, double sub_current) {
  175|  4.78k|    double current;
  176|       |
  177|  4.78k|    if (progress == NULL) {
  ------------------
  |  Branch (177:9): [True: 4.78k, False: 0]
  ------------------
  178|  4.78k|        return 0;
  179|  4.78k|    }
  180|       |
  181|      0|    if (progress->callback_progress != NULL) {
  ------------------
  |  Branch (181:9): [True: 0, False: 0]
  ------------------
  182|      0|        current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
  ------------------
  |  |  515|      0|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 0]
  |  |  |  Branch (515:25): [True: 0, False: 0]
  |  |  |  Branch (515:37): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  183|       |
  184|      0|        if (current - progress->last_update > progress->precision || (progress->last_update < 1 && current == 1)) {
  ------------------
  |  Branch (184:13): [True: 0, False: 0]
  |  Branch (184:71): [True: 0, False: 0]
  |  Branch (184:100): [True: 0, False: 0]
  ------------------
  185|      0|            progress->callback_progress(progress->za, current, progress->ud_progress);
  186|      0|            progress->last_update = current;
  187|      0|        }
  188|      0|    }
  189|       |
  190|      0|    if (progress->callback_cancel != NULL) {
  ------------------
  |  Branch (190:9): [True: 0, False: 0]
  ------------------
  191|      0|        if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  ------------------
  192|      0|            return -1;
  193|      0|        }
  194|      0|    }
  195|       |
  196|      0|    return 0;
  197|      0|}

zip_realloc:
   38|  57.6k|bool zip_realloc(void **memory, zip_uint64_t *alloced_elements, zip_uint64_t element_size, zip_uint64_t additional_elements, zip_error_t *error) {
   39|  57.6k|    zip_uint64_t new_alloced_elements;
   40|  57.6k|    void *new_memory;
   41|       |
   42|  57.6k|    if (additional_elements == 0) {
  ------------------
  |  Branch (42:9): [True: 0, False: 57.6k]
  ------------------
   43|      0|        return true;
   44|      0|    }
   45|       |
   46|  57.6k|    new_alloced_elements = *alloced_elements + additional_elements;
   47|       |
   48|  57.6k|    if (new_alloced_elements < additional_elements || new_alloced_elements > SIZE_MAX / element_size) {
  ------------------
  |  Branch (48:9): [True: 0, False: 57.6k]
  |  Branch (48:55): [True: 0, False: 57.6k]
  ------------------
   49|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   50|      0|        return false;
   51|      0|    }
   52|       |
   53|  57.6k|    if ((new_memory = realloc(*memory, (size_t)(new_alloced_elements * element_size))) == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 57.6k]
  ------------------
   54|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   55|      0|        return false;
   56|      0|    }
   57|       |
   58|  57.6k|    *memory = new_memory;
   59|  57.6k|    *alloced_elements = new_alloced_elements;
   60|       |
   61|       |    return true;
   62|  57.6k|}

zip_set_archive_comment:
   40|  1.57k|ZIP_EXTERN int zip_set_archive_comment(zip_t *za, const char *comment, zip_uint16_t len) {
   41|  1.57k|    zip_string_t *cstr;
   42|       |
   43|  1.57k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  1.57k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  1.57k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 1.57k]
  |  |  ------------------
  ------------------
   44|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   45|      0|        return -1;
   46|      0|    }
   47|  1.57k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  1.57k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  1.57k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 1.57k]
  |  |  ------------------
  ------------------
   48|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
   49|      0|        return -1;
   50|      0|    }
   51|       |
   52|  1.57k|    if (len > 0 && comment == NULL) {
  ------------------
  |  Branch (52:9): [True: 1.28k, False: 293]
  |  Branch (52:20): [True: 0, False: 1.28k]
  ------------------
   53|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   54|      0|        return -1;
   55|      0|    }
   56|       |
   57|  1.57k|    if (len > 0) {
  ------------------
  |  Branch (57:9): [True: 1.28k, False: 293]
  ------------------
   58|  1.28k|        if ((cstr = _zip_string_new((const zip_uint8_t *)comment, len, ZIP_FL_ENC_GUESS, &za->error)) == NULL) {
  ------------------
  |  |  101|  1.28k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (58:13): [True: 0, False: 1.28k]
  ------------------
   59|      0|            return -1;
   60|      0|        }
   61|       |
   62|  1.28k|        if (_zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_CP437) {
  ------------------
  |  Branch (62:13): [True: 628, False: 655]
  ------------------
   63|    628|            _zip_string_free(cstr);
   64|    628|            zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|    628|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   65|    628|            return -1;
   66|    628|        }
   67|  1.28k|    }
   68|    293|    else {
   69|    293|        cstr = NULL;
   70|    293|    }
   71|       |
   72|    948|    _zip_string_free(za->comment_changes);
   73|    948|    za->comment_changes = NULL;
   74|       |
   75|    948|    if (((za->comment_orig && _zip_string_equal(za->comment_orig, cstr)) || (za->comment_orig == NULL && cstr == NULL))) {
  ------------------
  |  Branch (75:11): [True: 0, False: 948]
  |  Branch (75:31): [True: 0, False: 0]
  |  Branch (75:78): [True: 948, False: 0]
  |  Branch (75:106): [True: 293, False: 655]
  ------------------
   76|    293|        _zip_string_free(cstr);
   77|    293|        za->comment_changed = 0;
   78|    293|    }
   79|    655|    else {
   80|    655|        za->comment_changes = cstr;
   81|    655|        za->comment_changed = 1;
   82|    655|    }
   83|       |
   84|    948|    return 0;
   85|  1.57k|}

zip_set_default_password:
   41|  7.62k|ZIP_EXTERN int zip_set_default_password(zip_t *za, const char *passwd) {
   42|  7.62k|    if (za == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 7.62k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  7.62k|    if (za->default_password != NULL) {
  ------------------
  |  Branch (46:9): [True: 0, False: 7.62k]
  ------------------
   47|      0|        _zip_crypto_clear(za->default_password, strlen(za->default_password));
  ------------------
  |  |  533|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
   48|      0|    }
   49|  7.62k|    free(za->default_password);
   50|       |
   51|  7.62k|    if (passwd && passwd[0] != '\0') {
  ------------------
  |  Branch (51:9): [True: 7.62k, False: 0]
  |  Branch (51:19): [True: 7.62k, False: 0]
  ------------------
   52|  7.62k|        if ((za->default_password = strdup(passwd)) == NULL) {
  ------------------
  |  Branch (52:13): [True: 0, False: 7.62k]
  ------------------
   53|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   54|      0|            return -1;
   55|      0|        }
   56|  7.62k|    }
   57|      0|    else {
   58|      0|        za->default_password = NULL;
   59|      0|    }
   60|       |
   61|  7.62k|    return 0;
   62|  7.62k|}

zip_set_file_compression:
   38|  18.2k|ZIP_EXTERN int zip_set_file_compression(zip_t *za, zip_uint64_t idx, zip_int32_t method, zip_uint32_t flags) {
   39|  18.2k|    zip_entry_t *e;
   40|       |
   41|  18.2k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (41:9): [True: 0, False: 18.2k]
  ------------------
   42|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  18.2k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  18.2k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  18.2k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 18.2k]
  |  |  ------------------
  ------------------
   47|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|  18.2k|    if (ZIP_WANT_TORRENTZIP(za)) {
  ------------------
  |  |  523|  18.2k|#define ZIP_WANT_TORRENTZIP(za) ((za)->ch_flags & ZIP_AFL_WANT_TORRENTZIP)
  |  |  ------------------
  |  |  |  |  115|  18.2k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  |  |  ------------------
  |  |  |  Branch (523:33): [True: 0, False: 18.2k]
  |  |  ------------------
  ------------------
   51|      0|        zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
  ------------------
  |  |  165|      0|#define ZIP_ER_NOT_ALLOWED 34     /* N Not allowed in torrentzip */
  ------------------
   52|      0|        return -1;
   53|      0|    }
   54|       |
   55|  18.2k|    if (!zip_compression_method_supported(method, true)) {
  ------------------
  |  Branch (55:9): [True: 0, False: 18.2k]
  ------------------
   56|      0|        zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0);
  ------------------
  |  |  147|      0|#define ZIP_ER_COMPNOTSUPP 16     /* N Compression method not supported */
  ------------------
   57|      0|        return -1;
   58|      0|    }
   59|       |
   60|  18.2k|    e = za->entry + idx;
   61|       |
   62|       |    /* TODO: do we want to recompress if level is set? Only if it's
   63|       |     * different than what bit flags tell us, but those are not
   64|       |     * defined for all compression methods, or not directly mappable
   65|       |     * to levels */
   66|       |
   67|  18.2k|    if (e->changes == NULL) {
  ------------------
  |  Branch (67:9): [True: 0, False: 18.2k]
  ------------------
   68|      0|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (68:13): [True: 0, False: 0]
  ------------------
   69|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   70|      0|            return -1;
   71|      0|        }
   72|      0|    }
   73|       |
   74|  18.2k|    e->changes->comp_method = method;
   75|  18.2k|    e->changes->compression_level = (zip_uint16_t)flags;
   76|  18.2k|    e->changes->changed |= ZIP_DIRENT_COMP_METHOD;
  ------------------
  |  |  336|  18.2k|#define ZIP_DIRENT_COMP_METHOD 0x0001u
  ------------------
   77|       |
   78|  18.2k|    return 0;
   79|  18.2k|}

_zip_set_name:
   41|  26.4k|int _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags) {
   42|  26.4k|    zip_entry_t *e;
   43|  26.4k|    zip_string_t *str;
   44|  26.4k|    bool same_as_orig;
   45|  26.4k|    zip_int64_t i;
   46|  26.4k|    const zip_uint8_t *old_name, *new_name;
   47|  26.4k|    zip_string_t *old_str;
   48|       |
   49|  26.4k|    if (idx >= za->nentry) {
  ------------------
  |  Branch (49:9): [True: 0, False: 26.4k]
  ------------------
   50|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|  26.4k|    if (ZIP_IS_RDONLY(za)) {
  ------------------
  |  |  521|  26.4k|#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY)
  |  |  ------------------
  |  |  |  |  113|  26.4k|#define ZIP_AFL_RDONLY 2u                                 /* read only -- cannot be cleared */
  |  |  ------------------
  |  |  |  Branch (521:27): [True: 0, False: 26.4k]
  |  |  ------------------
  ------------------
   55|      0|        zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
  ------------------
  |  |  156|      0|#define ZIP_ER_RDONLY 25          /* N Read-only archive */
  ------------------
   56|      0|        return -1;
   57|      0|    }
   58|       |
   59|  26.4k|    if (name && name[0] != '\0') {
  ------------------
  |  Branch (59:9): [True: 26.4k, False: 0]
  |  Branch (59:17): [True: 26.4k, False: 0]
  ------------------
   60|  26.4k|        size_t name_len = strlen(name);
   61|  26.4k|        if (name_len > ZIP_UINT16_MAX) {
  ------------------
  |  |   38|  26.4k|#define ZIP_UINT16_MAX	 0xffff
  ------------------
  |  Branch (61:13): [True: 0, False: 26.4k]
  ------------------
   62|      0|            zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   63|      0|            return -1;
   64|      0|        }
   65|  26.4k|        if ((str = _zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)name_len, flags, &za->error)) == NULL) {
  ------------------
  |  Branch (65:13): [True: 0, False: 26.4k]
  ------------------
   66|      0|            return -1;
   67|      0|        }
   68|  26.4k|        if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) {
  ------------------
  |  |  266|  26.4k|#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  101|  26.4k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  108|  26.4k|#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  107|  26.4k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  |  |  ------------------
  ------------------
                      if ((flags & ZIP_FL_ENCODING_ALL) == ZIP_FL_ENC_GUESS && _zip_guess_encoding(str, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_UTF8_GUESSED) {
  ------------------
  |  |  101|  52.9k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (68:13): [True: 26.4k, False: 0]
  |  Branch (68:66): [True: 265, False: 26.2k]
  ------------------
   69|    265|            str->encoding = ZIP_ENCODING_UTF8_KNOWN;
   70|    265|        }
   71|  26.4k|    }
   72|      0|    else {
   73|      0|        str = NULL;
   74|      0|    }
   75|       |
   76|       |    /* TODO: encoding flags needed for CP437? */
   77|  26.4k|    if ((i = _zip_name_locate(za, name, 0, NULL)) >= 0 && (zip_uint64_t)i != idx) {
  ------------------
  |  Branch (77:9): [True: 4.31k, False: 22.1k]
  |  Branch (77:59): [True: 783, False: 3.53k]
  ------------------
   78|    783|        _zip_string_free(str);
   79|    783|        zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|    783|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
   80|    783|        return -1;
   81|    783|    }
   82|       |
   83|       |    /* no effective name change */
   84|  25.6k|    if (i >= 0 && (zip_uint64_t)i == idx) {
  ------------------
  |  Branch (84:9): [True: 3.53k, False: 22.1k]
  |  Branch (84:19): [True: 3.53k, False: 0]
  ------------------
   85|  3.53k|        _zip_string_free(str);
   86|  3.53k|        return 0;
   87|  3.53k|    }
   88|       |
   89|  22.1k|    e = za->entry + idx;
   90|       |
   91|  22.1k|    if (e->orig) {
  ------------------
  |  Branch (91:9): [True: 0, False: 22.1k]
  ------------------
   92|      0|        same_as_orig = _zip_string_equal(e->orig->filename, str);
   93|      0|    }
   94|  22.1k|    else {
   95|  22.1k|        same_as_orig = false;
   96|  22.1k|    }
   97|       |
   98|  22.1k|    if (!same_as_orig && e->changes == NULL) {
  ------------------
  |  Branch (98:9): [True: 22.1k, False: 0]
  |  Branch (98:26): [True: 21.7k, False: 454]
  ------------------
   99|  21.7k|        if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
  ------------------
  |  Branch (99:13): [True: 0, False: 21.7k]
  ------------------
  100|      0|            zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  101|      0|            _zip_string_free(str);
  102|      0|            return -1;
  103|      0|        }
  104|  21.7k|    }
  105|       |
  106|  22.1k|    if ((new_name = _zip_string_get(same_as_orig ? e->orig->filename : str, NULL, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 22.1k]
  |  Branch (106:37): [True: 0, False: 22.1k]
  ------------------
  107|      0|        _zip_string_free(str);
  108|      0|        return -1;
  109|      0|    }
  110|       |
  111|  22.1k|    if (e->changes) {
  ------------------
  |  Branch (111:9): [True: 22.1k, False: 0]
  ------------------
  112|  22.1k|        old_str = e->changes->filename;
  113|  22.1k|    }
  114|      0|    else if (e->orig) {
  ------------------
  |  Branch (114:14): [True: 0, False: 0]
  ------------------
  115|      0|        old_str = e->orig->filename;
  116|      0|    }
  117|      0|    else {
  118|      0|        old_str = NULL;
  119|      0|    }
  120|       |
  121|  22.1k|    if (old_str) {
  ------------------
  |  Branch (121:9): [True: 454, False: 21.7k]
  ------------------
  122|    454|        if ((old_name = _zip_string_get(old_str, NULL, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (122:13): [True: 0, False: 454]
  ------------------
  123|      0|            _zip_string_free(str);
  124|      0|            return -1;
  125|      0|        }
  126|    454|    }
  127|  21.7k|    else {
  128|  21.7k|        old_name = NULL;
  129|  21.7k|    }
  130|       |
  131|  22.1k|    if (_zip_hash_add(za->names, new_name, idx, 0, &za->error) == false) {
  ------------------
  |  Branch (131:9): [True: 0, False: 22.1k]
  ------------------
  132|      0|        _zip_string_free(str);
  133|      0|        return -1;
  134|      0|    }
  135|  22.1k|    if (old_name) {
  ------------------
  |  Branch (135:9): [True: 454, False: 21.7k]
  ------------------
  136|    454|        _zip_hash_delete(za->names, old_name, NULL);
  137|    454|    }
  138|       |
  139|  22.1k|    if (same_as_orig) {
  ------------------
  |  Branch (139:9): [True: 0, False: 22.1k]
  ------------------
  140|      0|        if (e->changes) {
  ------------------
  |  Branch (140:13): [True: 0, False: 0]
  ------------------
  141|      0|            if (e->changes->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  337|      0|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (141:17): [True: 0, False: 0]
  ------------------
  142|      0|                _zip_string_free(e->changes->filename);
  143|      0|                e->changes->changed &= ~ZIP_DIRENT_FILENAME;
  ------------------
  |  |  337|      0|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  144|      0|                if (e->changes->changed == 0) {
  ------------------
  |  Branch (144:21): [True: 0, False: 0]
  ------------------
  145|      0|                    _zip_dirent_free(e->changes);
  146|      0|                    e->changes = NULL;
  147|      0|                }
  148|      0|                else {
  149|       |                    /* TODO: what if not cloned? can that happen? */
  150|      0|                    e->changes->filename = e->orig->filename;
  151|      0|                }
  152|      0|            }
  153|      0|        }
  154|      0|        _zip_string_free(str);
  155|      0|    }
  156|  22.1k|    else {
  157|  22.1k|        if (e->changes->changed & ZIP_DIRENT_FILENAME) {
  ------------------
  |  |  337|  22.1k|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (157:13): [True: 454, False: 21.7k]
  ------------------
  158|    454|            _zip_string_free(e->changes->filename);
  159|    454|        }
  160|  22.1k|        e->changes->changed |= ZIP_DIRENT_FILENAME;
  ------------------
  |  |  337|  22.1k|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  161|  22.1k|        e->changes->filename = str;
  162|  22.1k|    }
  163|       |
  164|  22.1k|    return 0;
  165|  22.1k|}

zip_source_at_eof:
    3|  31.6k|ZIP_EXTERN int zip_source_at_eof(zip_source_t *src) {
    4|  31.6k|    zip_uint8_t d[1];
    5|  31.6k|    zip_int64_t n;
    6|       |
    7|  31.6k|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  31.6k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (7:9): [True: 0, False: 31.6k]
  ------------------
    8|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
    9|      0|        return -1;
   10|      0|    }
   11|       |
   12|  31.6k|    if (!src->eof) {
  ------------------
  |  Branch (12:9): [True: 0, False: 31.6k]
  ------------------
   13|      0|        if (src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_AT_EOF)) {
  ------------------
  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (13:13): [True: 0, False: 0]
  ------------------
   14|      0|            n = _zip_source_call(src, NULL, 0, ZIP_SOURCE_AT_EOF);
   15|      0|            if (n < 0) {
  ------------------
  |  Branch (15:17): [True: 0, False: 0]
  ------------------
   16|      0|                return -1;
   17|      0|            }
   18|      0|            if (n != 0) {
  ------------------
  |  Branch (18:17): [True: 0, False: 0]
  ------------------
   19|      0|                src->eof = true;
   20|      0|            }
   21|      0|        }
   22|      0|        else {
   23|      0|            n = zip_source_read(src, d, sizeof(d));
   24|      0|            if (n < 0) {
  ------------------
  |  Branch (24:17): [True: 0, False: 0]
  ------------------
   25|      0|                return -1;
   26|      0|            }
   27|      0|            if (n > 0) {
  ------------------
  |  Branch (27:17): [True: 0, False: 0]
  ------------------
   28|      0|                if (src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) {
  ------------------
  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (28:21): [True: 0, False: 0]
  ------------------
   29|      0|                    if (zip_source_seek(src, -1, SEEK_CUR) < 0) {
  ------------------
  |  Branch (29:25): [True: 0, False: 0]
  ------------------
   30|      0|                        return -1;
   31|      0|                    }
   32|      0|                }
   33|      0|                else {
   34|      0|                    src->have_next_byte = true;
   35|      0|                    src->next_byte = d[0];
   36|      0|                    src->bytes_read -= 1;
   37|      0|                }
   38|      0|            }
   39|      0|        }
   40|      0|    }
   41|       |
   42|  31.6k|    return src->eof ? 1 : 0;
  ------------------
  |  Branch (42:12): [True: 31.6k, False: 0]
  ------------------
   43|  31.6k|}

zip_source_begin_write:
   38|  4.78k|ZIP_EXTERN int zip_source_begin_write(zip_source_t *src) {
   39|  4.78k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|  4.78k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|  4.78k|    if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  442|  4.78k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  |  |  ------------------
  |  |  |  Branch (442:41): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
   45|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|  4.78k|    if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_BEGIN_WRITE) < 0) {
  ------------------
  |  Branch (49:9): [True: 0, False: 4.78k]
  ------------------
   50|      0|        return -1;
   51|      0|    }
   52|       |
   53|  4.78k|    src->write_state = ZIP_SOURCE_WRITE_OPEN;
   54|       |    /* Clear past error. Otherwise the error from zip_source_begin_write_cloning() will persist and be reported on zip_source_close(). */
   55|  4.78k|    zip_error_set(&src->error, ZIP_ER_OK, 0);
  ------------------
  |  |  131|  4.78k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
   56|       |
   57|  4.78k|    return 0;
   58|  4.78k|}

zip_source_buffer:
   88|  25.9k|ZIP_EXTERN zip_source_t *zip_source_buffer(zip_t *za, const void *data, zip_uint64_t len, int freep) {
   89|  25.9k|    if (za == NULL) {
  ------------------
  |  Branch (89:9): [True: 0, False: 25.9k]
  ------------------
   90|      0|        return NULL;
   91|      0|    }
   92|       |
   93|  25.9k|    return zip_source_buffer_with_attributes_create(data, len, freep, NULL, &za->error);
   94|  25.9k|}
zip_source_buffer_create:
   97|  4.98k|ZIP_EXTERN zip_source_t *zip_source_buffer_create(const void *data, zip_uint64_t len, int freep, zip_error_t *error) {
   98|       |    return zip_source_buffer_with_attributes_create(data, len, freep, NULL, error);
   99|  4.98k|}
zip_source_buffer_with_attributes_create:
  102|  38.1k|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) {
  103|  38.1k|    zip_buffer_fragment_t fragment;
  104|       |
  105|  38.1k|    if (data == NULL) {
  ------------------
  |  Branch (105:9): [True: 19.8k, False: 18.2k]
  ------------------
  106|  19.8k|        if (len > 0) {
  ------------------
  |  Branch (106:13): [True: 0, False: 19.8k]
  ------------------
  107|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  108|      0|            return NULL;
  109|      0|        }
  110|       |
  111|  19.8k|        return zip_source_buffer_fragment_with_attributes_create(NULL, 0, freep, attributes, error);
  112|  19.8k|    }
  113|       |
  114|  18.2k|    fragment.data = (zip_uint8_t *)data;
  115|  18.2k|    fragment.length = len;
  116|       |
  117|  18.2k|    return zip_source_buffer_fragment_with_attributes_create(&fragment, 1, freep, attributes, error);
  118|  38.1k|}
zip_source_buffer_fragment_with_attributes_create:
  134|  38.1k|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) {
  135|  38.1k|    struct read_data *ctx;
  136|  38.1k|    zip_source_t *zs;
  137|  38.1k|    buffer_t *buffer;
  138|       |
  139|  38.1k|    if (fragments == NULL && nfragments > 0) {
  ------------------
  |  Branch (139:9): [True: 19.8k, False: 18.2k]
  |  Branch (139:30): [True: 0, False: 19.8k]
  ------------------
  140|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|       |
  144|  38.1k|    if ((buffer = buffer_new(fragments, nfragments, freep, error)) == NULL) {
  ------------------
  |  Branch (144:9): [True: 0, False: 38.1k]
  ------------------
  145|      0|        return NULL;
  146|      0|    }
  147|       |
  148|  38.1k|    if ((ctx = (struct read_data *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 38.1k]
  ------------------
  149|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  150|      0|        buffer_free(buffer);
  151|      0|        return NULL;
  152|      0|    }
  153|       |
  154|  38.1k|    ctx->in = buffer;
  155|  38.1k|    ctx->out = NULL;
  156|  38.1k|    ctx->mtime = time(NULL);
  157|  38.1k|    if (attributes) {
  ------------------
  |  Branch (157:9): [True: 7.22k, False: 30.9k]
  ------------------
  158|  7.22k|        (void)memcpy_s(&ctx->attributes, sizeof(ctx->attributes), attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|  7.22k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  159|  7.22k|    }
  160|  30.9k|    else {
  161|  30.9k|        zip_file_attributes_init(&ctx->attributes);
  162|  30.9k|    }
  163|  38.1k|    zip_error_init(&ctx->error);
  164|       |
  165|  38.1k|    if ((zs = zip_source_function_create(read_data, ctx, error)) == NULL) {
  ------------------
  |  Branch (165:9): [True: 0, False: 38.1k]
  ------------------
  166|      0|        buffer_free(ctx->in);
  167|      0|        free(ctx);
  168|      0|        return NULL;
  169|      0|    }
  170|       |
  171|  38.1k|    return zs;
  172|  38.1k|}
zip_source_buffer.c:read_data:
  179|   799k|static zip_int64_t read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  180|   799k|    struct read_data *ctx = (struct read_data *)state;
  181|       |
  182|   799k|    switch (cmd) {
  183|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (183:5): [True: 0, False: 799k]
  ------------------
  184|      0|        return buffer_at_eof(ctx->in);
  185|       |
  186|  4.78k|    case ZIP_SOURCE_BEGIN_WRITE:
  ------------------
  |  Branch (186:5): [True: 4.78k, False: 795k]
  ------------------
  187|  4.78k|        if ((ctx->out = buffer_new(NULL, 0, 0, &ctx->error)) == NULL) {
  ------------------
  |  Branch (187:13): [True: 0, False: 4.78k]
  ------------------
  188|      0|            return -1;
  189|      0|        }
  190|  4.78k|        ctx->out->offset = 0;
  191|  4.78k|        ctx->out->current_fragment = 0;
  192|  4.78k|        return 0;
  193|       |
  194|      0|    case ZIP_SOURCE_BEGIN_WRITE_CLONING:
  ------------------
  |  Branch (194:5): [True: 0, False: 799k]
  ------------------
  195|      0|        if ((ctx->out = buffer_clone(ctx->in, len, &ctx->error)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 0, False: 0]
  ------------------
  196|      0|            return -1;
  197|      0|        }
  198|      0|        ctx->out->offset = len;
  199|      0|        ctx->out->current_fragment = ctx->out->nfragments;
  200|      0|        return 0;
  201|       |
  202|  38.2k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (202:5): [True: 38.2k, False: 761k]
  ------------------
  203|  38.2k|        return 0;
  204|       |
  205|  4.78k|    case ZIP_SOURCE_COMMIT_WRITE:
  ------------------
  |  Branch (205:5): [True: 4.78k, False: 795k]
  ------------------
  206|  4.78k|        buffer_free(ctx->in);
  207|  4.78k|        ctx->in = ctx->out;
  208|  4.78k|        ctx->out = NULL;
  209|  4.78k|        return 0;
  210|       |
  211|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (211:5): [True: 0, False: 799k]
  ------------------
  212|      0|        return zip_error_to_data(&ctx->error, data, len);
  213|       |
  214|  38.1k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (214:5): [True: 38.1k, False: 761k]
  ------------------
  215|  38.1k|        buffer_free(ctx->in);
  216|  38.1k|        buffer_free(ctx->out);
  217|  38.1k|        free(ctx);
  218|  38.1k|        return 0;
  219|       |
  220|  56.9k|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (220:5): [True: 56.9k, False: 742k]
  ------------------
  221|  56.9k|        if (len < sizeof(ctx->attributes)) {
  ------------------
  |  Branch (221:13): [True: 0, False: 56.9k]
  ------------------
  222|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  223|      0|            return -1;
  224|      0|        }
  225|       |
  226|  56.9k|        (void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|  56.9k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  227|       |
  228|  56.9k|        return sizeof(ctx->attributes);
  229|  56.9k|    }
  230|       |
  231|  38.2k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (231:5): [True: 38.2k, False: 761k]
  ------------------
  232|  38.2k|        ctx->in->offset = 0;
  233|  38.2k|        ctx->in->current_fragment = 0;
  234|  38.2k|        return 0;
  235|       |
  236|  77.4k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (236:5): [True: 77.4k, False: 722k]
  ------------------
  237|  77.4k|        if (len > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  77.4k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (237:13): [True: 0, False: 77.4k]
  ------------------
  238|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  239|      0|            return -1;
  240|      0|        }
  241|  77.4k|        return buffer_read(ctx->in, data, len);
  242|       |
  243|    198|    case ZIP_SOURCE_REMOVE: {
  ------------------
  |  Branch (243:5): [True: 198, False: 799k]
  ------------------
  244|    198|        buffer_t *empty = buffer_new(NULL, 0, 0, &ctx->error);
  245|    198|        if (empty == NULL) {
  ------------------
  |  Branch (245:13): [True: 0, False: 198]
  ------------------
  246|      0|            return -1;
  247|      0|        }
  248|       |
  249|    198|        buffer_free(ctx->in);
  250|    198|        ctx->in = empty;
  251|    198|        return 0;
  252|    198|    }
  253|       |
  254|      0|    case ZIP_SOURCE_ROLLBACK_WRITE:
  ------------------
  |  Branch (254:5): [True: 0, False: 799k]
  ------------------
  255|      0|        buffer_free(ctx->out);
  256|      0|        ctx->out = NULL;
  257|      0|        return 0;
  258|       |
  259|  45.0k|    case ZIP_SOURCE_SEEK:
  ------------------
  |  Branch (259:5): [True: 45.0k, False: 754k]
  ------------------
  260|  45.0k|        return buffer_seek(ctx->in, data, len, &ctx->error);
  261|       |
  262|  40.6k|    case ZIP_SOURCE_SEEK_WRITE:
  ------------------
  |  Branch (262:5): [True: 40.6k, False: 759k]
  ------------------
  263|  40.6k|        return buffer_seek(ctx->out, data, len, &ctx->error);
  264|       |
  265|   104k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (265:5): [True: 104k, False: 695k]
  ------------------
  266|   104k|        zip_stat_t *st;
  267|       |
  268|   104k|        if (len < sizeof(*st)) {
  ------------------
  |  Branch (268:13): [True: 0, False: 104k]
  ------------------
  269|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  270|      0|            return -1;
  271|      0|        }
  272|       |
  273|   104k|        st = (zip_stat_t *)data;
  274|       |
  275|   104k|        zip_stat_init(st);
  276|   104k|        st->mtime = ctx->mtime;
  277|   104k|        st->size = ctx->in->size;
  278|   104k|        st->comp_size = st->size;
  279|   104k|        st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|   104k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  280|   104k|        st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|   104k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  281|   104k|        st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  327|   104k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  325|   104k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|   104k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|   104k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      st->valid = ZIP_STAT_MTIME | ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|   104k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  282|       |
  283|   104k|        return sizeof(*st);
  284|   104k|    }
  285|       |
  286|  38.1k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (286:5): [True: 38.1k, False: 761k]
  ------------------
  287|  38.1k|        return zip_source_make_command_bitmap(ZIP_SOURCE_AT_EOF, ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_BEGIN_WRITE_CLONING, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  288|       |
  289|  4.78k|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (289:5): [True: 4.78k, False: 795k]
  ------------------
  290|  4.78k|        if (ctx->in->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  4.78k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (290:13): [True: 0, False: 4.78k]
  ------------------
  291|      0|            zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
  292|      0|            return -1;
  293|      0|        }
  294|  4.78k|        return (zip_int64_t)ctx->in->offset;
  295|       |
  296|       |
  297|   104k|    case ZIP_SOURCE_TELL_WRITE:
  ------------------
  |  Branch (297:5): [True: 104k, False: 695k]
  ------------------
  298|   104k|        if (ctx->out->offset > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   104k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (298:13): [True: 0, False: 104k]
  ------------------
  299|      0|            zip_error_set(&ctx->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
  300|      0|            return -1;
  301|      0|        }
  302|   104k|        return (zip_int64_t)ctx->out->offset;
  303|       |
  304|   203k|    case ZIP_SOURCE_WRITE:
  ------------------
  |  Branch (304:5): [True: 203k, False: 596k]
  ------------------
  305|   203k|        if (len > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   203k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (305:13): [True: 0, False: 203k]
  ------------------
  306|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  307|      0|            return -1;
  308|      0|        }
  309|   203k|        return buffer_write(ctx->out, data, len, &ctx->error);
  310|       |
  311|      0|    default:
  ------------------
  |  Branch (311:5): [True: 0, False: 799k]
  ------------------
  312|      0|        zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
  313|      0|        return -1;
  314|   799k|    }
  315|   799k|}
zip_source_buffer.c:buffer_find_fragment:
  373|  85.6k|static zip_uint64_t buffer_find_fragment(const buffer_t *buffer, zip_uint64_t offset) {
  374|  85.6k|    zip_uint64_t low, high, mid;
  375|       |
  376|  85.6k|    if (buffer->nfragments == 0) {
  ------------------
  |  Branch (376:9): [True: 0, False: 85.6k]
  ------------------
  377|      0|        return 0;
  378|      0|    }
  379|       |
  380|  85.6k|    low = 0;
  381|  85.6k|    high = buffer->nfragments - 1;
  382|       |
  383|  86.1k|    while (low < high) {
  ------------------
  |  Branch (383:12): [True: 15.6k, False: 70.5k]
  ------------------
  384|  15.6k|        mid = (high - low) / 2 + low;
  385|  15.6k|        if (buffer->fragment_offsets[mid] > offset) {
  ------------------
  |  Branch (385:13): [True: 0, False: 15.6k]
  ------------------
  386|      0|            high = mid - 1;
  387|      0|        }
  388|  15.6k|        else if (mid == buffer->nfragments || buffer->fragment_offsets[mid + 1] > offset) {
  ------------------
  |  Branch (388:18): [True: 0, False: 15.6k]
  |  Branch (388:47): [True: 15.1k, False: 512]
  ------------------
  389|  15.1k|            return mid;
  390|  15.1k|        }
  391|    512|        else {
  392|    512|            low = mid + 1;
  393|    512|        }
  394|  15.6k|    }
  395|       |
  396|  70.5k|    return low;
  397|  85.6k|}
zip_source_buffer.c:buffer_read:
  514|  77.4k|static zip_int64_t buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
  515|  77.4k|    zip_uint64_t n, i, fragment_offset;
  516|       |
  517|  77.4k|    length = ZIP_MIN(length, buffer->size - buffer->offset);
  ------------------
  |  |  515|  77.4k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 40.2k, False: 37.2k]
  |  |  ------------------
  ------------------
  518|       |
  519|  77.4k|    if (length == 0) {
  ------------------
  |  Branch (519:9): [True: 21.2k, False: 56.2k]
  ------------------
  520|  21.2k|        return 0;
  521|  21.2k|    }
  522|  56.2k|    if (length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  56.2k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (522:9): [True: 0, False: 56.2k]
  ------------------
  523|      0|        return -1;
  524|      0|    }
  525|       |
  526|  56.2k|    i = buffer->current_fragment;
  527|  56.2k|    fragment_offset = buffer->offset - buffer->fragment_offsets[i];
  528|  56.2k|    n = 0;
  529|   112k|    while (n < length) {
  ------------------
  |  Branch (529:12): [True: 56.4k, False: 56.2k]
  ------------------
  530|  56.4k|        zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
  ------------------
  |  |  515|  56.4k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 45.0k, False: 11.4k]
  |  |  ------------------
  ------------------
  531|       |#if ZIP_UINT64_MAX > SIZE_MAX
  532|       |        left = ZIP_MIN(left, SIZE_MAX);
  533|       |#endif
  534|       |
  535|  56.4k|        (void)memcpy_s(data + n, (size_t)left, buffer->fragments[i].data + fragment_offset, (size_t)left);
  ------------------
  |  |  202|  56.4k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  536|       |
  537|  56.4k|        if (left == buffer->fragments[i].length - fragment_offset) {
  ------------------
  |  Branch (537:13): [True: 11.4k, False: 45.0k]
  ------------------
  538|  11.4k|            i++;
  539|  11.4k|        }
  540|  56.4k|        n += left;
  541|  56.4k|        fragment_offset = 0;
  542|  56.4k|    }
  543|       |
  544|  56.2k|    buffer->offset += n;
  545|  56.2k|    buffer->current_fragment = i;
  546|  56.2k|    return (zip_int64_t)n;
  547|  56.2k|}
zip_source_buffer.c:buffer_seek:
  550|  85.6k|static int buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error) {
  551|  85.6k|    zip_int64_t new_offset = zip_source_seek_compute_offset(buffer->offset, buffer->size, data, len, error);
  552|       |
  553|  85.6k|    if (new_offset < 0) {
  ------------------
  |  Branch (553:9): [True: 0, False: 85.6k]
  ------------------
  554|      0|        return -1;
  555|      0|    }
  556|       |
  557|  85.6k|    buffer->offset = (zip_uint64_t)new_offset;
  558|  85.6k|    buffer->current_fragment = buffer_find_fragment(buffer, buffer->offset);
  559|  85.6k|    return 0;
  560|  85.6k|}
zip_source_buffer.c:buffer_write:
  563|   203k|static zip_int64_t buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *error) {
  564|   203k|    zip_uint64_t copied, i, fragment_offset, capacity;
  565|       |
  566|   203k|    if (buffer->offset + length + WRITE_FRAGMENT_SIZE - 1 < length) {
  ------------------
  |  |   40|   203k|#define WRITE_FRAGMENT_SIZE (64 * 1024)
  ------------------
  |  Branch (566:9): [True: 0, False: 203k]
  ------------------
  567|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  568|      0|        return -1;
  569|      0|    }
  570|       |
  571|       |    /* grow buffer if needed */
  572|   203k|    capacity = buffer_capacity(buffer);
  ------------------
  |  |   69|   203k|#define buffer_capacity(buffer) ((buffer)->fragment_offsets[(buffer)->nfragments])
  ------------------
  573|   203k|    if (buffer->offset + length > capacity) {
  ------------------
  |  Branch (573:9): [True: 4.93k, False: 198k]
  ------------------
  574|  4.93k|        zip_uint64_t needed_fragments = buffer->nfragments + (length - (capacity - buffer->offset) + WRITE_FRAGMENT_SIZE - 1) / WRITE_FRAGMENT_SIZE;
  ------------------
  |  |   40|  4.93k|#define WRITE_FRAGMENT_SIZE (64 * 1024)
  ------------------
                      zip_uint64_t needed_fragments = buffer->nfragments + (length - (capacity - buffer->offset) + WRITE_FRAGMENT_SIZE - 1) / WRITE_FRAGMENT_SIZE;
  ------------------
  |  |   40|  4.93k|#define WRITE_FRAGMENT_SIZE (64 * 1024)
  ------------------
  575|       |
  576|  4.93k|        if (needed_fragments > buffer->fragments_capacity) {
  ------------------
  |  Branch (576:13): [True: 4.78k, False: 145]
  ------------------
  577|  4.78k|            zip_uint64_t new_capacity = buffer->fragments_capacity;
  578|       |
  579|  4.78k|            if (new_capacity == 0) {
  ------------------
  |  Branch (579:17): [True: 4.78k, False: 0]
  ------------------
  580|  4.78k|                new_capacity = 16;
  581|  4.78k|            }
  582|  4.78k|            while (new_capacity < needed_fragments) {
  ------------------
  |  Branch (582:20): [True: 0, False: 4.78k]
  ------------------
  583|      0|                new_capacity *= 2;
  584|      0|            }
  585|       |
  586|  4.78k|            if (!buffer_grow_fragments(buffer, new_capacity, error)) {
  ------------------
  |  Branch (586:17): [True: 0, False: 4.78k]
  ------------------
  587|      0|                zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  588|      0|                return -1;
  589|      0|            }
  590|  4.78k|        }
  591|       |
  592|  9.86k|        while (buffer->nfragments < needed_fragments) {
  ------------------
  |  Branch (592:16): [True: 4.93k, False: 4.93k]
  ------------------
  593|  4.93k|            if ((buffer->fragments[buffer->nfragments].data = malloc(WRITE_FRAGMENT_SIZE)) == NULL) {
  ------------------
  |  |   40|  4.93k|#define WRITE_FRAGMENT_SIZE (64 * 1024)
  ------------------
  |  Branch (593:17): [True: 0, False: 4.93k]
  ------------------
  594|      0|                zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  595|      0|                return -1;
  596|      0|            }
  597|  4.93k|            buffer->fragments[buffer->nfragments].length = WRITE_FRAGMENT_SIZE;
  ------------------
  |  |   40|  4.93k|#define WRITE_FRAGMENT_SIZE (64 * 1024)
  ------------------
  598|  4.93k|            buffer->nfragments++;
  599|  4.93k|            capacity += WRITE_FRAGMENT_SIZE;
  ------------------
  |  |   40|  4.93k|#define WRITE_FRAGMENT_SIZE (64 * 1024)
  ------------------
  600|  4.93k|            buffer->fragment_offsets[buffer->nfragments] = capacity;
  601|  4.93k|        }
  602|  4.93k|    }
  603|       |
  604|   203k|    i = buffer->current_fragment;
  605|   203k|    fragment_offset = buffer->offset - buffer->fragment_offsets[i];
  606|   203k|    copied = 0;
  607|   407k|    while (copied < length) {
  ------------------
  |  Branch (607:12): [True: 203k, False: 203k]
  ------------------
  608|   203k|        zip_uint64_t n = ZIP_MIN(ZIP_MIN(length - copied, buffer->fragments[i].length - fragment_offset), SIZE_MAX);
  ------------------
  |  |  515|   407k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 203k, False: 0]
  |  |  |  Branch (515:25): [True: 203k, False: 157]
  |  |  |  Branch (515:37): [True: 203k, False: 157]
  |  |  ------------------
  ------------------
  609|       |#if ZIP_UINT64_MAX > SIZE_MAX
  610|       |        n = ZIP_MIN(n, SIZE_MAX);
  611|       |#endif
  612|       |
  613|   203k|        (void)memcpy_s(buffer->fragments[i].data + fragment_offset, (size_t)n, data + copied, (size_t)n);
  ------------------
  |  |  202|   203k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  614|       |
  615|   203k|        if (n == buffer->fragments[i].length - fragment_offset) {
  ------------------
  |  Branch (615:13): [True: 157, False: 203k]
  ------------------
  616|    157|            i++;
  617|    157|            fragment_offset = 0;
  618|    157|        }
  619|   203k|        else {
  620|   203k|            fragment_offset += n;
  621|   203k|        }
  622|   203k|        copied += n;
  623|   203k|    }
  624|       |
  625|   203k|    buffer->offset += copied;
  626|   203k|    buffer->current_fragment = i;
  627|   203k|    if (buffer->offset > buffer->size) {
  ------------------
  |  Branch (627:9): [True: 144k, False: 59.7k]
  ------------------
  628|   144k|        buffer->size = buffer->offset;
  629|   144k|    }
  630|       |
  631|   203k|    return (zip_int64_t)copied;
  632|   203k|}
zip_source_buffer.c:buffer_grow_fragments:
  423|  23.0k|static bool buffer_grow_fragments(buffer_t *buffer, zip_uint64_t capacity, zip_error_t *error) {
  424|  23.0k|    zip_uint64_t additional_fragments;
  425|  23.0k|    zip_uint64_t offset_capacity = buffer->fragments_capacity + 1;
  426|       |
  427|  23.0k|    if (capacity <= buffer->fragments_capacity) {
  ------------------
  |  Branch (427:9): [True: 0, False: 23.0k]
  ------------------
  428|      0|        return true;
  429|      0|    }
  430|       |
  431|  23.0k|    additional_fragments = capacity - buffer->fragments_capacity;
  432|       |
  433|  23.0k|    if (!ZIP_REALLOC(buffer->fragments, buffer->fragments_capacity, additional_fragments, error)) {
  ------------------
  |  |  107|  23.0k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (433:9): [True: 0, False: 23.0k]
  ------------------
  434|      0|        return false;
  435|      0|    }
  436|       |    /* The size of both buffer->fragments and buffer->fragment_offsets is stored in buffer->fragments_capacity, so use a temporary capacity variable here for reallocating buffer->fragment_offsets. */
  437|  23.0k|    if (!ZIP_REALLOC(buffer->fragment_offsets, offset_capacity, additional_fragments, error)) {
  ------------------
  |  |  107|  23.0k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (437:9): [True: 0, False: 23.0k]
  ------------------
  438|      0|        buffer->fragments_capacity -= additional_fragments;
  439|      0|        return false;
  440|      0|    }
  441|       |
  442|  23.0k|    return true;
  443|  23.0k|}
zip_source_buffer.c:buffer_free:
  400|  81.2k|static void buffer_free(buffer_t *buffer) {
  401|  81.2k|    zip_uint64_t i;
  402|       |
  403|  81.2k|    if (buffer == NULL) {
  ------------------
  |  Branch (403:9): [True: 38.1k, False: 43.1k]
  ------------------
  404|  38.1k|        return;
  405|  38.1k|    }
  406|       |
  407|  43.1k|    if (buffer->shared_buffer != NULL) {
  ------------------
  |  Branch (407:9): [True: 0, False: 43.1k]
  ------------------
  408|      0|        buffer->shared_buffer->shared_buffer = NULL;
  409|      0|        buffer->shared_buffer->shared_fragments = 0;
  410|       |
  411|      0|        buffer->first_owned_fragment = ZIP_MAX(buffer->first_owned_fragment, buffer->shared_fragments);
  ------------------
  |  |  514|      0|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (514:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  412|      0|    }
  413|       |
  414|  59.7k|    for (i = buffer->first_owned_fragment; i < buffer->nfragments; i++) {
  ------------------
  |  Branch (414:44): [True: 16.5k, False: 43.1k]
  ------------------
  415|  16.5k|        free(buffer->fragments[i].data);
  416|  16.5k|    }
  417|  43.1k|    free(buffer->fragments);
  418|  43.1k|    free(buffer->fragment_offsets);
  419|  43.1k|    free(buffer);
  420|  43.1k|}
zip_source_buffer.c:buffer_new:
  446|  43.1k|static buffer_t *buffer_new(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int free_data, zip_error_t *error) {
  447|  43.1k|    buffer_t *buffer;
  448|       |
  449|  43.1k|    if ((buffer = malloc(sizeof(*buffer))) == NULL) {
  ------------------
  |  Branch (449:9): [True: 0, False: 43.1k]
  ------------------
  450|      0|        return NULL;
  451|      0|    }
  452|       |
  453|  43.1k|    buffer->offset = 0;
  454|  43.1k|    buffer->first_owned_fragment = 0;
  455|  43.1k|    buffer->size = 0;
  456|  43.1k|    buffer->fragments = NULL;
  457|  43.1k|    buffer->fragment_offsets = NULL;
  458|  43.1k|    buffer->nfragments = 0;
  459|  43.1k|    buffer->fragments_capacity = 0;
  460|  43.1k|    buffer->shared_buffer = NULL;
  461|  43.1k|    buffer->shared_fragments = 0;
  462|       |
  463|  43.1k|    if (nfragments == 0) {
  ------------------
  |  Branch (463:9): [True: 24.8k, False: 18.2k]
  ------------------
  464|  24.8k|        if ((buffer->fragment_offsets = malloc(sizeof(buffer->fragment_offsets[0]))) == NULL) {
  ------------------
  |  Branch (464:13): [True: 0, False: 24.8k]
  ------------------
  465|      0|            free(buffer);
  466|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  467|      0|            return NULL;
  468|      0|        }
  469|  24.8k|        buffer->fragment_offsets[0] = 0;
  470|  24.8k|    }
  471|  18.2k|    else {
  472|  18.2k|        zip_uint64_t i, j, offset;
  473|       |
  474|  18.2k|        if (!buffer_grow_fragments(buffer, nfragments, NULL)) {
  ------------------
  |  Branch (474:13): [True: 0, False: 18.2k]
  ------------------
  475|      0|            zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  476|      0|            buffer_free(buffer);
  477|      0|            return NULL;
  478|      0|        }
  479|       |
  480|  18.2k|        offset = 0;
  481|  36.5k|        for (i = 0, j = 0; i < nfragments; i++) {
  ------------------
  |  Branch (481:28): [True: 18.2k, False: 18.2k]
  ------------------
  482|  18.2k|            if (fragments[i].length == 0) {
  ------------------
  |  Branch (482:17): [True: 6.61k, False: 11.6k]
  ------------------
  483|  6.61k|                continue;
  484|  6.61k|            }
  485|  11.6k|            if (fragments[i].data == NULL) {
  ------------------
  |  Branch (485:17): [True: 0, False: 11.6k]
  ------------------
  486|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  487|      0|                buffer_free(buffer);
  488|      0|                return NULL;
  489|      0|            }
  490|  11.6k|            buffer->fragments[j].data = fragments[i].data;
  491|  11.6k|            buffer->fragments[j].length = fragments[i].length;
  492|  11.6k|            buffer->fragment_offsets[j] = offset;
  493|  11.6k|            if (offset + fragments[i].length < offset) {
  ------------------
  |  Branch (493:17): [True: 0, False: 11.6k]
  ------------------
  494|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  495|      0|                buffer_free(buffer);
  496|      0|                return NULL;
  497|      0|            }
  498|  11.6k|            offset += fragments[i].length;
  499|  11.6k|            j++;
  500|  11.6k|        }
  501|  18.2k|        buffer->nfragments = j;
  502|  18.2k|        buffer->first_owned_fragment = free_data ? 0 : buffer->nfragments;
  ------------------
  |  Branch (502:40): [True: 18.2k, False: 0]
  ------------------
  503|  18.2k|        buffer->fragment_offsets[buffer->nfragments] = offset;
  504|  18.2k|        buffer->size = offset;
  505|  18.2k|    }
  506|       |
  507|  43.1k|    return buffer;
  508|  43.1k|}

_zip_source_call:
   38|  1.30M|zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command) {
   39|  1.30M|    zip_int64_t ret;
   40|       |
   41|  1.30M|    if ((src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(command)) == 0) {
  ------------------
  |  |  276|  1.30M|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (41:9): [True: 0, False: 1.30M]
  ------------------
   42|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  1.30M|    if (src->src == NULL) {
  ------------------
  |  Branch (46:9): [True: 761k, False: 541k]
  ------------------
   47|   761k|        ret = src->cb.f(src->ud, data, length, command);
   48|   761k|    }
   49|   541k|    else {
   50|   541k|        ret = src->cb.l(src->src, src->ud, data, length, command);
   51|   541k|    }
   52|       |
   53|  1.30M|    if (ret < 0) {
  ------------------
  |  Branch (53:9): [True: 232, False: 1.30M]
  ------------------
   54|    232|        if (command != ZIP_SOURCE_ERROR && command != ZIP_SOURCE_SUPPORTS) {
  ------------------
  |  Branch (54:13): [True: 232, False: 0]
  |  Branch (54:44): [True: 232, False: 0]
  ------------------
   55|    232|            _zip_source_get_error(src);
   56|    232|        }
   57|    232|    }
   58|       |
   59|  1.30M|    return ret;
   60|  1.30M|}
_zip_source_get_error:
   62|    232|void _zip_source_get_error(zip_source_t *src) {
   63|    232|    int e[2];
   64|       |
   65|    232|    if (_zip_source_call(src, e, sizeof(e), ZIP_SOURCE_ERROR) < 0) {
  ------------------
  |  Branch (65:9): [True: 0, False: 232]
  ------------------
   66|      0|        zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   67|      0|    }
   68|    232|    else {
   69|    232|        zip_error_set(&src->error, e[0], e[1]);
   70|    232|    }
   71|    232|}

zip_source_close:
   38|   141k|int zip_source_close(zip_source_t *src) {
   39|   141k|    int ret = 0;
   40|       |
   41|   141k|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|   141k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (41:9): [True: 7.13k, False: 134k]
  ------------------
   42|  7.13k|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|  7.13k|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   43|  7.13k|        return -1;
   44|  7.13k|    }
   45|       |
   46|   134k|    src->open_count--;
   47|   134k|    if (src->open_count == 0) {
  ------------------
  |  Branch (47:9): [True: 122k, False: 11.5k]
  ------------------
   48|   122k|        src->have_next_byte = false;
   49|       |
   50|   122k|        if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE) < 0) {
  ------------------
  |  Branch (50:13): [True: 116, False: 122k]
  ------------------
   51|    116|            ret = -1;
   52|    116|        }
   53|       |
   54|   122k|        if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|   122k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 84.3k, False: 38.2k]
  |  |  ------------------
  ------------------
   55|  84.3k|            if (!ZIP_SOURCE_IS_OPEN_READING(src->src)) {
  ------------------
  |  |  441|  84.3k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (55:17): [True: 0, False: 84.3k]
  ------------------
   56|      0|                if (ret == 0) {
  ------------------
  |  Branch (56:21): [True: 0, False: 0]
  ------------------
   57|      0|                    zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   58|      0|                }
   59|      0|                return -1;
   60|      0|            }
   61|  84.3k|            if (zip_source_close(src->src) < 0) {
  ------------------
  |  Branch (61:17): [True: 0, False: 84.3k]
  ------------------
   62|      0|                if (ret == 0) {
  ------------------
  |  Branch (62:21): [True: 0, False: 0]
  ------------------
   63|      0|                    zip_error_set_from_source(&src->error, src->src);
   64|      0|                }
   65|      0|                ret = -1;
   66|      0|            }
   67|  84.3k|        }
   68|   122k|    }
   69|       |
   70|   134k|    return ret;
   71|   134k|}

zip_source_commit_write:
   38|  4.78k|ZIP_EXTERN int zip_source_commit_write(zip_source_t *src) {
   39|  4.78k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|  4.78k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 4.78k]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|  4.78k|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  442|  4.78k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
  |  Branch (44:9): [True: 0, False: 4.78k]
  ------------------
   45|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|  4.78k|    if (src->open_count > 1) {
  ------------------
  |  Branch (49:9): [True: 0, False: 4.78k]
  ------------------
   50|      0|        zip_error_set(&src->error, ZIP_ER_INUSE, 0);
  ------------------
  |  |  160|      0|#define ZIP_ER_INUSE 29           /* N Resource still in use */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|  4.78k|    else if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  4.78k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 4.78k, False: 0]
  |  |  ------------------
  ------------------
   54|  4.78k|        if (zip_source_close(src) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 4.78k]
  ------------------
   55|      0|            return -1;
   56|      0|        }
   57|  4.78k|    }
   58|       |
   59|  4.78k|    if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_COMMIT_WRITE) < 0) {
  ------------------
  |  Branch (59:9): [True: 0, False: 4.78k]
  ------------------
   60|      0|        src->write_state = ZIP_SOURCE_WRITE_FAILED;
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|  4.78k|    src->write_state = ZIP_SOURCE_WRITE_CLOSED;
   65|       |
   66|  4.78k|    return 0;
   67|  4.78k|}

_zip_get_compression_algorithm:
   93|  32.0k|zip_compression_algorithm_t *_zip_get_compression_algorithm(zip_int32_t method, bool compress) {
   94|  32.0k|    size_t i;
   95|  32.0k|    zip_uint16_t real_method = ZIP_CM_ACTUAL(method);
  ------------------
  |  |   87|  32.0k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  32.0k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|  9.92k|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 9.92k, False: 22.1k]
  |  |  ------------------
  ------------------
   96|       |
   97|  32.0k|    for (i = 0; i < implementations_size; i++) {
  ------------------
  |  Branch (97:17): [True: 32.0k, False: 0]
  ------------------
   98|  32.0k|        if (implementations[i].method == real_method) {
  ------------------
  |  Branch (98:13): [True: 32.0k, False: 0]
  ------------------
   99|  32.0k|            if (compress) {
  ------------------
  |  Branch (99:17): [True: 28.4k, False: 3.61k]
  ------------------
  100|  28.4k|                return implementations[i].compress;
  101|  28.4k|            }
  102|  3.61k|            else {
  103|  3.61k|                return implementations[i].decompress;
  104|  3.61k|            }
  105|  32.0k|        }
  106|  32.0k|    }
  107|       |
  108|      0|    return NULL;
  109|  32.0k|}
zip_compression_method_supported:
  111|  18.2k|ZIP_EXTERN int zip_compression_method_supported(zip_int32_t method, int compress) {
  112|  18.2k|    if (method == ZIP_CM_STORE) {
  ------------------
  |  |  179|  18.2k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (112:9): [True: 11.5k, False: 6.72k]
  ------------------
  113|  11.5k|        return 1;
  114|  11.5k|    }
  115|  6.72k|    return _zip_get_compression_algorithm(method, compress) != NULL;
  116|  18.2k|}
zip_source_compress:
  118|  10.8k|zip_source_t *zip_source_compress(zip_t *za, zip_source_t *src, zip_int32_t method, zip_uint32_t compression_flags) {
  119|       |    return compression_source_new(za, src, method, true, compression_flags);
  120|  10.8k|}
zip_source_decompress:
  122|  3.61k|zip_source_t *zip_source_decompress(zip_t *za, zip_source_t *src, zip_int32_t method) {
  123|       |    return compression_source_new(za, src, method, false, 0);
  124|  3.61k|}
zip_source_compress.c:compression_source_new:
  127|  14.4k|static zip_source_t *compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, zip_uint32_t compression_flags) {
  128|  14.4k|    struct context *ctx;
  129|  14.4k|    zip_source_t *s2;
  130|  14.4k|    zip_compression_algorithm_t *algorithm = NULL;
  131|       |
  132|  14.4k|    if (src == NULL) {
  ------------------
  |  Branch (132:9): [True: 0, False: 14.4k]
  ------------------
  133|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  134|      0|        return NULL;
  135|      0|    }
  136|       |
  137|  14.4k|    if ((algorithm = _zip_get_compression_algorithm(method, compress)) == NULL) {
  ------------------
  |  Branch (137:9): [True: 0, False: 14.4k]
  ------------------
  138|      0|        zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0);
  ------------------
  |  |  147|      0|#define ZIP_ER_COMPNOTSUPP 16     /* N Compression method not supported */
  ------------------
  139|      0|        return NULL;
  140|      0|    }
  141|       |
  142|  14.4k|    if ((ctx = context_new(method, compress, compression_flags, algorithm, za->open_flags & ZIP_CHECKCONS)) == NULL) {
  ------------------
  |  |   88|  14.4k|#define ZIP_CHECKCONS 4
  ------------------
  |  Branch (142:9): [True: 0, False: 14.4k]
  ------------------
  143|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  144|      0|        return NULL;
  145|      0|    }
  146|       |
  147|  14.4k|    if ((s2 = zip_source_layered(za, src, compress_callback, ctx)) == NULL) {
  ------------------
  |  Branch (147:9): [True: 0, False: 14.4k]
  ------------------
  148|      0|        context_free(ctx);
  149|      0|        return NULL;
  150|      0|    }
  151|       |
  152|  14.4k|    return s2;
  153|  14.4k|}
zip_source_compress.c:context_new:
  156|  14.4k|static struct context *context_new(zip_int32_t method, bool compress, zip_uint32_t compression_flags, zip_compression_algorithm_t *algorithm, bool check_consistency) {
  157|  14.4k|    struct context *ctx;
  158|       |
  159|  14.4k|    if ((ctx = (struct context *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (159:9): [True: 0, False: 14.4k]
  ------------------
  160|      0|        return NULL;
  161|      0|    }
  162|  14.4k|    zip_error_init(&ctx->error);
  163|  14.4k|    ctx->can_store = compress ? method == ZIP_CM_DEFAULT : false;
  ------------------
  |  |  178|  10.8k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  |  Branch (163:22): [True: 10.8k, False: 3.61k]
  ------------------
  164|  14.4k|    ctx->algorithm = algorithm;
  165|  14.4k|    ctx->method = method;
  166|  14.4k|    ctx->compress = compress;
  167|  14.4k|    ctx->end_of_input = false;
  168|  14.4k|    ctx->end_of_stream = false;
  169|  14.4k|    ctx->is_stored = false;
  170|  14.4k|    ctx->check_consistency = check_consistency;
  171|       |
  172|  14.4k|    if ((ctx->ud = ctx->algorithm->allocate(ZIP_CM_ACTUAL(method), compression_flags, &ctx->error)) == NULL) {
  ------------------
  |  |   87|  14.4k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  14.4k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|  7.57k|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 7.57k, False: 6.91k]
  |  |  ------------------
  ------------------
  |  Branch (172:9): [True: 0, False: 14.4k]
  ------------------
  173|      0|        zip_error_fini(&ctx->error);
  174|      0|        free(ctx);
  175|      0|        return NULL;
  176|      0|    }
  177|       |
  178|  14.4k|    return ctx;
  179|  14.4k|}
zip_source_compress.c:compress_callback:
  314|   114k|static zip_int64_t compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  315|   114k|    struct context *ctx;
  316|       |
  317|   114k|    ctx = (struct context *)ud;
  318|       |
  319|   114k|    switch (cmd) {
  320|  14.4k|    case ZIP_SOURCE_OPEN: {
  ------------------
  |  Branch (320:5): [True: 14.4k, False: 100k]
  ------------------
  321|  14.4k|        zip_stat_t st;
  322|  14.4k|        zip_file_attributes_t attributes;
  323|       |
  324|  14.4k|        ctx->size = 0;
  325|  14.4k|        ctx->end_of_input = false;
  326|  14.4k|        ctx->end_of_stream = false;
  327|  14.4k|        ctx->is_stored = false;
  328|  14.4k|        ctx->first_read = -1;
  329|       |
  330|  14.4k|        if (zip_source_stat(src, &st) < 0 || zip_source_get_file_attributes(src, &attributes) < 0) {
  ------------------
  |  Branch (330:13): [True: 0, False: 14.4k]
  |  Branch (330:46): [True: 0, False: 14.4k]
  ------------------
  331|      0|            zip_error_set_from_source(&ctx->error, src);
  332|      0|            return -1;
  333|      0|        }
  334|       |
  335|  14.4k|        if (!ctx->algorithm->start(ctx->ud, &st, &attributes)) {
  ------------------
  |  Branch (335:13): [True: 0, False: 14.4k]
  ------------------
  336|      0|            return -1;
  337|      0|        }
  338|       |
  339|  14.4k|        return 0;
  340|  14.4k|    }
  341|       |
  342|  20.5k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (342:5): [True: 20.5k, False: 94.3k]
  ------------------
  343|  20.5k|        return compress_read(src, ctx, data, len);
  344|       |
  345|  14.4k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (345:5): [True: 14.4k, False: 100k]
  ------------------
  346|  14.4k|        if (!ctx->algorithm->end(ctx->ud)) {
  ------------------
  |  Branch (346:13): [True: 0, False: 14.4k]
  ------------------
  347|      0|            return -1;
  348|      0|        }
  349|  14.4k|        return 0;
  350|       |
  351|  14.6k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (351:5): [True: 14.6k, False: 100k]
  ------------------
  352|  14.6k|        zip_stat_t *st;
  353|       |
  354|  14.6k|        st = (zip_stat_t *)data;
  355|       |
  356|  14.6k|        if (ctx->compress) {
  ------------------
  |  Branch (356:13): [True: 11.7k, False: 2.94k]
  ------------------
  357|  11.7k|            if (ctx->end_of_stream) {
  ------------------
  |  Branch (357:17): [True: 10.8k, False: 864]
  ------------------
  358|  10.8k|                st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_ACTUAL(ctx->method);
  ------------------
  |  |  179|  7.19k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
                              st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_ACTUAL(ctx->method);
  ------------------
  |  |   87|  14.5k|#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  178|  3.67k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  |  |  ------------------
  |  |               #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
  |  |  ------------------
  |  |  |  |  187|    382|#define ZIP_CM_DEFLATE 8         /* deflated */
  |  |  ------------------
  |  |  |  Branch (87:42): [True: 382, False: 3.29k]
  |  |  ------------------
  ------------------
  |  Branch (358:35): [True: 7.19k, False: 3.67k]
  ------------------
  359|  10.8k|                st->comp_size = ctx->size;
  360|  10.8k|                st->valid |= ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  326|  10.8k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                              st->valid |= ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|  10.8k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  361|  10.8k|            }
  362|    864|            else {
  363|    864|                st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  326|    864|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                              st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  329|    864|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  364|    864|            }
  365|  11.7k|        }
  366|  2.94k|        else {
  367|  2.94k|            st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|  2.94k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  368|  2.94k|            st->valid |= ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|  2.94k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  369|  2.94k|            st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|  2.94k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  370|  2.94k|            if (ctx->end_of_stream) {
  ------------------
  |  Branch (370:17): [True: 2.94k, False: 0]
  ------------------
  371|  2.94k|                st->size = ctx->size;
  372|  2.94k|                st->valid |= ZIP_STAT_SIZE;
  ------------------
  |  |  325|  2.94k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  373|  2.94k|            }
  374|  2.94k|        }
  375|  14.6k|    }
  376|  14.6k|        return 0;
  377|       |
  378|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (378:5): [True: 0, False: 114k]
  ------------------
  379|      0|        return zip_error_to_data(&ctx->error, data, len);
  380|       |
  381|  14.4k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (381:5): [True: 14.4k, False: 100k]
  ------------------
  382|  14.4k|        context_free(ctx);
  383|  14.4k|        return 0;
  384|       |
  385|  21.7k|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (385:5): [True: 21.7k, False: 93.1k]
  ------------------
  386|  21.7k|        zip_file_attributes_t *attributes = (zip_file_attributes_t *)data;
  387|       |
  388|  21.7k|        if (len < sizeof(*attributes)) {
  ------------------
  |  Branch (388:13): [True: 0, False: 21.7k]
  ------------------
  389|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  390|      0|            return -1;
  391|      0|        }
  392|       |
  393|  21.7k|        attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  364|  21.7k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
                      attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  366|  21.7k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  394|  21.7k|        attributes->version_needed = ctx->algorithm->version_needed;
  395|  21.7k|        attributes->general_purpose_bit_mask = ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK;
  ------------------
  |  |  102|  21.7k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK 0x083e
  ------------------
  396|  21.7k|        attributes->general_purpose_bit_flags = (ctx->is_stored ? 0 : ctx->algorithm->general_purpose_bit_flags(ctx->ud));
  ------------------
  |  Branch (396:50): [True: 7.19k, False: 14.5k]
  ------------------
  397|       |
  398|  21.7k|        return sizeof(*attributes);
  399|  21.7k|    }
  400|       |
  401|  14.4k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (401:5): [True: 14.4k, False: 100k]
  ------------------
  402|  14.4k|        return ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  ------------------
  |  |  282|  14.4k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  ------------------
  |  |  |  |  276|  14.4k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  283|  14.4k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  ------------------
  |  |  |  |  276|  14.4k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  284|  14.4k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  ------------------
  |  |  |  |  276|  14.4k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  285|  14.4k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  ------------------
  |  |  |  |  276|  14.4k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  286|  14.4k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  ------------------
  |  |  |  |  276|  14.4k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  287|  14.4k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  ------------------
  |  |  |  |  276|  14.4k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  403|       |
  404|      0|    default:
  ------------------
  |  Branch (404:5): [True: 0, False: 114k]
  ------------------
  405|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  406|   114k|    }
  407|   114k|}
zip_source_compress.c:compress_read:
  194|  20.5k|static zip_int64_t compress_read(zip_source_t *src, struct context *ctx, void *data, zip_uint64_t len) {
  195|  20.5k|    zip_compression_status_t ret;
  196|  20.5k|    bool end;
  197|  20.5k|    zip_int64_t n;
  198|  20.5k|    zip_uint64_t out_offset;
  199|  20.5k|    zip_uint64_t out_len;
  200|       |
  201|  20.5k|    if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) {
  ------------------
  |  |  131|  20.5k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
  |  Branch (201:9): [True: 0, False: 20.5k]
  ------------------
  202|      0|        return -1;
  203|      0|    }
  204|       |
  205|  20.5k|    if (len == 0 || ctx->end_of_stream) {
  ------------------
  |  Branch (205:9): [True: 0, False: 20.5k]
  |  Branch (205:21): [True: 6.02k, False: 14.4k]
  ------------------
  206|  6.02k|        return 0;
  207|  6.02k|    }
  208|       |
  209|  14.4k|    out_offset = 0;
  210|       |
  211|  14.4k|    end = false;
  212|  51.8k|    while (!end && out_offset < len) {
  ------------------
  |  Branch (212:12): [True: 44.5k, False: 7.29k]
  |  Branch (212:20): [True: 44.5k, False: 0]
  ------------------
  213|  44.5k|        out_len = len - out_offset;
  214|  44.5k|        ret = ctx->algorithm->process(ctx->ud, (zip_uint8_t *)data + out_offset, &out_len);
  215|       |
  216|  44.5k|        if (ret != ZIP_COMPRESSION_ERROR) {
  ------------------
  |  Branch (216:13): [True: 44.5k, False: 0]
  ------------------
  217|  44.5k|            out_offset += out_len;
  218|  44.5k|        }
  219|       |
  220|  44.5k|        switch (ret) {
  ------------------
  |  Branch (220:17): [True: 44.5k, False: 0]
  ------------------
  221|  14.4k|        case ZIP_COMPRESSION_END:
  ------------------
  |  Branch (221:9): [True: 14.4k, False: 30.0k]
  ------------------
  222|  14.4k|            ctx->end_of_stream = true;
  223|       |
  224|  14.4k|            if (!ctx->end_of_input) {
  ------------------
  |  Branch (224:17): [True: 3.61k, False: 10.8k]
  ------------------
  225|  3.61k|                n = zip_source_read(src, ctx->buffer, 1);
  226|  3.61k|                if (n < 0) {
  ------------------
  |  Branch (226:21): [True: 0, False: 3.61k]
  ------------------
  227|      0|                    zip_error_set_from_source(&ctx->error, src);
  228|      0|                    end = true;
  229|      0|                    break;
  230|      0|                }
  231|  3.61k|                else if (n == 0) {
  ------------------
  |  Branch (231:26): [True: 3.61k, False: 0]
  ------------------
  232|  3.61k|                    ctx->end_of_input = true;
  233|  3.61k|                    n = ctx->algorithm->end_of_input(ctx->ud) ? 1 : 0;
  ------------------
  |  Branch (233:25): [True: 0, False: 3.61k]
  ------------------
  234|  3.61k|                }
  235|       |
  236|  3.61k|                if (n > 0 && ctx->check_consistency) {
  ------------------
  |  Branch (236:21): [True: 0, False: 3.61k]
  |  Branch (236:30): [True: 0, False: 0]
  ------------------
  237|       |                    /* garbage after stream, or compression ended before all data read */
  238|      0|                    zip_error_set(&ctx->error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE);
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                                  zip_error_set(&ctx->error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE);
  ------------------
  |  |  246|      0|#define ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE 25 /* G garbage at end of compressed data */
  ------------------
  239|      0|                    end = true;
  240|      0|                    break;
  241|      0|                }
  242|  3.61k|            }
  243|       |
  244|  14.4k|            if (ctx->first_read < 0) {
  ------------------
  |  Branch (244:17): [True: 0, False: 14.4k]
  ------------------
  245|       |                /* we got end of processed stream before reading any input data */
  246|      0|                zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  247|      0|                end = true;
  248|      0|                break;
  249|      0|            }
  250|  14.4k|            if (ctx->can_store && (zip_uint64_t)ctx->first_read <= out_offset) {
  ------------------
  |  Branch (250:17): [True: 7.57k, False: 6.91k]
  |  Branch (250:35): [True: 7.19k, False: 382]
  ------------------
  251|  7.19k|                ctx->is_stored = true;
  252|  7.19k|                ctx->size = (zip_uint64_t)ctx->first_read;
  253|  7.19k|                (void)memcpy_s(data, ctx->size, ctx->buffer, ctx->size);
  ------------------
  |  |  202|  7.19k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  254|  7.19k|                return (zip_int64_t)ctx->size;
  255|  7.19k|            }
  256|  7.29k|            end = true;
  257|  7.29k|            break;
  258|       |
  259|  13.2k|        case ZIP_COMPRESSION_OK:
  ------------------
  |  Branch (259:9): [True: 13.2k, False: 31.3k]
  ------------------
  260|  13.2k|            break;
  261|       |
  262|  16.8k|        case ZIP_COMPRESSION_NEED_DATA:
  ------------------
  |  Branch (262:9): [True: 16.8k, False: 27.7k]
  ------------------
  263|  16.8k|            if (ctx->end_of_input) {
  ------------------
  |  Branch (263:17): [True: 0, False: 16.8k]
  ------------------
  264|       |                /* TODO: error: stream not ended, but no more input */
  265|      0|                end = true;
  266|      0|                break;
  267|      0|            }
  268|       |
  269|  16.8k|            if ((n = zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) {
  ------------------
  |  Branch (269:17): [True: 0, False: 16.8k]
  ------------------
  270|      0|                zip_error_set_from_source(&ctx->error, src);
  271|      0|                end = true;
  272|      0|                break;
  273|      0|            }
  274|  16.8k|            else if (n == 0) {
  ------------------
  |  Branch (274:22): [True: 10.8k, False: 5.96k]
  ------------------
  275|  10.8k|                ctx->end_of_input = true;
  276|  10.8k|                ctx->algorithm->end_of_input(ctx->ud);
  277|  10.8k|                if (ctx->first_read < 0) {
  ------------------
  |  Branch (277:21): [True: 8.52k, False: 2.35k]
  ------------------
  278|  8.52k|                    ctx->first_read = 0;
  279|  8.52k|                }
  280|  10.8k|            }
  281|  5.96k|            else {
  282|  5.96k|                if (ctx->first_read >= 0) {
  ------------------
  |  Branch (282:21): [True: 0, False: 5.96k]
  ------------------
  283|       |                    /* we overwrote a previously filled ctx->buffer */
  284|      0|                    ctx->can_store = false;
  285|      0|                }
  286|  5.96k|                else {
  287|  5.96k|                    ctx->first_read = n;
  288|  5.96k|                }
  289|       |
  290|  5.96k|                ctx->algorithm->input(ctx->ud, ctx->buffer, (zip_uint64_t)n);
  291|  5.96k|            }
  292|  16.8k|            break;
  293|       |
  294|  16.8k|        case ZIP_COMPRESSION_ERROR:
  ------------------
  |  Branch (294:9): [True: 0, False: 44.5k]
  ------------------
  295|       |            /* error set by algorithm */
  296|      0|            if (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) {
  ------------------
  |  |  131|      0|#define ZIP_ER_OK 0               /* N No error */
  ------------------
  |  Branch (296:17): [True: 0, False: 0]
  ------------------
  297|      0|                zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  298|      0|            }
  299|      0|            end = true;
  300|      0|            break;
  301|  44.5k|        }
  302|  44.5k|    }
  303|       |
  304|  7.29k|    if (out_offset > 0) {
  ------------------
  |  Branch (304:9): [True: 5.77k, False: 1.51k]
  ------------------
  305|  5.77k|        ctx->can_store = false;
  306|  5.77k|        ctx->size += out_offset;
  307|  5.77k|        return (zip_int64_t)out_offset;
  308|  5.77k|    }
  309|       |
  310|  1.51k|    return (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) ? 0 : -1;
  ------------------
  |  |  131|  1.51k|#define ZIP_ER_OK 0               /* N No error */
  ------------------
  |  Branch (310:12): [True: 1.51k, False: 0]
  ------------------
  311|  7.29k|}
zip_source_compress.c:context_free:
  182|  14.4k|static void context_free(struct context *ctx) {
  183|  14.4k|    if (ctx == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 14.4k]
  ------------------
  184|      0|        return;
  185|      0|    }
  186|       |
  187|  14.4k|    ctx->algorithm->deallocate(ctx->ud);
  188|  14.4k|    zip_error_fini(&ctx->error);
  189|       |
  190|  14.4k|    free(ctx);
  191|  14.4k|}

zip_source_crc_create:
   54|  31.6k|zip_source_t *zip_source_crc_create(zip_source_t *src, int validate, zip_error_t *error) {
   55|  31.6k|    struct crc_context *ctx;
   56|  31.6k|    zip_source_t *new_src;
   57|       |
   58|  31.6k|    if (src == NULL) {
  ------------------
  |  Branch (58:9): [True: 0, False: 31.6k]
  ------------------
   59|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   60|      0|        return NULL;
   61|      0|    }
   62|       |
   63|  31.6k|    if ((ctx = (struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (63:9): [True: 0, False: 31.6k]
  ------------------
   64|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   65|      0|        return NULL;
   66|      0|    }
   67|       |
   68|  31.6k|    zip_error_init(&ctx->error);
   69|  31.6k|    ctx->validate = validate;
   70|  31.6k|    ctx->crc_complete = 0;
   71|  31.6k|    ctx->crc_position = 0;
   72|  31.6k|    ctx->crc = (zip_uint32_t)crc32(0, NULL, 0);
   73|  31.6k|    ctx->size = 0;
   74|       |
   75|  31.6k|    new_src = zip_source_layered_create(src, crc_read, ctx, error);
   76|  31.6k|    if (new_src == NULL) {
  ------------------
  |  Branch (76:9): [True: 0, False: 31.6k]
  ------------------
   77|      0|        free(ctx);
   78|      0|        return NULL;
   79|      0|    }
   80|  31.6k|    return new_src;
   81|  31.6k|}
zip_source_crc.c:crc_read:
   84|   205k|static zip_int64_t crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
   85|   205k|    struct crc_context *ctx;
   86|   205k|    zip_int64_t n;
   87|       |
   88|   205k|    ctx = (struct crc_context *)_ctx;
   89|       |
   90|   205k|    switch (cmd) {
   91|  31.6k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (91:5): [True: 31.6k, False: 174k]
  ------------------
   92|  31.6k|        ctx->position = 0;
   93|  31.6k|        return 0;
   94|       |
   95|  45.7k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (95:5): [True: 45.7k, False: 160k]
  ------------------
   96|  45.7k|        if ((n = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (96:13): [True: 0, False: 45.7k]
  ------------------
   97|      0|            zip_error_set_from_source(&ctx->error, src);
   98|      0|            return -1;
   99|      0|        }
  100|       |
  101|  45.7k|        if (n == 0) {
  ------------------
  |  Branch (101:13): [True: 31.6k, False: 14.0k]
  ------------------
  102|  31.6k|            return validate_crc(ctx, src);
  103|  31.6k|        }
  104|  14.0k|        else {
  105|       |            /*
  106|       |             We can only compute the CRC data in the correct order. So we update the CRC for data read this time that starts at ctx->crc_position.
  107|       |
  108|       |             If we already computed the CRC for the whole file, or if there is a gap between ctx->crc_position and the start of new data, or if we already computed the CRC for all new data read, we don't update the CRC.
  109|       |
  110|       |             ctx->position is the position of the first byte in data.
  111|       |
  112|       |             ctx->crc_position is the position of the first byte in data that has not been included  in the CRC yet.
  113|       |
  114|       |             Therefore, we want to compute the CRC for data[ctx->crc_position - ctx->position .. n-1].
  115|       |
  116|       |            */
  117|  14.0k|            if (!ctx->crc_complete && ctx->position <= ctx->crc_position && ctx->crc_position < ctx->position + (zip_uint64_t)n) {
  ------------------
  |  Branch (117:17): [True: 14.0k, False: 0]
  |  Branch (117:39): [True: 14.0k, False: 0]
  |  Branch (117:77): [True: 14.0k, False: 0]
  ------------------
  118|  14.0k|                zip_uint64_t i, nn;
  119|       |
  120|  28.1k|                for (i = ctx->crc_position - ctx->position; i < (zip_uint64_t)n; i += nn) {
  ------------------
  |  Branch (120:61): [True: 14.0k, False: 14.0k]
  ------------------
  121|  14.0k|                    nn = ZIP_MIN(UINT_MAX, (zip_uint64_t)n - i);
  ------------------
  |  |  515|  14.0k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 14.0k]
  |  |  ------------------
  ------------------
  122|       |
  123|  14.0k|                    ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data + i, (uInt)nn);
  124|  14.0k|                    ctx->crc_position += nn;
  125|  14.0k|                }
  126|  14.0k|            }
  127|  14.0k|        }
  128|  14.0k|        ctx->position += (zip_uint64_t)n;
  129|  14.0k|        return n;
  130|       |
  131|  31.6k|    case ZIP_SOURCE_CLOSE: {
  ------------------
  |  Branch (131:5): [True: 31.6k, False: 174k]
  ------------------
  132|  31.6k|        zip_int64_t ret = zip_source_at_eof(src);
  133|  31.6k|        if (ret < 0) {
  ------------------
  |  Branch (133:13): [True: 0, False: 31.6k]
  ------------------
  134|      0|            zip_error_set_from_source(&ctx->error, src);
  135|      0|            return -1;
  136|      0|        }
  137|  31.6k|        else if (ret == 1) {
  ------------------
  |  Branch (137:18): [True: 31.6k, False: 0]
  ------------------
  138|  31.6k|            return validate_crc(ctx, src);
  139|  31.6k|        }
  140|      0|        else {
  141|      0|            return 0;
  142|      0|        }
  143|  31.6k|    }
  144|       |
  145|  33.4k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (145:5): [True: 33.4k, False: 172k]
  ------------------
  146|  33.4k|        zip_stat_t *st;
  147|       |
  148|  33.4k|        st = (zip_stat_t *)data;
  149|       |
  150|  33.4k|        if (ctx->crc_complete) {
  ------------------
  |  Branch (150:13): [True: 21.2k, False: 12.2k]
  ------------------
  151|  21.2k|            if ((st->valid & ZIP_STAT_SIZE) && st->size != ctx->size) {
  ------------------
  |  |  325|  21.2k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (151:17): [True: 21.2k, False: 0]
  |  Branch (151:48): [True: 0, False: 21.2k]
  ------------------
  152|      0|                zip_error_set(&ctx->error, ZIP_ER_DATA_LENGTH, 0);
  ------------------
  |  |  164|      0|#define ZIP_ER_DATA_LENGTH 33     /* N Unexpected length of data */
  ------------------
  153|      0|                return -1;
  154|      0|            }
  155|       |            /* TODO: Set comp_size, comp_method, encryption_method?
  156|       |                    After all, this only works for uncompressed data. */
  157|  21.2k|            st->size = ctx->size;
  158|  21.2k|            st->crc = ctx->crc;
  159|  21.2k|            st->comp_size = ctx->size;
  160|  21.2k|            st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|  21.2k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  161|  21.2k|            st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  21.2k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  162|  21.2k|            st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  325|  21.2k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  328|  21.2k|#define ZIP_STAT_CRC 0x0020u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|  21.2k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|  21.2k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                          st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  21.2k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  163|  21.2k|        }
  164|  33.4k|        return 0;
  165|  33.4k|    }
  166|       |
  167|    232|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (167:5): [True: 232, False: 205k]
  ------------------
  168|    232|        return zip_error_to_data(&ctx->error, data, len);
  169|       |
  170|  31.6k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (170:5): [True: 31.6k, False: 174k]
  ------------------
  171|  31.6k|        free(ctx);
  172|  31.6k|        return 0;
  173|       |
  174|  31.6k|    case ZIP_SOURCE_SUPPORTS: {
  ------------------
  |  Branch (174:5): [True: 31.6k, False: 174k]
  ------------------
  175|  31.6k|        zip_int64_t mask = zip_source_supports(src);
  176|       |
  177|  31.6k|        if (mask < 0) {
  ------------------
  |  Branch (177:13): [True: 0, False: 31.6k]
  ------------------
  178|      0|            zip_error_set_from_source(&ctx->error, src);
  179|      0|            return -1;
  180|      0|        }
  181|       |
  182|  31.6k|        mask &= ~zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
  183|  31.6k|        mask |= zip_source_make_command_bitmap(ZIP_SOURCE_FREE, -1);
  184|  31.6k|        return mask;
  185|  31.6k|    }
  186|       |
  187|      0|    case ZIP_SOURCE_SEEK: {
  ------------------
  |  Branch (187:5): [True: 0, False: 205k]
  ------------------
  188|      0|        zip_int64_t new_position;
  189|      0|        zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
  ------------------
  |  |  312|      0|#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
  |  |  ------------------
  |  |  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  |  |  ------------------
  |  |  |  Branch (312:54): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  190|       |
  191|      0|        if (args == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  ------------------
  192|      0|            return -1;
  193|      0|        }
  194|      0|        if (zip_source_seek(src, args->offset, args->whence) < 0 || (new_position = zip_source_tell(src)) < 0) {
  ------------------
  |  Branch (194:13): [True: 0, False: 0]
  |  Branch (194:69): [True: 0, False: 0]
  ------------------
  195|      0|            zip_error_set_from_source(&ctx->error, src);
  196|      0|            return -1;
  197|      0|        }
  198|       |
  199|      0|        ctx->position = (zip_uint64_t)new_position;
  200|       |
  201|      0|        return 0;
  202|      0|    }
  203|       |
  204|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (204:5): [True: 0, False: 205k]
  ------------------
  205|      0|        return (zip_int64_t)ctx->position;
  206|       |
  207|      0|    default:
  ------------------
  |  Branch (207:5): [True: 0, False: 205k]
  ------------------
  208|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  209|   205k|    }
  210|   205k|}
zip_source_crc.c:validate_crc:
  212|  63.2k|zip_int64_t validate_crc(struct crc_context *ctx, zip_source_t *src) {
  213|  63.2k|    struct zip_stat st;
  214|       |
  215|  63.2k|    ctx->size = ctx->position;
  216|       |
  217|  63.2k|    if (ctx->validate) {
  ------------------
  |  Branch (217:9): [True: 20.8k, False: 42.4k]
  ------------------
  218|  20.8k|        if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (218:13): [True: 0, False: 20.8k]
  ------------------
  219|      0|            zip_error_set_from_source(&ctx->error, src);
  220|      0|            return -1;
  221|      0|        }
  222|  20.8k|    }
  223|       |
  224|  63.2k|    if (ctx->crc_position == ctx->position) {
  ------------------
  |  Branch (224:9): [True: 63.2k, False: 0]
  ------------------
  225|  63.2k|        ctx->crc_complete = 1;
  226|       |
  227|  63.2k|        if (ctx->validate) {
  ------------------
  |  Branch (227:13): [True: 20.8k, False: 42.4k]
  ------------------
  228|  20.8k|            if ((st.valid & ZIP_STAT_CRC) && st.crc != ctx->crc) {
  ------------------
  |  |  328|  20.8k|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (228:17): [True: 20.8k, False: 0]
  |  Branch (228:46): [True: 232, False: 20.6k]
  ------------------
  229|    232|                zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
  ------------------
  |  |  138|    232|#define ZIP_ER_CRC 7              /* N CRC error */
  ------------------
  230|    232|                return -1;
  231|    232|            }
  232|  20.8k|        }
  233|  63.2k|    }
  234|       |
  235|  63.0k|    if (ctx->validate) {
  ------------------
  |  Branch (235:9): [True: 20.6k, False: 42.4k]
  ------------------
  236|  20.6k|        if ((st.valid & ZIP_STAT_SIZE) && st.size != ctx->size) {
  ------------------
  |  |  325|  20.6k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (236:13): [True: 20.6k, False: 0]
  |  Branch (236:43): [True: 0, False: 20.6k]
  ------------------
  237|       |            /* We don't have the index here, but the caller should know which file they are reading from. */
  238|      0|            zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_INVALID_FILE_LENGTH, MAX_DETAIL_INDEX));
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                          zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_INVALID_FILE_LENGTH, MAX_DETAIL_INDEX));
  ------------------
  |  |  215|      0|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |  |  Branch (215:48): [Folded, False: 0]
  |  |  ------------------
  ------------------
  239|      0|            return -1;
  240|      0|        }
  241|  20.6k|    }
  242|       |
  243|  63.0k|    return 0;
  244|  63.0k|}

zip_source_error:
   38|    198|zip_error_t *zip_source_error(zip_source_t *src) {
   39|    198|    return &src->error;
   40|    198|}

zip_source_free:
   40|   167k|ZIP_EXTERN void zip_source_free(zip_source_t *src) {
   41|   167k|    if (src == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 167k]
  ------------------
   42|      0|        return;
   43|      0|    }
   44|       |
   45|   167k|    if (src->refcount > 0) {
  ------------------
  |  Branch (45:9): [True: 167k, False: 0]
  ------------------
   46|   167k|        src->refcount--;
   47|   167k|    }
   48|   167k|    if (src->refcount > 0) {
  ------------------
  |  Branch (48:9): [True: 44.8k, False: 122k]
  ------------------
   49|  44.8k|        return;
   50|  44.8k|    }
   51|       |
   52|   122k|    if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|   122k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 116, False: 122k]
  |  |  ------------------
  ------------------
   53|    116|        src->open_count = 1; /* force close */
   54|    116|        zip_source_close(src);
   55|    116|    }
   56|   122k|    if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  442|   122k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  |  |  ------------------
  |  |  |  Branch (442:41): [True: 0, False: 122k]
  |  |  ------------------
  ------------------
   57|      0|        zip_source_rollback_write(src);
   58|      0|    }
   59|       |
   60|   122k|    if (src->source_archive && !src->source_closed) {
  ------------------
  |  Branch (60:9): [True: 18.6k, False: 103k]
  |  Branch (60:32): [True: 18.6k, False: 0]
  ------------------
   61|  18.6k|        _zip_deregister_source(src->source_archive, src);
   62|  18.6k|    }
   63|       |
   64|   122k|    (void)_zip_source_call(src, NULL, 0, ZIP_SOURCE_FREE);
   65|       |
   66|   122k|    if (src->src) {
  ------------------
  |  Branch (66:9): [True: 84.3k, False: 38.1k]
  ------------------
   67|  84.3k|        zip_source_free(src->src);
   68|  84.3k|    }
   69|       |
   70|   122k|    free(src);
   71|   122k|}

zip_source_function_create:
   49|  38.1k|ZIP_EXTERN zip_source_t *zip_source_function_create(zip_source_callback zcb, void *ud, zip_error_t *error) {
   50|  38.1k|    zip_source_t *zs;
   51|       |
   52|  38.1k|    if ((zs = _zip_source_new(error)) == NULL) {
  ------------------
  |  Branch (52:9): [True: 0, False: 38.1k]
  ------------------
   53|      0|        return NULL;
   54|      0|    }
   55|       |
   56|  38.1k|    zs->cb.f = zcb;
   57|  38.1k|    zs->ud = ud;
   58|       |
   59|  38.1k|    zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS);
   60|  38.1k|    if (zs->supports < 0) {
  ------------------
  |  Branch (60:9): [True: 0, False: 38.1k]
  ------------------
   61|      0|        zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
  ------------------
  |  |  282|      0|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  283|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  284|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  285|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  286|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  287|      0|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  ------------------
  |  |  |  |  276|      0|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
   62|      0|    }
   63|  38.1k|    zs->supports |= zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, -1);
   64|       |
   65|  38.1k|    return zs;
   66|  38.1k|}
zip_source_keep:
   69|  44.8k|ZIP_EXTERN void zip_source_keep(zip_source_t *src) {
   70|  44.8k|    src->refcount++;
   71|  44.8k|}
_zip_source_new:
   74|   122k|zip_source_t *_zip_source_new(zip_error_t *error) {
   75|   122k|    zip_source_t *src;
   76|       |
   77|   122k|    if ((src = (zip_source_t *)malloc(sizeof(*src))) == NULL) {
  ------------------
  |  Branch (77:9): [True: 0, False: 122k]
  ------------------
   78|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   79|      0|        return NULL;
   80|      0|    }
   81|       |
   82|   122k|    src->src = NULL;
   83|   122k|    src->cb.f = NULL;
   84|   122k|    src->ud = NULL;
   85|   122k|    src->open_count = 0;
   86|   122k|    src->write_state = ZIP_SOURCE_WRITE_CLOSED;
   87|   122k|    src->source_closed = false;
   88|   122k|    src->source_archive = NULL;
   89|   122k|    src->refcount = 1;
   90|   122k|    zip_error_init(&src->error);
   91|   122k|    src->eof = false;
   92|   122k|    src->had_read_error = false;
   93|   122k|    src->bytes_read = 0;
   94|   122k|    src->have_next_byte = false;
   95|       |
   96|   122k|    return src;
   97|   122k|}

zip_source_get_dos_time:
   38|  23.7k|int zip_source_get_dos_time(zip_source_t *src, zip_dostime_t *dos_time) {
   39|  23.7k|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 23.7k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|  23.7k|    if (dos_time == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 23.7k]
  ------------------
   43|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|  23.7k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (47:9): [True: 0, False: 23.7k]
  ------------------
   48|      0|        zip_error_set(&src->error, ZIP_ER_READ, ENOENT);
  ------------------
  |  |  136|      0|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
   49|      0|    }
   50|       |
   51|  23.7k|    if (zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_GET_DOS_TIME)) {
  ------------------
  |  |  276|  23.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (51:9): [True: 1.21k, False: 22.5k]
  ------------------
   52|  1.21k|        zip_int64_t n = _zip_source_call(src, dos_time, sizeof(*dos_time), ZIP_SOURCE_GET_DOS_TIME);
   53|       |
   54|  1.21k|        if (n < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 1.21k]
  ------------------
   55|      0|            return -1;
   56|      0|        }
   57|  1.21k|        else if (n == 0) {
  ------------------
  |  Branch (57:18): [True: 0, False: 1.21k]
  ------------------
   58|      0|            return 0;
   59|      0|        }
   60|  1.21k|        else if (n == sizeof(*dos_time)) {
  ------------------
  |  Branch (60:18): [True: 1.21k, False: 0]
  ------------------
   61|  1.21k|            return 1;
   62|  1.21k|        }
   63|      0|        else {
   64|      0|            zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   65|      0|            return -1;
   66|      0|        }
   67|  1.21k|    }
   68|  22.5k|    else {
   69|  22.5k|        return 0;
   70|  22.5k|    }
   71|  23.7k|}

zip_file_attributes_init:
   36|   309k|ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *attributes) {
   37|   309k|    attributes->valid = 0;
   38|   309k|    attributes->version = 1;
   39|   309k|}
zip_source_get_file_attributes:
   41|   158k|int zip_source_get_file_attributes(zip_source_t *src, zip_file_attributes_t *attributes) {
   42|   158k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 158k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|   158k|    if (attributes == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 158k]
  ------------------
   46|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|   158k|    zip_file_attributes_init(attributes);
   51|       |
   52|   158k|    if (src->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_GET_FILE_ATTRIBUTES)) {
  ------------------
  |  |  276|   158k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (52:9): [True: 102k, False: 56.0k]
  ------------------
   53|   102k|        if (_zip_source_call(src, attributes, sizeof(*attributes), ZIP_SOURCE_GET_FILE_ATTRIBUTES) < 0) {
  ------------------
  |  Branch (53:13): [True: 0, False: 102k]
  ------------------
   54|      0|            return -1;
   55|      0|        }
   56|   102k|    }
   57|       |
   58|   158k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|   158k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 101k, False: 56.9k]
  |  |  ------------------
  ------------------
   59|   101k|        zip_file_attributes_t lower_attributes;
   60|       |
   61|   101k|        zip_file_attributes_init(&lower_attributes);
   62|       |
   63|   101k|        if (zip_source_get_file_attributes(src->src, &lower_attributes) < 0) {
  ------------------
  |  Branch (63:13): [True: 0, False: 101k]
  ------------------
   64|      0|            zip_error_set_from_source(&src->error, src->src);
   65|      0|            return -1;
   66|      0|        }
   67|       |
   68|   101k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) == 0) {
  ------------------
  |  |  362|   101k|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
                      if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) && (attributes->valid & ZIP_FILE_ATTRIBUTES_HOST_SYSTEM) == 0) {
  ------------------
  |  |  362|  2.75k|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
  |  Branch (68:13): [True: 2.75k, False: 98.4k]
  |  Branch (68:75): [True: 2.75k, False: 0]
  ------------------
   69|  2.75k|            attributes->host_system = lower_attributes.host_system;
   70|  2.75k|            attributes->valid |= ZIP_FILE_ATTRIBUTES_HOST_SYSTEM;
  ------------------
  |  |  362|  2.75k|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
   71|  2.75k|        }
   72|   101k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_ASCII) && (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) == 0) {
  ------------------
  |  |  363|   101k|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
                      if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_ASCII) && (attributes->valid & ZIP_FILE_ATTRIBUTES_ASCII) == 0) {
  ------------------
  |  |  363|  2.75k|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
  |  Branch (72:13): [True: 2.75k, False: 98.4k]
  |  Branch (72:69): [True: 2.75k, False: 0]
  ------------------
   73|  2.75k|            attributes->ascii = lower_attributes.ascii;
   74|  2.75k|            attributes->valid |= ZIP_FILE_ATTRIBUTES_ASCII;
  ------------------
  |  |  363|  2.75k|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
   75|  2.75k|        }
   76|   101k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED)) {
  ------------------
  |  |  364|   101k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  |  Branch (76:13): [True: 6.70k, False: 94.5k]
  ------------------
   77|  6.70k|            if (attributes->valid & ZIP_FILE_ATTRIBUTES_VERSION_NEEDED) {
  ------------------
  |  |  364|  6.70k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  |  Branch (77:17): [True: 6.70k, False: 0]
  ------------------
   78|  6.70k|                attributes->version_needed = ZIP_MAX(lower_attributes.version_needed, attributes->version_needed);
  ------------------
  |  |  514|  6.70k|#define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (514:24): [True: 0, False: 6.70k]
  |  |  ------------------
  ------------------
   79|  6.70k|            }
   80|      0|            else {
   81|      0|                attributes->version_needed = lower_attributes.version_needed;
   82|      0|                attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED;
  ------------------
  |  |  364|      0|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
   83|      0|            }
   84|  6.70k|        }
   85|   101k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) == 0) {
  ------------------
  |  |  365|   101k|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
                      if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) && (attributes->valid & ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES) == 0) {
  ------------------
  |  |  365|  2.75k|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
  |  Branch (85:13): [True: 2.75k, False: 98.4k]
  |  Branch (85:88): [True: 2.75k, False: 0]
  ------------------
   86|  2.75k|            attributes->external_file_attributes = lower_attributes.external_file_attributes;
   87|  2.75k|            attributes->valid |= ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES;
  ------------------
  |  |  365|  2.75k|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
   88|  2.75k|        }
   89|   101k|        if ((lower_attributes.valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS)) {
  ------------------
  |  |  366|   101k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  |  Branch (89:13): [True: 9.46k, False: 91.7k]
  ------------------
   90|  9.46k|            if (attributes->valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS) {
  ------------------
  |  |  366|  9.46k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  |  Branch (90:17): [True: 1.72k, False: 7.73k]
  ------------------
   91|       |                /* only take from lower level what is not defined at current level */
   92|  1.72k|                lower_attributes.general_purpose_bit_mask &= ~attributes->general_purpose_bit_mask;
   93|       |
   94|  1.72k|                attributes->general_purpose_bit_flags |= lower_attributes.general_purpose_bit_flags & lower_attributes.general_purpose_bit_mask;
   95|  1.72k|                attributes->general_purpose_bit_mask |= lower_attributes.general_purpose_bit_mask;
   96|  1.72k|            }
   97|  7.73k|            else {
   98|  7.73k|                attributes->valid |= ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  366|  7.73k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
   99|  7.73k|                attributes->general_purpose_bit_flags = lower_attributes.general_purpose_bit_flags;
  100|  7.73k|                attributes->general_purpose_bit_mask = lower_attributes.general_purpose_bit_mask;
  101|  7.73k|            }
  102|  9.46k|        }
  103|   101k|    }
  104|       |
  105|   158k|    return 0;
  106|   158k|}

zip_source_layered:
   40|  33.9k|zip_source_t *zip_source_layered(zip_t *za, zip_source_t *src, zip_source_layered_callback cb, void *ud) {
   41|  33.9k|    if (za == NULL) {
  ------------------
  |  Branch (41:9): [True: 0, False: 33.9k]
  ------------------
   42|      0|        return NULL;
   43|      0|    }
   44|       |
   45|  33.9k|    return zip_source_layered_create(src, cb, ud, &za->error);
   46|  33.9k|}
zip_source_layered_create:
   49|  84.3k|zip_source_t *zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error) {
   50|  84.3k|    zip_source_t *zs;
   51|  84.3k|    zip_int64_t lower_supports, supports;
   52|       |
   53|  84.3k|    lower_supports = zip_source_supports(src);
   54|  84.3k|    supports = cb(src, ud, &lower_supports, sizeof(lower_supports), ZIP_SOURCE_SUPPORTS);
   55|  84.3k|    if (supports < 0) {
  ------------------
  |  Branch (55:9): [True: 0, False: 84.3k]
  ------------------
   56|      0|        zip_error_set(error, ZIP_ER_INVAL, 0); /* Initialize in case cb doesn't return valid error. */
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   57|      0|        cb(src, ud, error, sizeof(*error), ZIP_SOURCE_ERROR);
   58|      0|        return NULL;
   59|      0|    }
   60|       |
   61|  84.3k|    if ((zs = _zip_source_new(error)) == NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 84.3k]
  ------------------
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|  84.3k|    zs->src = src;
   66|  84.3k|    zs->cb.l = cb;
   67|  84.3k|    zs->ud = ud;
   68|  84.3k|    zs->supports = supports;
   69|       |
   70|       |    /* Layered sources can't support writing, since we currently have no use case. If we want to revisit this, we have to define how the two sources interact. */
   71|  84.3k|    zs->supports &= ~(ZIP_SOURCE_SUPPORTS_WRITABLE & ~ZIP_SOURCE_SUPPORTS_SEEKABLE);
  ------------------
  |  |  294|  84.3k|#define ZIP_SOURCE_SUPPORTS_WRITABLE    (ZIP_SOURCE_SUPPORTS_SEEKABLE \
  |  |  ------------------
  |  |  |  |  289|  84.3k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  |  |  ------------------
  |  |  |  |  |  |  282|  84.3k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  284|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  285|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  286|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  287|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  290|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  291|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  292|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  295|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  296|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  297|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  298|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  299|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  300|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  301|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
                  zs->supports &= ~(ZIP_SOURCE_SUPPORTS_WRITABLE & ~ZIP_SOURCE_SUPPORTS_SEEKABLE);
  ------------------
  |  |  289|  84.3k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|  84.3k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|  84.3k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|  84.3k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
   72|       |
   73|  84.3k|    return zs;
   74|  84.3k|}

zip_source_open:
   37|   134k|ZIP_EXTERN int zip_source_open(zip_source_t *src) {
   38|   134k|    if (src->source_closed) {
  ------------------
  |  Branch (38:9): [True: 0, False: 134k]
  ------------------
   39|      0|        return -1;
   40|      0|    }
   41|   134k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (41:9): [True: 198, False: 134k]
  ------------------
   42|    198|        zip_error_set(&src->error, ZIP_ER_DELETED, 0);
  ------------------
  |  |  154|    198|#define ZIP_ER_DELETED 23         /* N Entry has been deleted */
  ------------------
   43|    198|        return -1;
   44|    198|    }
   45|       |
   46|   134k|    if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|   134k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 11.5k, False: 122k]
  |  |  ------------------
  ------------------
   47|  11.5k|        if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) == 0) {
  ------------------
  |  |  276|  11.5k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (47:13): [True: 0, False: 11.5k]
  ------------------
   48|      0|            zip_error_set(&src->error, ZIP_ER_INUSE, 0);
  ------------------
  |  |  160|      0|#define ZIP_ER_INUSE 29           /* N Resource still in use */
  ------------------
   49|      0|            return -1;
   50|      0|        }
   51|  11.5k|    }
   52|   122k|    else {
   53|   122k|        if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|   122k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 84.3k, False: 38.2k]
  |  |  ------------------
  ------------------
   54|  84.3k|            if (zip_source_open(src->src) < 0) {
  ------------------
  |  Branch (54:17): [True: 0, False: 84.3k]
  ------------------
   55|      0|                zip_error_set_from_source(&src->error, src->src);
   56|      0|                return -1;
   57|      0|            }
   58|  84.3k|        }
   59|       |
   60|   122k|        if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_OPEN) < 0) {
  ------------------
  |  Branch (60:13): [True: 0, False: 122k]
  ------------------
   61|      0|            if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|      0|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   62|      0|                zip_source_close(src->src);
   63|      0|            }
   64|      0|            return -1;
   65|      0|        }
   66|   122k|    }
   67|       |
   68|       |    /* TODO: Move the next four lines to into the else branch above, or better yet to zip_source_close()?
   69|       |       They should probably only happen when ZIP_SOURCE_IS_OPEN_READING(src) changes, so other references that have the source open are not affected. */
   70|   134k|    src->eof = false;
   71|   134k|    src->had_read_error = false;
   72|   134k|    _zip_error_clear(&src->error);
   73|   134k|    src->bytes_read = 0;
   74|       |
   75|   134k|    src->open_count++;
   76|       |
   77|   134k|    return 0;
   78|   134k|}

zip_source_pkware_decode:
   53|  1.21k|zip_source_t *zip_source_pkware_decode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password) {
   54|  1.21k|    struct trad_pkware *ctx;
   55|  1.21k|    zip_source_t *s2;
   56|  1.21k|    zip_stat_t st;
   57|       |
   58|  1.21k|    if (password == NULL || src == NULL || em != ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|  1.21k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (58:9): [True: 0, False: 1.21k]
  |  Branch (58:29): [True: 0, False: 1.21k]
  |  Branch (58:44): [True: 0, False: 1.21k]
  ------------------
   59|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   60|      0|        return NULL;
   61|      0|    }
   62|  1.21k|    if (flags & ZIP_CODEC_ENCODE) {
  ------------------
  |  |  115|  1.21k|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (62:9): [True: 0, False: 1.21k]
  ------------------
   63|      0|        zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
   64|      0|        return NULL;
   65|      0|    }
   66|       |
   67|  1.21k|    if (zip_source_stat(src, &st) != 0) {
  ------------------
  |  Branch (67:9): [True: 0, False: 1.21k]
  ------------------
   68|      0|        zip_error_set_from_source(&za->error, src);
   69|      0|        return NULL;
   70|      0|    }
   71|       |
   72|  1.21k|    if ((st.valid & ZIP_STAT_COMP_SIZE) == 0 || st.comp_size < ZIP_CRYPTO_PKWARE_HEADERLEN) {
  ------------------
  |  |  326|  1.21k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                  if ((st.valid & ZIP_STAT_COMP_SIZE) == 0 || st.comp_size < ZIP_CRYPTO_PKWARE_HEADERLEN) {
  ------------------
  |  |   77|  1.21k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (72:9): [True: 0, False: 1.21k]
  |  Branch (72:49): [True: 0, False: 1.21k]
  ------------------
   73|      0|        zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   74|      0|        return NULL;
   75|      0|    }
   76|       |
   77|  1.21k|    if ((ctx = trad_pkware_new(password, &za->error)) == NULL) {
  ------------------
  |  Branch (77:9): [True: 0, False: 1.21k]
  ------------------
   78|      0|        return NULL;
   79|      0|    }
   80|       |
   81|  1.21k|    if ((s2 = zip_source_layered(za, src, pkware_decrypt, ctx)) == NULL) {
  ------------------
  |  Branch (81:9): [True: 0, False: 1.21k]
  ------------------
   82|      0|        trad_pkware_free(ctx);
   83|      0|        return NULL;
   84|      0|    }
   85|       |
   86|  1.21k|    return s2;
   87|  1.21k|}
zip_source_pkware_decode.c:pkware_decrypt:
  139|  10.0k|static zip_int64_t pkware_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  140|  10.0k|    struct trad_pkware *ctx;
  141|  10.0k|    zip_int64_t n;
  142|       |
  143|  10.0k|    ctx = (struct trad_pkware *)ud;
  144|       |
  145|  10.0k|    switch (cmd) {
  146|  1.21k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (146:5): [True: 1.21k, False: 8.86k]
  ------------------
  147|  1.21k|        _zip_pkware_keys_reset(&ctx->keys);
  148|  1.21k|        _zip_pkware_decrypt(&ctx->keys, NULL, (const zip_uint8_t *)ctx->password, strlen(ctx->password));
  149|  1.21k|        if (decrypt_header(src, ctx) < 0) {
  ------------------
  |  Branch (149:13): [True: 0, False: 1.21k]
  ------------------
  150|      0|            return -1;
  151|      0|        }
  152|  1.21k|        return 0;
  153|       |
  154|  2.18k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (154:5): [True: 2.18k, False: 7.89k]
  ------------------
  155|  2.18k|        if ((n = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (155:13): [True: 0, False: 2.18k]
  ------------------
  156|      0|            zip_error_set_from_source(&ctx->error, src);
  157|      0|            return -1;
  158|      0|        }
  159|       |
  160|  2.18k|        _zip_pkware_decrypt(&ctx->keys, (zip_uint8_t *)data, (zip_uint8_t *)data, (zip_uint64_t)n);
  161|  2.18k|        return n;
  162|       |
  163|  1.21k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (163:5): [True: 1.21k, False: 8.86k]
  ------------------
  164|  1.21k|        return 0;
  165|       |
  166|  3.04k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (166:5): [True: 3.04k, False: 7.03k]
  ------------------
  167|  3.04k|        zip_stat_t *st;
  168|       |
  169|  3.04k|        st = (zip_stat_t *)data;
  170|       |
  171|  3.04k|        st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  3.04k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  172|  3.04k|        st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  3.04k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  173|  3.04k|        if (st->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  326|  3.04k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (173:13): [True: 3.04k, False: 0]
  ------------------
  174|  3.04k|            if (st->comp_size < ZIP_CRYPTO_PKWARE_HEADERLEN) {
  ------------------
  |  |   77|  3.04k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (174:17): [True: 0, False: 3.04k]
  ------------------
  175|      0|                zip_error_set(&ctx->error, ZIP_ER_DATA_LENGTH, 0);
  ------------------
  |  |  164|      0|#define ZIP_ER_DATA_LENGTH 33     /* N Unexpected length of data */
  ------------------
  176|      0|                return -1;
  177|      0|            }
  178|  3.04k|            st->comp_size -= ZIP_CRYPTO_PKWARE_HEADERLEN;
  ------------------
  |  |   77|  3.04k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  179|  3.04k|        }
  180|       |
  181|  3.04k|        return 0;
  182|  3.04k|    }
  183|       |
  184|  1.21k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (184:5): [True: 1.21k, False: 8.86k]
  ------------------
  185|  1.21k|        return zip_source_make_command_bitmap(ZIP_SOURCE_AT_EOF, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  186|       |
  187|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (187:5): [True: 0, False: 10.0k]
  ------------------
  188|      0|        return zip_error_to_data(&ctx->error, data, len);
  189|       |
  190|  1.21k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (190:5): [True: 1.21k, False: 8.86k]
  ------------------
  191|  1.21k|        trad_pkware_free(ctx);
  192|  1.21k|        return 0;
  193|       |
  194|      0|    default:
  ------------------
  |  Branch (194:5): [True: 0, False: 10.0k]
  ------------------
  195|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  196|  10.0k|    }
  197|  10.0k|}
zip_source_pkware_decode.c:decrypt_header:
   90|  1.21k|static int decrypt_header(zip_source_t *src, struct trad_pkware *ctx) {
   91|  1.21k|    zip_uint8_t header[ZIP_CRYPTO_PKWARE_HEADERLEN];
   92|  1.21k|    zip_stat_t st;
   93|  1.21k|    zip_dostime_t dostime;
   94|  1.21k|    zip_int64_t n;
   95|       |
   96|  1.21k|    if ((n = zip_source_read(src, header, ZIP_CRYPTO_PKWARE_HEADERLEN)) < 0) {
  ------------------
  |  |   77|  1.21k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (96:9): [True: 0, False: 1.21k]
  ------------------
   97|      0|        zip_error_set_from_source(&ctx->error, src);
   98|      0|        return -1;
   99|      0|    }
  100|       |
  101|  1.21k|    if (n != ZIP_CRYPTO_PKWARE_HEADERLEN) {
  ------------------
  |  |   77|  1.21k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (101:9): [True: 0, False: 1.21k]
  ------------------
  102|      0|        zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  103|      0|        return -1;
  104|      0|    }
  105|       |
  106|  1.21k|    _zip_pkware_decrypt(&ctx->keys, header, header, ZIP_CRYPTO_PKWARE_HEADERLEN);
  ------------------
  |  |   77|  1.21k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  107|       |
  108|  1.21k|    if (zip_source_stat(src, &st) < 0 || (st.valid & ZIP_STAT_CRC) == 0) {
  ------------------
  |  |  328|  1.21k|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (108:9): [True: 0, False: 1.21k]
  |  Branch (108:42): [True: 0, False: 1.21k]
  ------------------
  109|       |        /* skip password validation */
  110|      0|        return 0;
  111|      0|    }
  112|       |
  113|  1.21k|    if (zip_source_get_dos_time(src, &dostime) <= 0) {
  ------------------
  |  Branch (113:9): [True: 0, False: 1.21k]
  ------------------
  114|      0|        if ((st.valid & ZIP_STAT_MTIME) == 0) {
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (114:13): [True: 0, False: 0]
  ------------------
  115|       |            /* no date available, skip password validation */
  116|      0|            return 0;
  117|      0|        }
  118|       |
  119|      0|        if (_zip_u2d_time(st.mtime, &dostime, &ctx->error) < 0) {
  ------------------
  |  Branch (119:13): [True: 0, False: 0]
  ------------------
  120|      0|            return -1;
  121|      0|        }
  122|      0|    }
  123|       |
  124|       |    /*
  125|       |       password verification - two ways:
  126|       |       - mtime - InfoZIP way, to avoid computing complete CRC before encrypting data
  127|       |       - CRC - old PKWare way
  128|       |    */
  129|  1.21k|    if (header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] == dostime.time >> 8 || header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] == st.crc >> 24) {
  ------------------
  |  |   77|  1.21k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
                  if (header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] == dostime.time >> 8 || header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] == st.crc >> 24) {
  ------------------
  |  |   77|      0|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (129:9): [True: 1.21k, False: 0]
  |  Branch (129:73): [True: 0, False: 0]
  ------------------
  130|  1.21k|        return 0;
  131|  1.21k|    }
  132|      0|    else {
  133|      0|        zip_error_set(&ctx->error, ZIP_ER_WRONGPASSWD, 0);
  ------------------
  |  |  158|      0|#define ZIP_ER_WRONGPASSWD 27     /* N Wrong password provided */
  ------------------
  134|      0|        return -1;
  135|      0|    }
  136|  1.21k|}
zip_source_pkware_decode.c:trad_pkware_new:
  200|  1.21k|static struct trad_pkware *trad_pkware_new(const char *password, zip_error_t *error) {
  201|  1.21k|    struct trad_pkware *ctx;
  202|       |
  203|  1.21k|    if ((ctx = (struct trad_pkware *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (203:9): [True: 0, False: 1.21k]
  ------------------
  204|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  205|      0|        return NULL;
  206|      0|    }
  207|       |
  208|  1.21k|    if ((ctx->password = strdup(password)) == NULL) {
  ------------------
  |  Branch (208:9): [True: 0, False: 1.21k]
  ------------------
  209|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  210|      0|        free(ctx);
  211|      0|        return NULL;
  212|      0|    }
  213|       |
  214|  1.21k|    zip_error_init(&ctx->error);
  215|       |
  216|  1.21k|    return ctx;
  217|  1.21k|}
zip_source_pkware_decode.c:trad_pkware_free:
  220|  1.21k|static void trad_pkware_free(struct trad_pkware *ctx) {
  221|  1.21k|    if (ctx == NULL) {
  ------------------
  |  Branch (221:9): [True: 0, False: 1.21k]
  ------------------
  222|      0|        return;
  223|      0|    }
  224|       |
  225|  1.21k|    _zip_crypto_clear(ctx->password, strlen(ctx->password));
  ------------------
  |  |  533|  1.21k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  226|  1.21k|    free(ctx->password);
  227|  1.21k|    free(ctx);
  228|  1.21k|}

zip_source_pkware_encode:
   56|  1.34k|zip_source_t *zip_source_pkware_encode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password) {
   57|  1.34k|    struct trad_pkware *ctx;
   58|  1.34k|    zip_source_t *s2;
   59|       |
   60|  1.34k|    if (password == NULL || src == NULL || em != ZIP_EM_TRAD_PKWARE) {
  ------------------
  |  |  208|  1.34k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  |  Branch (60:9): [True: 0, False: 1.34k]
  |  Branch (60:29): [True: 0, False: 1.34k]
  |  Branch (60:44): [True: 0, False: 1.34k]
  ------------------
   61|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   62|      0|        return NULL;
   63|      0|    }
   64|  1.34k|    if (!(flags & ZIP_CODEC_ENCODE)) {
  ------------------
  |  |  115|  1.34k|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (64:9): [True: 0, False: 1.34k]
  ------------------
   65|      0|        zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
   66|      0|        return NULL;
   67|      0|    }
   68|       |
   69|  1.34k|    if ((ctx = trad_pkware_new(password, &za->error)) == NULL) {
  ------------------
  |  Branch (69:9): [True: 0, False: 1.34k]
  ------------------
   70|      0|        zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   71|      0|        return NULL;
   72|      0|    }
   73|       |
   74|  1.34k|    if (zip_source_get_dos_time(src, &ctx->dostime) <= 0) {
  ------------------
  |  Branch (74:9): [True: 1.34k, False: 0]
  ------------------
   75|  1.34k|        zip_stat_t st;
   76|       |
   77|  1.34k|        if (zip_source_stat(src, &st) < 0) {
  ------------------
  |  Branch (77:13): [True: 0, False: 1.34k]
  ------------------
   78|      0|            zip_error_set_from_source(&za->error, src);
   79|      0|            trad_pkware_free(ctx);
   80|      0|            return NULL;
   81|      0|        }
   82|  1.34k|        if (_zip_u2d_time((st.valid & ZIP_STAT_MTIME) ? st.mtime : time(NULL), &ctx->dostime, &za->error) < 0) {
  ------------------
  |  |  327|  1.34k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (82:13): [True: 0, False: 1.34k]
  |  Branch (82:27): [True: 1.34k, False: 0]
  ------------------
   83|      0|            trad_pkware_free(ctx);
   84|      0|            return NULL;
   85|      0|        }
   86|  1.34k|    }
   87|       |
   88|  1.34k|    if ((s2 = zip_source_layered(za, src, pkware_encrypt, ctx)) == NULL) {
  ------------------
  |  Branch (88:9): [True: 0, False: 1.34k]
  ------------------
   89|      0|        trad_pkware_free(ctx);
   90|      0|        return NULL;
   91|      0|    }
   92|       |
   93|  1.34k|    return s2;
   94|  1.34k|}
zip_source_pkware_encode.c:pkware_encrypt:
  123|  12.0k|static zip_int64_t pkware_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip_source_cmd_t cmd) {
  124|  12.0k|    struct trad_pkware *ctx;
  125|  12.0k|    zip_int64_t n;
  126|  12.0k|    zip_uint64_t buffer_n;
  127|       |
  128|  12.0k|    ctx = (struct trad_pkware *)ud;
  129|       |
  130|  12.0k|    switch (cmd) {
  131|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (131:5): [True: 0, False: 12.0k]
  ------------------
  132|      0|        return ctx->eof;
  133|       |
  134|  1.34k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (134:5): [True: 1.34k, False: 10.7k]
  ------------------
  135|  1.34k|        ctx->eof = false;
  136|       |
  137|       |        /* initialize keys */
  138|  1.34k|        _zip_pkware_keys_reset(&ctx->keys);
  139|  1.34k|        _zip_pkware_encrypt(&ctx->keys, NULL, (const zip_uint8_t *)ctx->password, strlen(ctx->password));
  140|       |
  141|  1.34k|        if (encrypt_header(src, ctx) < 0) {
  ------------------
  |  Branch (141:13): [True: 0, False: 1.34k]
  ------------------
  142|      0|            return -1;
  143|      0|        }
  144|  1.34k|        return 0;
  145|       |
  146|  2.68k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (146:5): [True: 2.68k, False: 9.39k]
  ------------------
  147|  2.68k|        buffer_n = 0;
  148|       |
  149|  2.68k|        if (ctx->buffer) {
  ------------------
  |  Branch (149:13): [True: 1.34k, False: 1.34k]
  ------------------
  150|       |            /* write header values to data */
  151|  1.34k|            buffer_n = _zip_buffer_read(ctx->buffer, data, length);
  152|  1.34k|            data = (zip_uint8_t *)data + buffer_n;
  153|  1.34k|            length -= buffer_n;
  154|       |
  155|  1.34k|            if (_zip_buffer_eof(ctx->buffer)) {
  ------------------
  |  Branch (155:17): [True: 1.34k, False: 0]
  ------------------
  156|  1.34k|                _zip_buffer_free(ctx->buffer);
  157|  1.34k|                ctx->buffer = NULL;
  158|  1.34k|            }
  159|  1.34k|        }
  160|       |
  161|  2.68k|        if (ctx->eof) {
  ------------------
  |  Branch (161:13): [True: 1.34k, False: 1.34k]
  ------------------
  162|  1.34k|            return (zip_int64_t)buffer_n;
  163|  1.34k|        }
  164|       |
  165|  1.34k|        if ((n = zip_source_read(src, data, length)) < 0) {
  ------------------
  |  Branch (165:13): [True: 0, False: 1.34k]
  ------------------
  166|      0|            zip_error_set_from_source(&ctx->error, src);
  167|      0|            return -1;
  168|      0|        }
  169|       |
  170|  1.34k|        _zip_pkware_encrypt(&ctx->keys, (zip_uint8_t *)data, (zip_uint8_t *)data, (zip_uint64_t)n);
  171|       |
  172|  1.34k|        if ((zip_uint64_t)n < length) {
  ------------------
  |  Branch (172:13): [True: 1.34k, False: 0]
  ------------------
  173|  1.34k|            ctx->eof = true;
  174|  1.34k|        }
  175|       |
  176|  1.34k|        return (zip_int64_t)buffer_n + n;
  177|       |
  178|  1.34k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (178:5): [True: 1.34k, False: 10.7k]
  ------------------
  179|  1.34k|        _zip_buffer_free(ctx->buffer);
  180|  1.34k|        ctx->buffer = NULL;
  181|  1.34k|        return 0;
  182|       |
  183|  1.34k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (183:5): [True: 1.34k, False: 10.7k]
  ------------------
  184|  1.34k|        zip_stat_t *st;
  185|       |
  186|  1.34k|        st = (zip_stat_t *)data;
  187|  1.34k|        st->encryption_method = ZIP_EM_TRAD_PKWARE;
  ------------------
  |  |  208|  1.34k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  188|  1.34k|        st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  1.34k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  189|  1.34k|        if (st->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  326|  1.34k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (189:13): [True: 1.34k, False: 0]
  ------------------
  190|  1.34k|            st->comp_size += ZIP_CRYPTO_PKWARE_HEADERLEN;
  ------------------
  |  |   77|  1.34k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  191|  1.34k|        }
  192|       |
  193|  1.34k|        return 0;
  194|  1.34k|    }
  195|       |
  196|  2.68k|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (196:5): [True: 2.68k, False: 9.39k]
  ------------------
  197|  2.68k|        zip_file_attributes_t *attributes = (zip_file_attributes_t *)data;
  198|  2.68k|        if (length < sizeof(*attributes)) {
  ------------------
  |  Branch (198:13): [True: 0, False: 2.68k]
  ------------------
  199|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  200|      0|            return -1;
  201|      0|        }
  202|  2.68k|        attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  364|  2.68k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
                      attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  366|  2.68k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  203|  2.68k|        attributes->version_needed = 20;
  204|  2.68k|        attributes->general_purpose_bit_flags = ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  254|  2.68k|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  205|  2.68k|        attributes->general_purpose_bit_mask = ZIP_GPBF_DATA_DESCRIPTOR;
  ------------------
  |  |  254|  2.68k|#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008u   /* crc/size after file data */
  ------------------
  206|       |
  207|  2.68k|        return 0;
  208|  2.68k|    }
  209|       |
  210|      0|    case ZIP_SOURCE_GET_DOS_TIME:
  ------------------
  |  Branch (210:5): [True: 0, False: 12.0k]
  ------------------
  211|      0|        if (length < sizeof(ctx->dostime)) {
  ------------------
  |  Branch (211:13): [True: 0, False: 0]
  ------------------
  212|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  213|      0|            return -1;
  214|      0|        }
  215|      0|        (void)memcpy_s(data, sizeof(ctx->dostime), &ctx->dostime, sizeof(ctx->dostime));
  ------------------
  |  |  202|      0|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  216|      0|        return sizeof(ctx->dostime);
  217|       |
  218|  1.34k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (218:5): [True: 1.34k, False: 10.7k]
  ------------------
  219|  1.34k|        return zip_source_make_command_bitmap(ZIP_SOURCE_AT_EOF, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_GET_DOS_TIME, -1);
  220|       |
  221|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (221:5): [True: 0, False: 12.0k]
  ------------------
  222|      0|        return zip_error_to_data(&ctx->error, data, length);
  223|       |
  224|  1.34k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (224:5): [True: 1.34k, False: 10.7k]
  ------------------
  225|  1.34k|        trad_pkware_free(ctx);
  226|  1.34k|        return 0;
  227|       |
  228|      0|    default:
  ------------------
  |  Branch (228:5): [True: 0, False: 12.0k]
  ------------------
  229|      0|        return zip_source_pass_to_lower_layer(src, data, length, cmd);
  230|  12.0k|    }
  231|  12.0k|}
zip_source_pkware_encode.c:encrypt_header:
   97|  1.34k|static int encrypt_header(zip_source_t *src, struct trad_pkware *ctx) {
   98|  1.34k|    zip_uint8_t *header;
   99|       |
  100|  1.34k|    if ((ctx->buffer = _zip_buffer_new(NULL, ZIP_CRYPTO_PKWARE_HEADERLEN)) == NULL) {
  ------------------
  |  |   77|  1.34k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (100:9): [True: 0, False: 1.34k]
  ------------------
  101|      0|        zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  102|      0|        return -1;
  103|      0|    }
  104|       |
  105|  1.34k|    header = _zip_buffer_data(ctx->buffer);
  106|       |
  107|       |    /* generate header from random bytes and mtime
  108|       |       see appnote.iz, XIII. Decryption, Step 2, last paragraph */
  109|  1.34k|    if (!zip_secure_random(header, ZIP_CRYPTO_PKWARE_HEADERLEN - 1)) {
  ------------------
  |  |   77|  1.34k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  |  Branch (109:9): [True: 0, False: 1.34k]
  ------------------
  110|      0|        zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  111|      0|        _zip_buffer_free(ctx->buffer);
  112|      0|        ctx->buffer = NULL;
  113|      0|        return -1;
  114|      0|    }
  115|  1.34k|    header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] = (zip_uint8_t)((ctx->dostime.time >> 8) & 0xff);
  ------------------
  |  |   77|  1.34k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  116|       |
  117|  1.34k|    _zip_pkware_encrypt(&ctx->keys, header, header, ZIP_CRYPTO_PKWARE_HEADERLEN);
  ------------------
  |  |   77|  1.34k|#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
  ------------------
  118|       |
  119|  1.34k|    return 0;
  120|  1.34k|}
zip_source_pkware_encode.c:trad_pkware_new:
  234|  1.34k|static struct trad_pkware *trad_pkware_new(const char *password, zip_error_t *error) {
  235|  1.34k|    struct trad_pkware *ctx;
  236|       |
  237|  1.34k|    if ((ctx = (struct trad_pkware *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (237:9): [True: 0, False: 1.34k]
  ------------------
  238|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  239|      0|        return NULL;
  240|      0|    }
  241|       |
  242|  1.34k|    if ((ctx->password = strdup(password)) == NULL) {
  ------------------
  |  Branch (242:9): [True: 0, False: 1.34k]
  ------------------
  243|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  244|      0|        free(ctx);
  245|      0|        return NULL;
  246|      0|    }
  247|  1.34k|    ctx->buffer = NULL;
  248|  1.34k|    zip_error_init(&ctx->error);
  249|       |
  250|  1.34k|    return ctx;
  251|  1.34k|}
zip_source_pkware_encode.c:trad_pkware_free:
  254|  1.34k|static void trad_pkware_free(struct trad_pkware *ctx) {
  255|  1.34k|    if (ctx == NULL) {
  ------------------
  |  Branch (255:9): [True: 0, False: 1.34k]
  ------------------
  256|      0|        return;
  257|      0|    }
  258|       |
  259|  1.34k|    _zip_crypto_clear(ctx->password, strlen(ctx->password));
  ------------------
  |  |  533|  1.34k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  260|  1.34k|    free(ctx->password);
  261|  1.34k|    _zip_buffer_free(ctx->buffer);
  262|  1.34k|    zip_error_fini(&ctx->error);
  263|  1.34k|    free(ctx);
  264|  1.34k|}

zip_source_read:
   38|   211k|zip_int64_t zip_source_read(zip_source_t *src, void *data, zip_uint64_t len) {
   39|   211k|    zip_uint64_t bytes_read;
   40|   211k|    zip_int64_t n;
   41|       |
   42|   211k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 211k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|   211k|    if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
  ------------------
  |  |  441|   423k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
                  if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
  ------------------
  |  |   45|   423k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (45:9): [True: 0, False: 211k]
  |  Branch (45:45): [True: 0, False: 211k]
  |  Branch (45:69): [True: 211k, False: 0]
  |  Branch (45:80): [True: 0, False: 211k]
  ------------------
   46|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|   211k|    if (src->had_read_error) {
  ------------------
  |  Branch (50:9): [True: 114, False: 211k]
  ------------------
   51|    114|        return -1;
   52|    114|    }
   53|       |
   54|   211k|    if (_zip_source_eof(src)) {
  ------------------
  |  Branch (54:9): [True: 43.5k, False: 167k]
  ------------------
   55|  43.5k|        return 0;
   56|  43.5k|    }
   57|       |
   58|   167k|    if (len == 0) {
  ------------------
  |  Branch (58:9): [True: 0, False: 167k]
  ------------------
   59|      0|        return 0;
   60|      0|    }
   61|       |
   62|   167k|    bytes_read = 0;
   63|   167k|    if (src->have_next_byte) {
  ------------------
  |  Branch (63:9): [True: 0, False: 167k]
  ------------------
   64|      0|        ((zip_uint8_t *)data)[0] = src->next_byte;
   65|      0|        bytes_read = 1;
   66|      0|        src->have_next_byte = false;
   67|      0|    }
   68|   291k|    while (bytes_read < len) {
  ------------------
  |  Branch (68:12): [True: 220k, False: 70.7k]
  ------------------
   69|   220k|        if ((n = _zip_source_call(src, (zip_uint8_t *)data + bytes_read, len - bytes_read, ZIP_SOURCE_READ)) < 0) {
  ------------------
  |  Branch (69:13): [True: 116, False: 220k]
  ------------------
   70|    116|            src->had_read_error = true;
   71|    116|            if (bytes_read == 0) {
  ------------------
  |  Branch (71:17): [True: 2, False: 114]
  ------------------
   72|      2|                return -1;
   73|      2|            }
   74|    114|            else {
   75|    114|                return (zip_int64_t)bytes_read;
   76|    114|            }
   77|    116|        }
   78|       |
   79|   220k|        if (n == 0) {
  ------------------
  |  Branch (79:13): [True: 97.0k, False: 123k]
  ------------------
   80|  97.0k|            src->eof = 1;
   81|  97.0k|            break;
   82|  97.0k|        }
   83|       |
   84|   123k|        bytes_read += (zip_uint64_t)n;
   85|   123k|    }
   86|       |
   87|   167k|    if (src->bytes_read + bytes_read < src->bytes_read) {
  ------------------
  |  Branch (87:9): [True: 0, False: 167k]
  ------------------
   88|      0|        src->bytes_read = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   89|      0|    }
   90|   167k|    else {
   91|   167k|        src->bytes_read += bytes_read;
   92|   167k|    }
   93|   167k|    return (zip_int64_t)bytes_read;
   94|   167k|}
_zip_source_eof:
   97|   211k|bool _zip_source_eof(zip_source_t *src) {
   98|   211k|    return src->eof;
   99|   211k|}

zip_source_remove:
   38|    198|int zip_source_remove(zip_source_t *src) {
   39|    198|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|    198|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 198]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|    198|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (44:9): [True: 0, False: 198]
  ------------------
   45|      0|        return 0;
   46|      0|    }
   47|       |
   48|    198|    if (ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|    198|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  |  |  ------------------
  |  |  |  Branch (441:41): [True: 198, False: 0]
  |  |  ------------------
  ------------------
   49|    198|        if (zip_source_close(src) < 0) {
  ------------------
  |  Branch (49:13): [True: 0, False: 198]
  ------------------
   50|      0|            return -1;
   51|      0|        }
   52|    198|    }
   53|    198|    if (src->write_state != ZIP_SOURCE_WRITE_CLOSED) {
  ------------------
  |  Branch (53:9): [True: 0, False: 198]
  ------------------
   54|      0|        zip_source_rollback_write(src);
   55|      0|    }
   56|       |
   57|    198|    if (_zip_source_call(src, NULL, 0, ZIP_SOURCE_REMOVE) < 0) {
  ------------------
  |  Branch (57:9): [True: 0, False: 198]
  ------------------
   58|      0|        return -1;
   59|      0|    }
   60|       |
   61|    198|    src->write_state = ZIP_SOURCE_WRITE_REMOVED;
   62|       |
   63|    198|    return 0;
   64|    198|}

zip_source_seek:
   39|  45.0k|ZIP_EXTERN int zip_source_seek(zip_source_t *src, zip_int64_t offset, int whence) {
   40|  45.0k|    zip_source_args_seek_t args;
   41|       |
   42|  45.0k|    if (src->source_closed) {
  ------------------
  |  Branch (42:9): [True: 0, False: 45.0k]
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|  45.0k|    if (!ZIP_SOURCE_IS_OPEN_READING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
  ------------------
  |  |  441|  90.0k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (45:9): [True: 0, False: 45.0k]
  |  Branch (45:46): [True: 4.78k, False: 40.2k]
  |  Branch (45:68): [True: 4.78k, False: 0]
  |  Branch (45:90): [True: 0, False: 4.78k]
  ------------------
   46|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   47|      0|        return -1;
   48|      0|    }
   49|       |
   50|  45.0k|    args.offset = offset;
   51|  45.0k|    args.whence = whence;
   52|       |
   53|  45.0k|    if (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK) < 0) {
  ------------------
  |  Branch (53:9): [True: 0, False: 45.0k]
  ------------------
   54|      0|        return -1;
   55|      0|    }
   56|       |
   57|       |    /* have_next_byte is never true for sources that support seek. */
   58|  45.0k|    src->eof = 0;
   59|  45.0k|    return 0;
   60|  45.0k|}
zip_source_seek_compute_offset:
   63|  85.6k|zip_int64_t zip_source_seek_compute_offset(zip_uint64_t offset, zip_uint64_t length, void *data, zip_uint64_t data_length, zip_error_t *error) {
   64|  85.6k|    zip_uint64_t new_offset;
   65|  85.6k|    zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, data_length, error);
  ------------------
  |  |  312|  85.6k|#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
  |  |  ------------------
  |  |  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  |  |  ------------------
  |  |  |  Branch (312:54): [True: 0, False: 85.6k]
  |  |  ------------------
  ------------------
   66|       |
   67|  85.6k|    if (args == NULL) {
  ------------------
  |  Branch (67:9): [True: 0, False: 85.6k]
  ------------------
   68|      0|        return -1;
   69|      0|    }
   70|       |
   71|  85.6k|    switch (args->whence) {
   72|      0|    case SEEK_CUR:
  ------------------
  |  Branch (72:5): [True: 0, False: 85.6k]
  ------------------
   73|      0|        new_offset = _zip_offset_add(offset, args->offset);
   74|      0|        break;
   75|       |
   76|  4.78k|    case SEEK_END:
  ------------------
  |  Branch (76:5): [True: 4.78k, False: 80.8k]
  ------------------
   77|  4.78k|        new_offset = _zip_offset_add(length, args->offset);
   78|  4.78k|        break;
   79|       |
   80|  80.8k|    case SEEK_SET:
  ------------------
  |  Branch (80:5): [True: 80.8k, False: 4.78k]
  ------------------
   81|  80.8k|        if (args->offset < 0 || (zip_uint64_t)args->offset > length) {
  ------------------
  |  Branch (81:13): [True: 0, False: 80.8k]
  |  Branch (81:33): [True: 0, False: 80.8k]
  ------------------
   82|      0|            new_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   83|      0|        }
   84|  80.8k|        else {
   85|  80.8k|            new_offset = (zip_uint64_t)args->offset;
   86|  80.8k|        }
   87|  80.8k|        break;
   88|       |
   89|      0|    default:
  ------------------
  |  Branch (89:5): [True: 0, False: 85.6k]
  ------------------
   90|      0|        new_offset = ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   91|  85.6k|    }
   92|       |
   93|  85.6k|    if (new_offset == ZIP_UINT64_MAX) {
  ------------------
  |  |   46|  85.6k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  |  Branch (93:9): [True: 0, False: 85.6k]
  ------------------
   94|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   95|      0|        return -1;
   96|      0|    }
   97|       |
   98|  85.6k|    return (zip_int64_t)new_offset;
   99|  85.6k|}
zip_source_seek.c:_zip_offset_add:
  101|  4.78k|static zip_uint64_t _zip_offset_add(zip_uint64_t offset, zip_int64_t delta) {
  102|  4.78k|    if (delta >= 0) {
  ------------------
  |  Branch (102:9): [True: 0, False: 4.78k]
  ------------------
  103|      0|        zip_uint64_t unsigned_delta = (zip_uint64_t)delta;
  104|       |
  105|      0|        if (offset > ZIP_INT64_MAX - unsigned_delta) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (105:13): [True: 0, False: 0]
  ------------------
  106|      0|            return ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  107|      0|        }
  108|      0|        return offset + unsigned_delta;
  109|      0|    }
  110|  4.78k|    else {
  111|       |        /* Handle ZIP_INT64_MIN without overflowing signed arithmetic. */
  112|  4.78k|        zip_uint64_t unsigned_delta = (zip_uint64_t)(-(delta + 1)) + 1;
  113|       |
  114|  4.78k|        if (offset < unsigned_delta) {
  ------------------
  |  Branch (114:13): [True: 0, False: 4.78k]
  ------------------
  115|      0|            return ZIP_UINT64_MAX;
  ------------------
  |  |   46|      0|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
  116|      0|        }
  117|  4.78k|        return offset - unsigned_delta;
  118|  4.78k|    }
  119|  4.78k|}

zip_source_seek_write:
   38|  40.6k|ZIP_EXTERN int zip_source_seek_write(zip_source_t *src, zip_int64_t offset, int whence) {
   39|  40.6k|    zip_source_args_seek_t args;
   40|       |
   41|  40.6k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|  40.6k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 40.6k]
  |  |  ------------------
  ------------------
   42|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   43|      0|        return -1;
   44|      0|    }
   45|       |
   46|  40.6k|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)) {
  ------------------
  |  |  442|  81.3k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
  |  Branch (46:9): [True: 0, False: 40.6k]
  |  Branch (46:46): [True: 0, False: 40.6k]
  |  Branch (46:68): [True: 0, False: 0]
  |  Branch (46:90): [True: 0, False: 0]
  ------------------
   47|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|  40.6k|    args.offset = offset;
   52|  40.6k|    args.whence = whence;
   53|       |
   54|  40.6k|    return (_zip_source_call(src, &args, sizeof(args), ZIP_SOURCE_SEEK_WRITE) < 0 ? -1 : 0);
  ------------------
  |  Branch (54:13): [True: 0, False: 40.6k]
  ------------------
   55|  40.6k|}

zip_source_stat:
   38|   203k|ZIP_EXTERN int zip_source_stat(zip_source_t *src, zip_stat_t *st) {
   39|   203k|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 203k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|   203k|    if (st == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 203k]
  ------------------
   43|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|   203k|    if (src->write_state == ZIP_SOURCE_WRITE_REMOVED) {
  ------------------
  |  Branch (47:9): [True: 198, False: 202k]
  ------------------
   48|    198|        zip_error_set(&src->error, ZIP_ER_READ, ENOENT);
  ------------------
  |  |  136|    198|#define ZIP_ER_READ 5             /* S Read error */
  ------------------
   49|    198|    }
   50|       |
   51|   203k|    zip_stat_init(st);
   52|       |
   53|   203k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|   203k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 98.4k, False: 104k]
  |  |  ------------------
  ------------------
   54|  98.4k|        if (zip_source_stat(src->src, st) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 98.4k]
  ------------------
   55|      0|            zip_error_set_from_source(&src->error, src->src);
   56|      0|            return -1;
   57|      0|        }
   58|  98.4k|    }
   59|       |
   60|   203k|    if (_zip_source_call(src, st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
  ------------------
  |  Branch (60:9): [True: 0, False: 203k]
  ------------------
   61|      0|        return -1;
   62|      0|    }
   63|       |
   64|   203k|    return 0;
   65|   203k|}

zip_source_supports:
   40|   184k|zip_int64_t zip_source_supports(zip_source_t *src) {
   41|   184k|    return src->supports;
   42|   184k|}
zip_source_make_command_bitmap:
   48|   192k|ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t cmd0, ...) {
   49|   192k|    zip_int64_t bitmap;
   50|   192k|    va_list ap;
   51|       |
   52|   192k|    bitmap = ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd0);
  ------------------
  |  |  276|   192k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
   53|       |
   54|       |
   55|   192k|    va_start(ap, cmd0);
   56|  1.28M|    for (;;) {
   57|  1.28M|        int cmd = va_arg(ap, int);
   58|  1.28M|        if (cmd < 0) {
  ------------------
  |  Branch (58:13): [True: 192k, False: 1.09M]
  ------------------
   59|   192k|            break;
   60|   192k|        }
   61|  1.09M|        bitmap |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd);
  ------------------
  |  |  276|  1.09M|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
   62|  1.09M|    }
   63|   192k|    va_end(ap);
   64|       |
   65|   192k|    return bitmap;
   66|   192k|}

zip_source_tell:
   38|  4.78k|ZIP_EXTERN zip_int64_t zip_source_tell(zip_source_t *src) {
   39|  4.78k|    if (src->source_closed) {
  ------------------
  |  Branch (39:9): [True: 0, False: 4.78k]
  ------------------
   40|      0|        return -1;
   41|      0|    }
   42|  4.78k|    if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
  ------------------
  |  |  441|  4.78k|#define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
  ------------------
  |  Branch (42:9): [True: 0, False: 4.78k]
  ------------------
   43|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|  4.78k|    if ((src->supports & (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK))) == 0) {
  ------------------
  |  |  276|  4.78k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
                  if ((src->supports & (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK))) == 0) {
  ------------------
  |  |  276|  4.78k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (47:9): [True: 0, False: 4.78k]
  ------------------
   48|      0|        if (src->bytes_read > ZIP_INT64_MAX) {
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (48:13): [True: 0, False: 0]
  ------------------
   49|      0|            zip_error_set(&src->error, ZIP_ER_TELL, EOVERFLOW);
  ------------------
  |  |  161|      0|#define ZIP_ER_TELL 30            /* S Tell error */
  ------------------
   50|      0|            return -1;
   51|      0|        }
   52|      0|        return (zip_int64_t)src->bytes_read;
   53|      0|    }
   54|       |
   55|  4.78k|    return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL);
   56|  4.78k|}

zip_source_tell_write:
   38|   104k|ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *src) {
   39|   104k|    if (ZIP_SOURCE_IS_LAYERED(src)) {
  ------------------
  |  |  443|   104k|#define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL)
  |  |  ------------------
  |  |  |  Branch (443:36): [True: 0, False: 104k]
  |  |  ------------------
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|   104k|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
  ------------------
  |  |  442|   104k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
  |  Branch (44:9): [True: 0, False: 104k]
  ------------------
   45|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   46|      0|        return -1;
   47|      0|    }
   48|       |
   49|   104k|    return _zip_source_call(src, NULL, 0, ZIP_SOURCE_TELL_WRITE);
   50|   104k|}

_zip_source_window_new:
   68|  18.7k|zip_source_t *_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_int64_t length, zip_stat_t *st, zip_uint64_t st_invalid, zip_file_attributes_t *attributes, zip_dostime_t *dostime, zip_t *source_archive, zip_uint64_t source_index, bool take_ownership, zip_error_t *error) {
   69|  18.7k|    zip_source_t *window_source;
   70|  18.7k|    struct window *ctx;
   71|       |
   72|  18.7k|    if (src == NULL || length < -1 || (source_archive == NULL && source_index != 0)) {
  ------------------
  |  Branch (72:9): [True: 0, False: 18.7k]
  |  Branch (72:24): [True: 0, False: 18.7k]
  |  Branch (72:40): [True: 7.34k, False: 11.3k]
  |  Branch (72:66): [True: 0, False: 7.34k]
  ------------------
   73|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   74|      0|        return NULL;
   75|      0|    }
   76|       |
   77|  18.7k|    if (length >= 0) {
  ------------------
  |  Branch (77:9): [True: 18.7k, False: 0]
  ------------------
   78|  18.7k|        if (start + (zip_uint64_t)length < start) {
  ------------------
  |  Branch (78:13): [True: 0, False: 18.7k]
  ------------------
   79|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   80|      0|            return NULL;
   81|      0|        }
   82|  18.7k|    }
   83|       |
   84|  18.7k|    if ((ctx = (struct window *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (84:9): [True: 0, False: 18.7k]
  ------------------
   85|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
   86|      0|        return NULL;
   87|      0|    }
   88|       |
   89|  18.7k|    ctx->start = start;
   90|  18.7k|    if (length == -1) {
  ------------------
  |  Branch (90:9): [True: 0, False: 18.7k]
  ------------------
   91|      0|        ctx->end_valid = false;
   92|      0|    }
   93|  18.7k|    else {
   94|  18.7k|        ctx->end = start + (zip_uint64_t)length;
   95|  18.7k|        ctx->end_valid = true;
   96|  18.7k|    }
   97|  18.7k|    zip_stat_init(&ctx->stat);
   98|  18.7k|    ctx->stat_invalid = st_invalid;
   99|  18.7k|    if (attributes != NULL) {
  ------------------
  |  Branch (99:9): [True: 18.6k, False: 116]
  ------------------
  100|  18.6k|        (void)memcpy_s(&ctx->attributes, sizeof(ctx->attributes), attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|  18.6k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  101|  18.6k|    }
  102|    116|    else {
  103|    116|        zip_file_attributes_init(&ctx->attributes);
  104|    116|    }
  105|  18.7k|    if (dostime != NULL) {
  ------------------
  |  Branch (105:9): [True: 18.6k, False: 116]
  ------------------
  106|  18.6k|        ctx->dostime = *dostime;
  107|  18.6k|        ctx->dostime_valid = true;
  108|  18.6k|    }
  109|    116|    else {
  110|    116|        ctx->dostime_valid = false;
  111|    116|    }
  112|  18.7k|    ctx->source_archive = source_archive;
  113|  18.7k|    ctx->source_index = source_index;
  114|  18.7k|    zip_error_init(&ctx->error);
  115|  18.7k|    ctx->supports = (zip_source_supports(src) & (ZIP_SOURCE_SUPPORTS_SEEKABLE | ZIP_SOURCE_SUPPORTS_REOPEN)) | (zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_GET_DOS_TIME, ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, ZIP_SOURCE_FREE, -1));
  ------------------
  |  |  289|  18.7k|#define ZIP_SOURCE_SUPPORTS_SEEKABLE	(ZIP_SOURCE_SUPPORTS_READABLE \
  |  |  ------------------
  |  |  |  |  282|  18.7k|#define ZIP_SOURCE_SUPPORTS_READABLE	(ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  283|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  284|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  285|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  286|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  |  |  287|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
  |  |  |  |  ------------------
  |  |  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  290|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
  |  |  ------------------
  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  291|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
  |  |  ------------------
  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  |  |  292|  18.7k|                                         | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
  |  |  ------------------
  |  |  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  |  |  ------------------
  ------------------
  116|  18.7k|    if (ctx->end_valid) {
  ------------------
  |  Branch (116:9): [True: 18.7k, False: 0]
  ------------------
  117|  18.7k|        ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_AT_EOF);
  ------------------
  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  118|  18.7k|    }
  119|  18.7k|    ctx->needs_seek = (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK)) ? true : false;
  ------------------
  |  |  276|  18.7k|#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
  ------------------
  |  Branch (119:23): [True: 18.7k, False: 0]
  ------------------
  120|       |
  121|  18.7k|    if (st) {
  ------------------
  |  Branch (121:9): [True: 18.7k, False: 0]
  ------------------
  122|  18.7k|        if (_zip_stat_merge(&ctx->stat, st, error) < 0) {
  ------------------
  |  Branch (122:13): [True: 0, False: 18.7k]
  ------------------
  123|      0|            free(ctx);
  124|      0|            return NULL;
  125|      0|        }
  126|  18.7k|    }
  127|       |
  128|  18.7k|    window_source = zip_source_layered_create(src, window_read, ctx, error);
  129|  18.7k|    if (window_source == NULL) {
  ------------------
  |  Branch (129:9): [True: 0, False: 18.7k]
  ------------------
  130|      0|        free(ctx);
  131|      0|        return NULL;
  132|      0|    }
  133|  18.7k|    if (!take_ownership) {
  ------------------
  |  Branch (133:9): [True: 11.5k, False: 7.22k]
  ------------------
  134|  11.5k|        zip_source_keep(src);
  135|  11.5k|    }
  136|  18.7k|    return window_source;
  137|  18.7k|}
_zip_source_set_source_archive:
  140|  18.6k|int _zip_source_set_source_archive(zip_source_t *src, zip_t *za) {
  141|  18.6k|    src->source_archive = za;
  142|  18.6k|    return _zip_register_source(za, src);
  143|  18.6k|}
_zip_deregister_source:
  371|  18.6k|void _zip_deregister_source(zip_t *za, zip_source_t *src) {
  372|  18.6k|    zip_uint64_t i;
  373|       |
  374|  18.6k|    for (i = 0; i < za->nopen_source; i++) {
  ------------------
  |  Branch (374:17): [True: 18.6k, False: 0]
  ------------------
  375|  18.6k|        if (za->open_source[i] == src) {
  ------------------
  |  Branch (375:13): [True: 18.6k, False: 0]
  ------------------
  376|  18.6k|            za->open_source[i] = za->open_source[za->nopen_source - 1];
  377|  18.6k|            za->nopen_source--;
  378|  18.6k|            break;
  379|  18.6k|        }
  380|  18.6k|    }
  381|  18.6k|}
_zip_register_source:
  384|  18.6k|int _zip_register_source(zip_t *za, zip_source_t *src) {
  385|  18.6k|    if (za->nopen_source + 1 >= za->nopen_source_alloc) {
  ------------------
  |  Branch (385:9): [True: 2.63k, False: 15.9k]
  ------------------
  386|  2.63k|        if (!ZIP_REALLOC(za->open_source, za->nopen_source_alloc, 10, &za->error)) {
  ------------------
  |  |  107|  2.63k|#define ZIP_REALLOC(memory, alloced_elements, additional_elements, error) zip_realloc((void **)&memory, &alloced_elements, sizeof(*memory), additional_elements, error)
  ------------------
  |  Branch (386:13): [True: 0, False: 2.63k]
  ------------------
  387|      0|            return -1;
  388|      0|        }
  389|  2.63k|    }
  390|       |
  391|  18.6k|    za->open_source[za->nopen_source++] = src;
  392|       |
  393|  18.6k|    return 0;
  394|  18.6k|}
zip_source_window.c:window_read:
  156|   153k|static zip_int64_t window_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  157|   153k|    struct window *ctx;
  158|   153k|    zip_int64_t ret;
  159|   153k|    zip_uint64_t n, i;
  160|       |
  161|   153k|    ctx = (struct window *)_ctx;
  162|       |
  163|   153k|    switch (cmd) {
  164|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (164:5): [True: 0, False: 153k]
  ------------------
  165|      0|        if (ctx->end_valid) {
  ------------------
  |  Branch (165:13): [True: 0, False: 0]
  ------------------
  166|      0|            return ctx->offset == ctx->end;
  167|      0|        }
  168|      0|        else {
  169|      0|            return zip_source_pass_to_lower_layer(src, data, len, cmd);
  170|      0|        }
  171|       |
  172|  18.7k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (172:5): [True: 18.7k, False: 135k]
  ------------------
  173|  18.7k|        return 0;
  174|       |
  175|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (175:5): [True: 0, False: 153k]
  ------------------
  176|      0|        return zip_error_to_data(&ctx->error, data, len);
  177|       |
  178|  18.7k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (178:5): [True: 18.7k, False: 135k]
  ------------------
  179|  18.7k|        free(ctx);
  180|  18.7k|        return 0;
  181|       |
  182|  18.7k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (182:5): [True: 18.7k, False: 135k]
  ------------------
  183|  18.7k|        if (ctx->source_archive) {
  ------------------
  |  Branch (183:13): [True: 11.3k, False: 7.34k]
  ------------------
  184|  11.3k|            zip_uint64_t offset;
  185|       |
  186|  11.3k|            if ((offset = _zip_file_get_offset(ctx->source_archive, ctx->source_index, &ctx->error)) == 0) {
  ------------------
  |  Branch (186:17): [True: 0, False: 11.3k]
  ------------------
  187|      0|                return -1;
  188|      0|            }
  189|  11.3k|            if (ctx->end_valid) {
  ------------------
  |  Branch (189:17): [True: 11.3k, False: 0]
  ------------------
  190|  11.3k|                if (ctx->end + offset < ctx->end) {
  ------------------
  |  Branch (190:21): [True: 0, False: 11.3k]
  ------------------
  191|       |                    /* zip archive data claims end of data past zip64 limits */
  192|      0|                    zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, ctx->source_index));
  ------------------
  |  |  152|      0|#define ZIP_ER_INCONS 21          /* L Zip archive inconsistent */
  ------------------
                                  zip_error_set(&ctx->error, ZIP_ER_INCONS, MAKE_DETAIL_WITH_INDEX(ZIP_ER_DETAIL_CDIR_ENTRY_INVALID, ctx->source_index));
  ------------------
  |  |  215|      0|#define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |               #define MAKE_DETAIL_WITH_INDEX(error, index) ((((index) > MAX_DETAIL_INDEX) ? MAX_DETAIL_INDEX : (int)(index)) << 8 | (error))
  |  |  ------------------
  |  |  |  |  214|      0|#define MAX_DETAIL_INDEX 0x7fffff
  |  |  ------------------
  |  |  |  Branch (215:48): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  193|      0|                    return -1;
  194|      0|                }
  195|  11.3k|                ctx->end += offset;
  196|  11.3k|            }
  197|  11.3k|            ctx->start += offset;
  198|  11.3k|            ctx->source_archive = NULL;
  199|  11.3k|        }
  200|       |
  201|  18.7k|        if (!ctx->needs_seek) {
  ------------------
  |  Branch (201:13): [True: 0, False: 18.7k]
  ------------------
  202|      0|            DEFINE_BYTE_ARRAY(b, BUFSIZE);
  ------------------
  |  |  477|      0|#define DEFINE_BYTE_ARRAY(buf, size) zip_uint8_t buf[size]
  ------------------
  203|       |
  204|      0|            if (!byte_array_init(b, BUFSIZE)) {
  ------------------
  |  |  478|      0|#define byte_array_init(buf, size) (1)
  ------------------
  |  Branch (204:17): [Folded, False: 0]
  ------------------
  205|      0|                zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  206|      0|                return -1;
  207|      0|            }
  208|       |
  209|      0|            for (n = 0; n < ctx->start; n += (zip_uint64_t)ret) {
  ------------------
  |  Branch (209:25): [True: 0, False: 0]
  ------------------
  210|      0|                i = (ctx->start - n > BUFSIZE ? BUFSIZE : ctx->start - n);
  ------------------
  |  |   66|      0|#define BUFSIZE 8192
  ------------------
                              i = (ctx->start - n > BUFSIZE ? BUFSIZE : ctx->start - n);
  ------------------
  |  |   66|      0|#define BUFSIZE 8192
  ------------------
  |  Branch (210:22): [True: 0, False: 0]
  ------------------
  211|      0|                if ((ret = zip_source_read(src, b, i)) < 0) {
  ------------------
  |  Branch (211:21): [True: 0, False: 0]
  ------------------
  212|      0|                    zip_error_set_from_source(&ctx->error, src);
  213|      0|                    byte_array_fini(b);
  ------------------
  |  |  479|      0|#define byte_array_fini(buf) ((void)0)
  ------------------
  214|      0|                    return -1;
  215|      0|                }
  216|      0|                if (ret == 0) {
  ------------------
  |  Branch (216:21): [True: 0, False: 0]
  ------------------
  217|      0|                    zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  218|      0|                    byte_array_fini(b);
  ------------------
  |  |  479|      0|#define byte_array_fini(buf) ((void)0)
  ------------------
  219|      0|                    return -1;
  220|      0|                }
  221|      0|            }
  222|       |
  223|      0|            byte_array_fini(b);
  ------------------
  |  |  479|      0|#define byte_array_fini(buf) ((void)0)
  ------------------
  224|      0|        }
  225|       |
  226|  18.7k|        ctx->offset = ctx->start;
  227|  18.7k|        return 0;
  228|       |
  229|  38.8k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (229:5): [True: 38.8k, False: 114k]
  ------------------
  230|  38.8k|        if (ctx->end_valid && len > ctx->end - ctx->offset) {
  ------------------
  |  Branch (230:13): [True: 38.8k, False: 0]
  |  Branch (230:31): [True: 13.3k, False: 25.4k]
  ------------------
  231|  13.3k|            len = ctx->end - ctx->offset;
  232|  13.3k|        }
  233|       |
  234|  38.8k|        if (len == 0) {
  ------------------
  |  Branch (234:13): [True: 10.4k, False: 28.4k]
  ------------------
  235|  10.4k|            return 0;
  236|  10.4k|        }
  237|       |
  238|  28.4k|        if (ctx->needs_seek) {
  ------------------
  |  Branch (238:13): [True: 28.4k, False: 0]
  ------------------
  239|  28.4k|            if (zip_source_seek(src, (zip_int64_t)ctx->offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (239:17): [True: 0, False: 28.4k]
  ------------------
  240|      0|                zip_error_set_from_source(&ctx->error, src);
  241|      0|                return -1;
  242|      0|            }
  243|  28.4k|        }
  244|       |
  245|  28.4k|        if ((ret = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (245:13): [True: 0, False: 28.4k]
  ------------------
  246|      0|            zip_error_set_from_source(&ctx->error, src);
  247|      0|            return -1;
  248|      0|        }
  249|       |
  250|  28.4k|        if (ret == 0) {
  ------------------
  |  Branch (250:13): [True: 0, False: 28.4k]
  ------------------
  251|      0|            if (ctx->end_valid && ctx->offset < ctx->end) {
  ------------------
  |  Branch (251:17): [True: 0, False: 0]
  |  Branch (251:35): [True: 0, False: 0]
  ------------------
  252|      0|                zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  253|      0|                return -1;
  254|      0|            }
  255|      0|        }
  256|       |
  257|  28.4k|        ctx->offset += (zip_uint64_t)ret;
  258|  28.4k|        return ret;
  259|       |
  260|      0|    case ZIP_SOURCE_SEEK: {
  ------------------
  |  Branch (260:5): [True: 0, False: 153k]
  ------------------
  261|      0|        zip_uint64_t length;
  262|      0|        zip_int64_t new_offset;
  263|      0|        zip_source_args_seek_t *args = ZIP_SOURCE_GET_ARGS(zip_source_args_seek_t, data, len, &ctx->error);
  ------------------
  |  |  312|      0|#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
  |  |  ------------------
  |  |  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  |  |  ------------------
  |  |  |  Branch (312:54): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  264|       |
  265|       |        /*
  266|       |          If we don't know the length and seek from the end, we seek in the lower source to get the new offset.
  267|       |        */
  268|      0|        if (!ctx->end_valid && args->whence == SEEK_END) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  |  Branch (268:32): [True: 0, False: 0]
  ------------------
  269|      0|            zip_int64_t lower_offset;
  270|       |
  271|      0|            if (zip_source_seek(src, args->offset, args->whence) < 0) {
  ------------------
  |  Branch (271:17): [True: 0, False: 0]
  ------------------
  272|      0|                zip_error_set_from_source(&ctx->error, src);
  273|      0|                return -1;
  274|      0|            }
  275|      0|            if ((lower_offset = zip_source_tell(src)) < 0) {
  ------------------
  |  Branch (275:17): [True: 0, False: 0]
  ------------------
  276|      0|                zip_error_set_from_source(&ctx->error, src);
  277|      0|                return -1;
  278|      0|            }
  279|      0|            if ((zip_uint64_t)lower_offset < ctx->start) {
  ------------------
  |  Branch (279:17): [True: 0, False: 0]
  ------------------
  280|      0|                zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  281|      0|                return -1;
  282|      0|            }
  283|      0|            ctx->offset = (zip_uint64_t)lower_offset;
  284|      0|            return 0;
  285|      0|        }
  286|       |
  287|       |        /* 
  288|       |          If we don't know the length, we disable the end check in zip_source_seek_compute_offset by passing in the largest possible value and seek in the lower source to validate the new offset.
  289|       |        */
  290|      0|        length = ctx->end_valid ? (ctx->end - ctx->start) : ZIP_INT64_MAX;
  ------------------
  |  |   45|      0|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (290:18): [True: 0, False: 0]
  ------------------
  291|      0|        new_offset = zip_source_seek_compute_offset(ctx->offset - ctx->start, length, data, len, &ctx->error);
  292|       |
  293|      0|        if (new_offset < 0) {
  ------------------
  |  Branch (293:13): [True: 0, False: 0]
  ------------------
  294|      0|            return -1;
  295|      0|        }
  296|       |
  297|      0|        if (new_offset + ctx->start < ctx->start) {
  ------------------
  |  Branch (297:13): [True: 0, False: 0]
  ------------------
  298|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  299|      0|            return -1;
  300|      0|        }
  301|      0|        new_offset += ctx->start;
  302|       |
  303|      0|        if (!ctx->end_valid) {
  ------------------
  |  Branch (303:13): [True: 0, False: 0]
  ------------------
  304|      0|            if (zip_source_seek(src, new_offset, SEEK_SET) < 0) {
  ------------------
  |  Branch (304:17): [True: 0, False: 0]
  ------------------
  305|      0|                zip_error_set_from_source(&ctx->error, src);
  306|      0|                return -1;
  307|      0|            }
  308|      0|        }
  309|      0|        ctx->offset = (zip_uint64_t)new_offset;
  310|      0|        return 0;
  311|      0|    }
  312|       |
  313|  35.2k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (313:5): [True: 35.2k, False: 118k]
  ------------------
  314|  35.2k|        zip_stat_t *st;
  315|       |
  316|  35.2k|        st = (zip_stat_t *)data;
  317|       |
  318|  35.2k|        if (_zip_stat_merge(st, &ctx->stat, &ctx->error) < 0) {
  ------------------
  |  Branch (318:13): [True: 0, False: 35.2k]
  ------------------
  319|      0|            return -1;
  320|      0|        }
  321|       |
  322|  35.2k|        if (!(ctx->stat.valid & ZIP_STAT_SIZE)) {
  ------------------
  |  |  325|  35.2k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (322:13): [True: 0, False: 35.2k]
  ------------------
  323|      0|            if (ctx->end_valid) {
  ------------------
  |  Branch (323:17): [True: 0, False: 0]
  ------------------
  324|      0|                st->valid |= ZIP_STAT_SIZE;
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  325|      0|                st->size = ctx->end - ctx->start;
  326|      0|            }
  327|      0|            else if (st->valid & ZIP_STAT_SIZE) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (327:22): [True: 0, False: 0]
  ------------------
  328|      0|                st->size -= ctx->start;
  329|      0|            }
  330|      0|        }
  331|       |
  332|  35.2k|        st->valid &= ~ctx->stat_invalid;
  333|       |
  334|  35.2k|        return 0;
  335|  35.2k|    }
  336|       |
  337|  3.61k|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES:
  ------------------
  |  Branch (337:5): [True: 3.61k, False: 150k]
  ------------------
  338|  3.61k|        if (len < sizeof(ctx->attributes)) {
  ------------------
  |  Branch (338:13): [True: 0, False: 3.61k]
  ------------------
  339|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  340|      0|            return -1;
  341|      0|        }
  342|       |
  343|  3.61k|        (void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
  ------------------
  |  |  202|  3.61k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  344|  3.61k|        return sizeof(ctx->attributes);
  345|       |
  346|  1.21k|    case ZIP_SOURCE_GET_DOS_TIME:
  ------------------
  |  Branch (346:5): [True: 1.21k, False: 152k]
  ------------------
  347|  1.21k|        if (len < sizeof(ctx->dostime)) {
  ------------------
  |  Branch (347:13): [True: 0, False: 1.21k]
  ------------------
  348|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  349|      0|            return -1;
  350|      0|        }
  351|  1.21k|        if (ctx->dostime_valid) {
  ------------------
  |  Branch (351:13): [True: 1.21k, False: 0]
  ------------------
  352|  1.21k|            (void)memcpy_s(data, sizeof(ctx->dostime), &ctx->dostime, sizeof(ctx->dostime));
  ------------------
  |  |  202|  1.21k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  353|  1.21k|            return sizeof(ctx->dostime);
  354|  1.21k|        }
  355|      0|        else {
  356|      0|            return 0;
  357|      0|        }
  358|       |
  359|  18.7k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (359:5): [True: 18.7k, False: 135k]
  ------------------
  360|  18.7k|        return ctx->supports;
  361|       |
  362|      0|    case ZIP_SOURCE_TELL:
  ------------------
  |  Branch (362:5): [True: 0, False: 153k]
  ------------------
  363|      0|        return (zip_int64_t)(ctx->offset - ctx->start);
  364|       |
  365|      0|    default:
  ------------------
  |  Branch (365:5): [True: 0, False: 153k]
  ------------------
  366|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  367|   153k|    }
  368|   153k|}

zip_source_winzip_aes_decode:
   61|  8.31k|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) {
   62|  8.31k|    zip_source_t *s2;
   63|  8.31k|    zip_stat_t st;
   64|  8.31k|    zip_uint64_t aux_length;
   65|  8.31k|    struct winzip_aes *ctx;
   66|       |
   67|  8.31k|    if ((encryption_method != ZIP_EM_AES_128 && encryption_method != ZIP_EM_AES_192 && encryption_method != ZIP_EM_AES_256) || password == NULL || src == NULL) {
  ------------------
  |  |  220|  16.6k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
                  if ((encryption_method != ZIP_EM_AES_128 && encryption_method != ZIP_EM_AES_192 && encryption_method != ZIP_EM_AES_256) || password == NULL || src == NULL) {
  ------------------
  |  |  221|  14.6k|#define ZIP_EM_AES_192 0x0102
  ------------------
                  if ((encryption_method != ZIP_EM_AES_128 && encryption_method != ZIP_EM_AES_192 && encryption_method != ZIP_EM_AES_256) || password == NULL || src == NULL) {
  ------------------
  |  |  222|  6.35k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (67:10): [True: 6.35k, False: 1.95k]
  |  Branch (67:49): [True: 6.35k, False: 0]
  |  Branch (67:88): [True: 0, False: 6.35k]
  |  Branch (67:128): [True: 0, False: 8.31k]
  |  Branch (67:148): [True: 0, False: 8.31k]
  ------------------
   68|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   69|      0|        return NULL;
   70|      0|    }
   71|  8.31k|    if (flags & ZIP_CODEC_ENCODE) {
  ------------------
  |  |  115|  8.31k|#define ZIP_CODEC_ENCODE 1 /* compress/encrypt */
  ------------------
  |  Branch (71:9): [True: 0, False: 8.31k]
  ------------------
   72|      0|        zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
   73|      0|        return NULL;
   74|      0|    }
   75|       |
   76|  8.31k|    if (zip_source_stat(src, &st) != 0) {
  ------------------
  |  Branch (76:9): [True: 0, False: 8.31k]
  ------------------
   77|      0|        zip_error_set_from_source(&za->error, src);
   78|      0|        return NULL;
   79|      0|    }
   80|       |
   81|  8.31k|    aux_length = WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(encryption_method) + HMAC_LENGTH;
  ------------------
  |  |   81|  8.31k|#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
  ------------------
                  aux_length = WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(encryption_method) + HMAC_LENGTH;
  ------------------
  |  |   85|  8.31k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  8.31k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|  6.35k|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.95k, False: 6.35k]
  |  |  |  Branch (85:64): [True: 0, False: 6.35k]
  |  |  ------------------
  ------------------
                  aux_length = WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(encryption_method) + HMAC_LENGTH;
  ------------------
  |  |   84|  8.31k|#define HMAC_LENGTH 10
  ------------------
   82|       |
   83|  8.31k|    if ((st.valid & ZIP_STAT_COMP_SIZE) == 0 || st.comp_size < aux_length) {
  ------------------
  |  |  326|  8.31k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (83:9): [True: 0, False: 8.31k]
  |  Branch (83:49): [True: 0, False: 8.31k]
  ------------------
   84|      0|        zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0);
  ------------------
  |  |  159|      0|#define ZIP_ER_OPNOTSUPP 28       /* N Operation not supported */
  ------------------
   85|      0|        return NULL;
   86|      0|    }
   87|       |
   88|  8.31k|    if ((ctx = winzip_aes_new(encryption_method, password, &za->error)) == NULL) {
  ------------------
  |  Branch (88:9): [True: 0, False: 8.31k]
  ------------------
   89|      0|        return NULL;
   90|      0|    }
   91|       |
   92|  8.31k|    ctx->data_length = st.comp_size - aux_length;
   93|       |
   94|  8.31k|    if ((s2 = zip_source_layered(za, src, winzip_aes_decrypt, ctx)) == NULL) {
  ------------------
  |  Branch (94:9): [True: 0, False: 8.31k]
  ------------------
   95|      0|        winzip_aes_free(ctx);
   96|      0|        return NULL;
   97|      0|    }
   98|       |
   99|  8.31k|    return s2;
  100|  8.31k|}
zip_source_winzip_aes_decode.c:winzip_aes_decrypt:
  159|  51.5k|static zip_int64_t winzip_aes_decrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
  160|  51.5k|    struct winzip_aes *ctx;
  161|  51.5k|    zip_int64_t n;
  162|       |
  163|  51.5k|    ctx = (struct winzip_aes *)ud;
  164|       |
  165|  51.5k|    switch (cmd) {
  166|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (166:5): [True: 0, False: 51.5k]
  ------------------
  167|      0|        return ctx->current_position == ctx->data_length;
  168|       |
  169|  8.31k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (169:5): [True: 8.31k, False: 43.2k]
  ------------------
  170|  8.31k|        ctx->hmac_verify_failed = false;
  171|  8.31k|        if (decrypt_header(src, ctx) < 0) {
  ------------------
  |  Branch (171:13): [True: 0, False: 8.31k]
  ------------------
  172|      0|            return -1;
  173|      0|        }
  174|  8.31k|        ctx->current_position = 0;
  175|  8.31k|        return 0;
  176|       |
  177|  16.1k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (177:5): [True: 16.1k, False: 35.3k]
  ------------------
  178|  16.1k|        len = ZIP_MIN(len, ctx->data_length - ctx->current_position);
  ------------------
  |  |  515|  16.1k|#define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (515:24): [True: 0, False: 16.1k]
  |  |  ------------------
  ------------------
  179|       |
  180|  16.1k|        if (len > 0) {
  ------------------
  |  Branch (180:13): [True: 7.82k, False: 8.31k]
  ------------------
  181|  7.82k|            if ((n = zip_source_read(src, data, len)) < 0) {
  ------------------
  |  Branch (181:17): [True: 0, False: 7.82k]
  ------------------
  182|      0|                zip_error_set_from_source(&ctx->error, src);
  183|      0|                return -1;
  184|      0|            }
  185|       |
  186|  7.82k|            if (n == 0) {
  ------------------
  |  Branch (186:17): [True: 0, False: 7.82k]
  ------------------
  187|      0|                zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  188|      0|                return -1;
  189|      0|            }
  190|       |
  191|  7.82k|            ctx->current_position += (zip_uint64_t)n;
  192|       |
  193|  7.82k|            if (!_zip_winzip_aes_decrypt(ctx->aes_ctx, (zip_uint8_t *)data, (zip_uint64_t)n)) {
  ------------------
  |  Branch (193:17): [True: 0, False: 7.82k]
  ------------------
  194|      0|                zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  195|      0|                return -1;
  196|      0|            }
  197|       |
  198|  7.82k|            if (ctx->current_position == ctx->data_length) {
  ------------------
  |  Branch (198:17): [True: 7.82k, False: 0]
  ------------------
  199|  7.82k|                verify_hmac(src, ctx);
  200|  7.82k|            }
  201|       |
  202|  7.82k|            return n;
  203|  7.82k|        }
  204|  8.31k|        else {
  205|  8.31k|            return ctx->hmac_verify_failed ? -1 : 0;
  ------------------
  |  Branch (205:20): [True: 0, False: 8.31k]
  ------------------
  206|  8.31k|        }
  207|       |
  208|  8.31k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (208:5): [True: 8.31k, False: 43.2k]
  ------------------
  209|  8.31k|        return ctx->hmac_verify_failed ? -1 : 0;
  ------------------
  |  Branch (209:16): [True: 0, False: 8.31k]
  ------------------
  210|       |
  211|  2.14k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (211:5): [True: 2.14k, False: 49.3k]
  ------------------
  212|  2.14k|        zip_stat_t *st;
  213|       |
  214|  2.14k|        st = (zip_stat_t *)data;
  215|       |
  216|  2.14k|        st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|  2.14k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  217|  2.14k|        st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  2.14k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  218|  2.14k|        if (st->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  326|  2.14k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (218:13): [True: 2.14k, False: 0]
  ------------------
  219|  2.14k|            if (st->comp_size < WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method) + HMAC_LENGTH) {
  ------------------
  |  |   81|  2.14k|#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
  ------------------
                          if (st->comp_size < WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method) + HMAC_LENGTH) {
  ------------------
  |  |   85|  2.14k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  2.14k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|    688|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.45k, False: 688]
  |  |  |  Branch (85:64): [True: 0, False: 688]
  |  |  ------------------
  ------------------
                          if (st->comp_size < WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method) + HMAC_LENGTH) {
  ------------------
  |  |   84|  2.14k|#define HMAC_LENGTH 10
  ------------------
  |  Branch (219:17): [True: 0, False: 2.14k]
  ------------------
  220|      0|                zip_error_set(&ctx->error, ZIP_ER_DATA_LENGTH, 0);
  ------------------
  |  |  164|      0|#define ZIP_ER_DATA_LENGTH 33     /* N Unexpected length of data */
  ------------------
  221|      0|                return -1;
  222|      0|            }
  223|  2.14k|            st->comp_size -= WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method) + HMAC_LENGTH;
  ------------------
  |  |   81|  2.14k|#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
  ------------------
                          st->comp_size -= WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method) + HMAC_LENGTH;
  ------------------
  |  |   85|  2.14k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  2.14k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|    688|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.45k, False: 688]
  |  |  |  Branch (85:64): [True: 0, False: 688]
  |  |  ------------------
  ------------------
                          st->comp_size -= WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method) + HMAC_LENGTH;
  ------------------
  |  |   84|  2.14k|#define HMAC_LENGTH 10
  ------------------
  224|  2.14k|        }
  225|       |
  226|  2.14k|        return 0;
  227|  2.14k|    }
  228|       |
  229|  8.31k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (229:5): [True: 8.31k, False: 43.2k]
  ------------------
  230|  8.31k|        return zip_source_make_command_bitmap(ZIP_SOURCE_AT_EOF, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
  231|       |
  232|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (232:5): [True: 0, False: 51.5k]
  ------------------
  233|      0|        return zip_error_to_data(&ctx->error, data, len);
  234|       |
  235|  8.31k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (235:5): [True: 8.31k, False: 43.2k]
  ------------------
  236|  8.31k|        winzip_aes_free(ctx);
  237|  8.31k|        return 0;
  238|       |
  239|      0|    default:
  ------------------
  |  Branch (239:5): [True: 0, False: 51.5k]
  ------------------
  240|      0|        return zip_source_pass_to_lower_layer(src, data, len, cmd);
  241|  51.5k|    }
  242|  51.5k|}
zip_source_winzip_aes_decode.c:decrypt_header:
  103|  8.31k|static int decrypt_header(zip_source_t *src, struct winzip_aes *ctx) {
  104|  8.31k|    zip_uint8_t header[WINZIP_AES_MAX_HEADER_LENGTH];
  105|  8.31k|    zip_uint8_t password_verification[WINZIP_AES_PASSWORD_VERIFY_LENGTH];
  106|  8.31k|    unsigned int headerlen;
  107|  8.31k|    zip_int64_t n;
  108|       |
  109|  8.31k|    headerlen = WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method);
  ------------------
  |  |   81|  8.31k|#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
  ------------------
                  headerlen = WINZIP_AES_PASSWORD_VERIFY_LENGTH + SALT_LENGTH(ctx->encryption_method);
  ------------------
  |  |   85|  8.31k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  8.31k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|  6.35k|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.95k, False: 6.35k]
  |  |  |  Branch (85:64): [True: 0, False: 6.35k]
  |  |  ------------------
  ------------------
  110|  8.31k|    if ((n = zip_source_read(src, header, headerlen)) < 0) {
  ------------------
  |  Branch (110:9): [True: 0, False: 8.31k]
  ------------------
  111|      0|        zip_error_set_from_source(&ctx->error, src);
  112|      0|        return -1;
  113|      0|    }
  114|       |
  115|  8.31k|    if (n != headerlen) {
  ------------------
  |  Branch (115:9): [True: 0, False: 8.31k]
  ------------------
  116|      0|        zip_error_set(&ctx->error, ZIP_ER_EOF, 0);
  ------------------
  |  |  148|      0|#define ZIP_ER_EOF 17             /* N Premature end of file */
  ------------------
  117|      0|        return -1;
  118|      0|    }
  119|       |
  120|  8.31k|    if ((ctx->aes_ctx = _zip_winzip_aes_new((zip_uint8_t *)ctx->password, strlen(ctx->password), header, ctx->encryption_method, password_verification, &ctx->error)) == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 8.31k]
  ------------------
  121|      0|        return -1;
  122|      0|    }
  123|  8.31k|    if (memcmp(password_verification, header + SALT_LENGTH(ctx->encryption_method), WINZIP_AES_PASSWORD_VERIFY_LENGTH) != 0) {
  ------------------
  |  |   85|  8.31k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  8.31k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|  6.35k|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.95k, False: 6.35k]
  |  |  |  Branch (85:64): [True: 0, False: 6.35k]
  |  |  ------------------
  ------------------
                  if (memcmp(password_verification, header + SALT_LENGTH(ctx->encryption_method), WINZIP_AES_PASSWORD_VERIFY_LENGTH) != 0) {
  ------------------
  |  |   81|  8.31k|#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
  ------------------
  |  Branch (123:9): [True: 0, False: 8.31k]
  ------------------
  124|      0|        _zip_winzip_aes_free(ctx->aes_ctx);
  125|      0|        ctx->aes_ctx = NULL;
  126|      0|        zip_error_set(&ctx->error, ZIP_ER_WRONGPASSWD, 0);
  ------------------
  |  |  158|      0|#define ZIP_ER_WRONGPASSWD 27     /* N Wrong password provided */
  ------------------
  127|      0|        return -1;
  128|      0|    }
  129|  8.31k|    return 0;
  130|  8.31k|}
zip_source_winzip_aes_decode.c:verify_hmac:
  133|  7.82k|static void verify_hmac(zip_source_t *src, struct winzip_aes *ctx) {
  134|  7.82k|    unsigned char computed[ZIP_CRYPTO_SHA1_LENGTH], from_file[HMAC_LENGTH];
  135|  7.82k|    if (zip_source_read(src, from_file, HMAC_LENGTH) < HMAC_LENGTH) {
  ------------------
  |  |   84|  7.82k|#define HMAC_LENGTH 10
  ------------------
                  if (zip_source_read(src, from_file, HMAC_LENGTH) < HMAC_LENGTH) {
  ------------------
  |  |   84|  7.82k|#define HMAC_LENGTH 10
  ------------------
  |  Branch (135:9): [True: 0, False: 7.82k]
  ------------------
  136|      0|        zip_error_set_from_source(&ctx->error, src);
  137|      0|        ctx->hmac_verify_failed = true;
  138|      0|        return;
  139|      0|    }
  140|       |
  141|  7.82k|    if (!_zip_winzip_aes_finish(ctx->aes_ctx, computed)) {
  ------------------
  |  Branch (141:9): [True: 0, False: 7.82k]
  ------------------
  142|      0|        zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  143|      0|        ctx->hmac_verify_failed = true;
  144|      0|        return;
  145|      0|    }
  146|  7.82k|    _zip_winzip_aes_free(ctx->aes_ctx);
  147|  7.82k|    ctx->aes_ctx = NULL;
  148|       |
  149|  7.82k|    if (memcmp(from_file, computed, HMAC_LENGTH) != 0) {
  ------------------
  |  |   84|  7.82k|#define HMAC_LENGTH 10
  ------------------
  |  Branch (149:9): [True: 0, False: 7.82k]
  ------------------
  150|      0|        zip_error_set(&ctx->error, ZIP_ER_CRC, 0);
  ------------------
  |  |  138|      0|#define ZIP_ER_CRC 7              /* N CRC error */
  ------------------
  151|      0|        ctx->hmac_verify_failed = true;
  152|      0|        return;
  153|      0|    }
  154|       |
  155|  7.82k|    return;
  156|  7.82k|}
zip_source_winzip_aes_decode.c:winzip_aes_free:
  245|  8.31k|static void winzip_aes_free(struct winzip_aes *ctx) {
  246|  8.31k|    if (ctx == NULL) {
  ------------------
  |  Branch (246:9): [True: 0, False: 8.31k]
  ------------------
  247|      0|        return;
  248|      0|    }
  249|       |
  250|  8.31k|    _zip_crypto_clear(ctx->password, strlen(ctx->password));
  ------------------
  |  |  533|  8.31k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  251|  8.31k|    free(ctx->password);
  252|  8.31k|    zip_error_fini(&ctx->error);
  253|  8.31k|    _zip_winzip_aes_free(ctx->aes_ctx);
  254|  8.31k|    free(ctx);
  255|  8.31k|}
zip_source_winzip_aes_decode.c:winzip_aes_new:
  258|  8.31k|static struct winzip_aes *winzip_aes_new(zip_uint16_t encryption_method, const char *password, zip_error_t *error) {
  259|  8.31k|    struct winzip_aes *ctx;
  260|       |
  261|  8.31k|    if ((ctx = (struct winzip_aes *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (261:9): [True: 0, False: 8.31k]
  ------------------
  262|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  263|      0|        return NULL;
  264|      0|    }
  265|       |
  266|  8.31k|    if ((ctx->password = strdup(password)) == NULL) {
  ------------------
  |  Branch (266:9): [True: 0, False: 8.31k]
  ------------------
  267|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  268|      0|        free(ctx);
  269|      0|        return NULL;
  270|      0|    }
  271|       |
  272|  8.31k|    ctx->encryption_method = encryption_method;
  273|  8.31k|    ctx->aes_ctx = NULL;
  274|  8.31k|    ctx->hmac_verify_failed = false;
  275|       |
  276|  8.31k|    zip_error_init(&ctx->error);
  277|       |
  278|  8.31k|    return ctx;
  279|  8.31k|}

zip_source_winzip_aes_encode:
   63|  8.56k|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) {
   64|  8.56k|    zip_source_t *s2;
   65|  8.56k|    struct winzip_aes *ctx;
   66|       |
   67|  8.56k|    if ((encryption_method != ZIP_EM_AES_128 && encryption_method != ZIP_EM_AES_192 && encryption_method != ZIP_EM_AES_256) || password == NULL || src == NULL) {
  ------------------
  |  |  220|  17.1k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
                  if ((encryption_method != ZIP_EM_AES_128 && encryption_method != ZIP_EM_AES_192 && encryption_method != ZIP_EM_AES_256) || password == NULL || src == NULL) {
  ------------------
  |  |  221|  15.1k|#define ZIP_EM_AES_192 0x0102
  ------------------
                  if ((encryption_method != ZIP_EM_AES_128 && encryption_method != ZIP_EM_AES_192 && encryption_method != ZIP_EM_AES_256) || password == NULL || src == NULL) {
  ------------------
  |  |  222|  6.57k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (67:10): [True: 6.57k, False: 1.98k]
  |  Branch (67:49): [True: 6.57k, False: 0]
  |  Branch (67:88): [True: 0, False: 6.57k]
  |  Branch (67:128): [True: 0, False: 8.56k]
  |  Branch (67:148): [True: 0, False: 8.56k]
  ------------------
   68|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   69|      0|        return NULL;
   70|      0|    }
   71|       |
   72|  8.56k|    if ((ctx = winzip_aes_new(encryption_method, password, &za->error)) == NULL) {
  ------------------
  |  Branch (72:9): [True: 0, False: 8.56k]
  ------------------
   73|      0|        return NULL;
   74|      0|    }
   75|       |
   76|  8.56k|    if ((s2 = zip_source_layered(za, src, winzip_aes_encrypt, ctx)) == NULL) {
  ------------------
  |  Branch (76:9): [True: 0, False: 8.56k]
  ------------------
   77|      0|        winzip_aes_free(ctx);
   78|      0|        return NULL;
   79|      0|    }
   80|       |
   81|  8.56k|    return s2;
   82|  8.56k|}
zip_source_winzip_aes_encode.c:winzip_aes_encrypt:
  107|  77.0k|static zip_int64_t winzip_aes_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip_source_cmd_t cmd) {
  108|  77.0k|    struct winzip_aes *ctx;
  109|  77.0k|    zip_int64_t ret;
  110|  77.0k|    zip_uint64_t buffer_n;
  111|       |
  112|  77.0k|    ctx = (struct winzip_aes *)ud;
  113|       |
  114|  77.0k|    switch (cmd) {
  115|      0|    case ZIP_SOURCE_AT_EOF:
  ------------------
  |  Branch (115:5): [True: 0, False: 77.0k]
  ------------------
  116|      0|        return ctx->eof && ctx->buffer == NULL;
  ------------------
  |  Branch (116:16): [True: 0, False: 0]
  |  Branch (116:28): [True: 0, False: 0]
  ------------------
  117|       |
  118|  8.56k|    case ZIP_SOURCE_OPEN:
  ------------------
  |  Branch (118:5): [True: 8.56k, False: 68.5k]
  ------------------
  119|  8.56k|        ctx->eof = false;
  120|  8.56k|        if (encrypt_header(src, ctx) < 0) {
  ------------------
  |  Branch (120:13): [True: 0, False: 8.56k]
  ------------------
  121|      0|            return -1;
  122|      0|        }
  123|  8.56k|        return 0;
  124|       |
  125|  17.1k|    case ZIP_SOURCE_READ:
  ------------------
  |  Branch (125:5): [True: 17.1k, False: 59.9k]
  ------------------
  126|  17.1k|        buffer_n = 0;
  127|       |
  128|  17.1k|        if (ctx->buffer) {
  ------------------
  |  Branch (128:13): [True: 8.56k, False: 8.56k]
  ------------------
  129|  8.56k|            buffer_n = _zip_buffer_read(ctx->buffer, data, length);
  130|       |
  131|  8.56k|            data = (zip_uint8_t *)data + buffer_n;
  132|  8.56k|            length -= buffer_n;
  133|       |
  134|  8.56k|            if (_zip_buffer_eof(ctx->buffer)) {
  ------------------
  |  Branch (134:17): [True: 8.56k, False: 0]
  ------------------
  135|  8.56k|                _zip_buffer_free(ctx->buffer);
  136|  8.56k|                ctx->buffer = NULL;
  137|  8.56k|            }
  138|  8.56k|        }
  139|       |
  140|  17.1k|        if (ctx->eof) {
  ------------------
  |  Branch (140:13): [True: 8.56k, False: 8.56k]
  ------------------
  141|  8.56k|            return (zip_int64_t)buffer_n;
  142|  8.56k|        }
  143|       |
  144|  8.56k|        if ((ret = zip_source_read(src, data, length)) < 0) {
  ------------------
  |  Branch (144:13): [True: 0, False: 8.56k]
  ------------------
  145|      0|            zip_error_set_from_source(&ctx->error, src);
  146|      0|            return -1;
  147|      0|        }
  148|       |
  149|  8.56k|        if (!_zip_winzip_aes_encrypt(ctx->aes_ctx, data, (zip_uint64_t)ret)) {
  ------------------
  |  Branch (149:13): [True: 0, False: 8.56k]
  ------------------
  150|      0|            zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  151|       |            /* TODO: return partial read? */
  152|      0|            return -1;
  153|      0|        }
  154|       |
  155|  8.56k|        if ((zip_uint64_t)ret < length) {
  ------------------
  |  Branch (155:13): [True: 8.56k, False: 0]
  ------------------
  156|  8.56k|            ctx->eof = true;
  157|  8.56k|            if (!_zip_winzip_aes_finish(ctx->aes_ctx, ctx->data)) {
  ------------------
  |  Branch (157:17): [True: 0, False: 8.56k]
  ------------------
  158|      0|                zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
  159|       |                /* TODO: return partial read? */
  160|      0|                return -1;
  161|      0|            }
  162|  8.56k|            _zip_winzip_aes_free(ctx->aes_ctx);
  163|  8.56k|            ctx->aes_ctx = NULL;
  164|  8.56k|            if ((ctx->buffer = _zip_buffer_new(ctx->data, HMAC_LENGTH)) == NULL) {
  ------------------
  |  |   84|  8.56k|#define HMAC_LENGTH 10
  ------------------
  |  Branch (164:17): [True: 0, False: 8.56k]
  ------------------
  165|      0|                zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  166|       |                /* TODO: return partial read? */
  167|      0|                return -1;
  168|      0|            }
  169|  8.56k|            buffer_n += _zip_buffer_read(ctx->buffer, (zip_uint8_t *)data + ret, length - (zip_uint64_t)ret);
  170|  8.56k|            if (_zip_buffer_eof(ctx->buffer)) {
  ------------------
  |  Branch (170:17): [True: 8.56k, False: 0]
  ------------------
  171|  8.56k|                _zip_buffer_free(ctx->buffer);
  172|  8.56k|                ctx->buffer = NULL;
  173|  8.56k|            }
  174|  8.56k|        }
  175|       |
  176|  8.56k|        return (zip_int64_t)(buffer_n + (zip_uint64_t)ret);
  177|       |
  178|  8.56k|    case ZIP_SOURCE_CLOSE:
  ------------------
  |  Branch (178:5): [True: 8.56k, False: 68.5k]
  ------------------
  179|  8.56k|        return 0;
  180|       |
  181|  8.56k|    case ZIP_SOURCE_STAT: {
  ------------------
  |  Branch (181:5): [True: 8.56k, False: 68.5k]
  ------------------
  182|  8.56k|        zip_stat_t *st;
  183|       |
  184|  8.56k|        st = (zip_stat_t *)data;
  185|  8.56k|        st->encryption_method = ctx->encryption_method;
  186|  8.56k|        st->valid |= ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  8.56k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  187|  8.56k|        if (st->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  326|  8.56k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (187:13): [True: 8.56k, False: 0]
  ------------------
  188|  8.56k|            st->comp_size += 12 + SALT_LENGTH(ctx->encryption_method);
  ------------------
  |  |   85|  8.56k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  8.56k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|  6.57k|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.98k, False: 6.57k]
  |  |  |  Branch (85:64): [True: 0, False: 6.57k]
  |  |  ------------------
  ------------------
  189|  8.56k|        }
  190|       |
  191|  8.56k|        return 0;
  192|  8.56k|    }
  193|       |
  194|  17.1k|    case ZIP_SOURCE_GET_FILE_ATTRIBUTES: {
  ------------------
  |  Branch (194:5): [True: 17.1k, False: 59.9k]
  ------------------
  195|  17.1k|        zip_file_attributes_t *attributes = (zip_file_attributes_t *)data;
  196|  17.1k|        if (length < sizeof(*attributes)) {
  ------------------
  |  Branch (196:13): [True: 0, False: 17.1k]
  ------------------
  197|      0|            zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  198|      0|            return -1;
  199|      0|        }
  200|  17.1k|        attributes->valid |= ZIP_FILE_ATTRIBUTES_VERSION_NEEDED;
  ------------------
  |  |  364|  17.1k|#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
  ------------------
  201|  17.1k|        attributes->version_needed = 51;
  202|       |
  203|  17.1k|        return 0;
  204|  17.1k|    }
  205|       |
  206|  8.56k|    case ZIP_SOURCE_SUPPORTS:
  ------------------
  |  Branch (206:5): [True: 8.56k, False: 68.5k]
  ------------------
  207|  8.56k|        return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
  208|       |
  209|      0|    case ZIP_SOURCE_ERROR:
  ------------------
  |  Branch (209:5): [True: 0, False: 77.0k]
  ------------------
  210|      0|        return zip_error_to_data(&ctx->error, data, length);
  211|       |
  212|  8.56k|    case ZIP_SOURCE_FREE:
  ------------------
  |  Branch (212:5): [True: 8.56k, False: 68.5k]
  ------------------
  213|  8.56k|        winzip_aes_free(ctx);
  214|  8.56k|        return 0;
  215|       |
  216|      0|    default:
  ------------------
  |  Branch (216:5): [True: 0, False: 77.0k]
  ------------------
  217|      0|        return zip_source_pass_to_lower_layer(src, data, length, cmd);
  218|  77.0k|    }
  219|  77.0k|}
zip_source_winzip_aes_encode.c:encrypt_header:
   85|  8.56k|static int encrypt_header(zip_source_t *src, struct winzip_aes *ctx) {
   86|  8.56k|    zip_uint16_t salt_length = SALT_LENGTH(ctx->encryption_method);
  ------------------
  |  |   85|  8.56k|#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  220|  8.56k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  |  |  ------------------
  |  |               #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
  |  |  ------------------
  |  |  |  |  221|  6.57k|#define ZIP_EM_AES_192 0x0102
  |  |  ------------------
  |  |  |  Branch (85:30): [True: 1.98k, False: 6.57k]
  |  |  |  Branch (85:64): [True: 0, False: 6.57k]
  |  |  ------------------
  ------------------
   87|  8.56k|    if (!zip_secure_random(ctx->data, salt_length)) {
  ------------------
  |  Branch (87:9): [True: 0, False: 8.56k]
  ------------------
   88|      0|        zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   89|      0|        return -1;
   90|      0|    }
   91|       |
   92|  8.56k|    if ((ctx->aes_ctx = _zip_winzip_aes_new((zip_uint8_t *)ctx->password, strlen(ctx->password), ctx->data, ctx->encryption_method, ctx->data + salt_length, &ctx->error)) == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 8.56k]
  ------------------
   93|      0|        return -1;
   94|      0|    }
   95|       |
   96|  8.56k|    if ((ctx->buffer = _zip_buffer_new(ctx->data, salt_length + WINZIP_AES_PASSWORD_VERIFY_LENGTH)) == NULL) {
  ------------------
  |  |   81|  8.56k|#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
  ------------------
  |  Branch (96:9): [True: 0, False: 8.56k]
  ------------------
   97|      0|        _zip_winzip_aes_free(ctx->aes_ctx);
   98|      0|        ctx->aes_ctx = NULL;
   99|      0|        zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  100|      0|        return -1;
  101|      0|    }
  102|       |
  103|  8.56k|    return 0;
  104|  8.56k|}
zip_source_winzip_aes_encode.c:winzip_aes_free:
  222|  8.56k|static void winzip_aes_free(struct winzip_aes *ctx) {
  223|  8.56k|    if (ctx == NULL) {
  ------------------
  |  Branch (223:9): [True: 0, False: 8.56k]
  ------------------
  224|      0|        return;
  225|      0|    }
  226|       |
  227|  8.56k|    _zip_crypto_clear(ctx->password, strlen(ctx->password));
  ------------------
  |  |  533|  8.56k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  228|  8.56k|    free(ctx->password);
  229|  8.56k|    zip_error_fini(&ctx->error);
  230|  8.56k|    _zip_buffer_free(ctx->buffer);
  231|  8.56k|    _zip_winzip_aes_free(ctx->aes_ctx);
  232|  8.56k|    free(ctx);
  233|  8.56k|}
zip_source_winzip_aes_encode.c:winzip_aes_new:
  236|  8.56k|static struct winzip_aes *winzip_aes_new(zip_uint16_t encryption_method, const char *password, zip_error_t *error) {
  237|  8.56k|    struct winzip_aes *ctx;
  238|       |
  239|  8.56k|    if ((ctx = (struct winzip_aes *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (239:9): [True: 0, False: 8.56k]
  ------------------
  240|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  241|      0|        return NULL;
  242|      0|    }
  243|       |
  244|  8.56k|    if ((ctx->password = strdup(password)) == NULL) {
  ------------------
  |  Branch (244:9): [True: 0, False: 8.56k]
  ------------------
  245|      0|        free(ctx);
  246|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  247|      0|        return NULL;
  248|      0|    }
  249|       |
  250|  8.56k|    ctx->encryption_method = encryption_method;
  251|  8.56k|    ctx->buffer = NULL;
  252|  8.56k|    ctx->aes_ctx = NULL;
  253|       |
  254|  8.56k|    zip_error_init(&ctx->error);
  255|       |
  256|       |    ctx->eof = false;
  257|  8.56k|    return ctx;
  258|  8.56k|}

zip_source_write:
   38|   203k|ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *src, const void *data, zip_uint64_t length) {
   39|   203k|    if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) {
  ------------------
  |  |  442|   407k|#define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
  ------------------
                  if (!ZIP_SOURCE_IS_OPEN_WRITING(src) || length > ZIP_INT64_MAX) {
  ------------------
  |  |   45|   203k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (39:9): [True: 0, False: 203k]
  |  Branch (39:45): [True: 0, False: 203k]
  ------------------
   40|      0|        zip_error_set(&src->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   41|      0|        return -1;
   42|      0|    }
   43|       |
   44|   203k|    return _zip_source_call(src, (void *)data, length, ZIP_SOURCE_WRITE);
   45|   203k|}

zip_source_zip_file_create:
   46|  18.6k|ZIP_EXTERN zip_source_t *zip_source_zip_file_create(zip_t *srcza, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_int64_t len, const char *password, zip_error_t *error) {
   47|       |    /* TODO: We need to make sure that the returned source is invalidated when srcza is closed. */
   48|  18.6k|    zip_source_t *src, *s2;
   49|  18.6k|    zip_stat_t st;
   50|  18.6k|    zip_file_attributes_t attributes;
   51|  18.6k|    zip_dirent_t *de;
   52|  18.6k|    bool partial_data, needs_crc, encrypted, needs_decrypt, compressed, needs_decompress, changed_data, have_size, have_comp_size;
   53|  18.6k|    zip_flags_t stat_flags;
   54|  18.6k|    zip_int64_t data_len;
   55|  18.6k|    bool take_ownership = false;
   56|  18.6k|    bool empty_data = false;
   57|       |
   58|  18.6k|    if (srcza == NULL || srcidx >= srcza->nentry || len < -1) {
  ------------------
  |  Branch (58:9): [True: 0, False: 18.6k]
  |  Branch (58:26): [True: 0, False: 18.6k]
  |  Branch (58:53): [True: 0, False: 18.6k]
  ------------------
   59|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   60|      0|        return NULL;
   61|      0|    }
   62|       |
   63|  18.6k|    if (flags & ZIP_FL_ENCRYPTED) {
  ------------------
  |  |  100|  18.6k|#define ZIP_FL_ENCRYPTED 32u   /* read encrypted data (implies ZIP_FL_COMPRESSED) */
  ------------------
  |  Branch (63:9): [True: 0, False: 18.6k]
  ------------------
   64|      0|        flags |= ZIP_FL_COMPRESSED;
  ------------------
  |  |   97|      0|#define ZIP_FL_COMPRESSED 4u /* read compressed data */
  ------------------
   65|      0|    }
   66|       |
   67|  18.6k|    changed_data = false;
   68|  18.6k|    if ((flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |   98|  18.6k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (68:9): [True: 18.6k, False: 0]
  ------------------
   69|  18.6k|        zip_entry_t *entry = srcza->entry + srcidx;
   70|  18.6k|        if (ZIP_ENTRY_DATA_CHANGED(entry)) {
  ------------------
  |  |  518|  18.6k|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  ------------------
  |  |  |  Branch (518:35): [True: 0, False: 18.6k]
  |  |  ------------------
  ------------------
   71|      0|            if ((flags & ZIP_FL_COMPRESSED) || !zip_source_supports_reopen(entry->source)) {
  ------------------
  |  |   97|      0|#define ZIP_FL_COMPRESSED 4u /* read compressed data */
  ------------------
  |  Branch (71:17): [True: 0, False: 0]
  |  Branch (71:48): [True: 0, False: 0]
  ------------------
   72|      0|                zip_error_set(error, ZIP_ER_CHANGED, 0);
  ------------------
  |  |  146|      0|#define ZIP_ER_CHANGED 15         /* N Entry has been changed */
  ------------------
   73|      0|                return NULL;
   74|      0|            }
   75|       |
   76|      0|            changed_data = true;
   77|      0|        }
   78|  18.6k|        else if (entry->deleted) {
  ------------------
  |  Branch (78:18): [True: 0, False: 18.6k]
  ------------------
   79|      0|            zip_error_set(error, ZIP_ER_CHANGED, 0);
  ------------------
  |  |  146|      0|#define ZIP_ER_CHANGED 15         /* N Entry has been changed */
  ------------------
   80|      0|            return NULL;
   81|      0|        }
   82|  18.6k|    }
   83|       |
   84|  18.6k|    stat_flags = flags;
   85|  18.6k|    if (!changed_data) {
  ------------------
  |  Branch (85:9): [True: 18.6k, False: 0]
  ------------------
   86|  18.6k|        stat_flags |= ZIP_FL_UNCHANGED;
  ------------------
  |  |   98|  18.6k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
   87|  18.6k|    }
   88|       |
   89|  18.6k|    if (zip_stat_index(srcza, srcidx, stat_flags, &st) < 0) {
  ------------------
  |  Branch (89:9): [True: 0, False: 18.6k]
  ------------------
   90|      0|        zip_error_set(error, ZIP_ER_INTERNAL, 0);
  ------------------
  |  |  151|      0|#define ZIP_ER_INTERNAL 20        /* N Internal error */
  ------------------
   91|      0|        return NULL;
   92|      0|    }
   93|       |
   94|  18.6k|    if ((start > 0 || len >= 0) && (flags & ZIP_FL_COMPRESSED)) {
  ------------------
  |  |   97|      0|#define ZIP_FL_COMPRESSED 4u /* read compressed data */
  ------------------
  |  Branch (94:10): [True: 0, False: 18.6k]
  |  Branch (94:23): [True: 0, False: 18.6k]
  |  Branch (94:36): [True: 0, False: 0]
  ------------------
   95|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   96|      0|        return NULL;
   97|      0|    }
   98|       |
   99|  18.6k|    have_size = (st.valid & ZIP_STAT_SIZE) != 0;
  ------------------
  |  |  325|  18.6k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  100|       |    /* overflow or past end of file */
  101|  18.6k|    if (len >= 0 && ((start > 0 && start + len < start) || (have_size && start + len > st.size))) {
  ------------------
  |  Branch (101:9): [True: 0, False: 18.6k]
  |  Branch (101:23): [True: 0, False: 0]
  |  Branch (101:36): [True: 0, False: 0]
  |  Branch (101:61): [True: 0, False: 0]
  |  Branch (101:74): [True: 0, False: 0]
  ------------------
  102|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  103|      0|        return NULL;
  104|      0|    }
  105|       |
  106|  18.6k|    if (len == -1) {
  ------------------
  |  Branch (106:9): [True: 18.6k, False: 0]
  ------------------
  107|  18.6k|        if (have_size) {
  ------------------
  |  Branch (107:13): [True: 18.6k, False: 0]
  ------------------
  108|  18.6k|            if (st.size - start > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  18.6k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (108:17): [True: 0, False: 18.6k]
  ------------------
  109|      0|                zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  110|      0|                return NULL;
  111|      0|            }
  112|  18.6k|            data_len = (zip_int64_t)(st.size - start);
  113|  18.6k|        }
  114|      0|        else {
  115|      0|            data_len = -1;
  116|      0|        }
  117|  18.6k|    }
  118|      0|    else {
  119|      0|        data_len = len;
  120|      0|    }
  121|       |
  122|  18.6k|    if (have_size) {
  ------------------
  |  Branch (122:9): [True: 18.6k, False: 0]
  ------------------
  123|  18.6k|        partial_data = (zip_uint64_t)(data_len) < st.size;
  124|  18.6k|    }
  125|      0|    else {
  126|      0|        partial_data = true;
  127|      0|    }
  128|  18.6k|    encrypted = (st.valid & ZIP_STAT_ENCRYPTION_METHOD) && (st.encryption_method != ZIP_EM_NONE);
  ------------------
  |  |  330|  18.6k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
                  encrypted = (st.valid & ZIP_STAT_ENCRYPTION_METHOD) && (st.encryption_method != ZIP_EM_NONE);
  ------------------
  |  |  207|  18.6k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  |  Branch (128:17): [True: 18.6k, False: 0]
  |  Branch (128:60): [True: 9.52k, False: 9.09k]
  ------------------
  129|  18.6k|    needs_decrypt = ((flags & ZIP_FL_ENCRYPTED) == 0) && encrypted;
  ------------------
  |  |  100|  18.6k|#define ZIP_FL_ENCRYPTED 32u   /* read encrypted data (implies ZIP_FL_COMPRESSED) */
  ------------------
  |  Branch (129:21): [True: 18.6k, False: 0]
  |  Branch (129:58): [True: 9.52k, False: 9.09k]
  ------------------
  130|  18.6k|    compressed = (st.valid & ZIP_STAT_COMP_METHOD) && (st.comp_method != ZIP_CM_STORE);
  ------------------
  |  |  329|  18.6k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                  compressed = (st.valid & ZIP_STAT_COMP_METHOD) && (st.comp_method != ZIP_CM_STORE);
  ------------------
  |  |  179|  18.6k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (130:18): [True: 18.6k, False: 0]
  |  Branch (130:55): [True: 3.61k, False: 15.0k]
  ------------------
  131|  18.6k|    needs_decompress = ((flags & ZIP_FL_COMPRESSED) == 0) && compressed;
  ------------------
  |  |   97|  18.6k|#define ZIP_FL_COMPRESSED 4u /* read compressed data */
  ------------------
  |  Branch (131:24): [True: 18.6k, False: 0]
  |  Branch (131:62): [True: 3.61k, False: 15.0k]
  ------------------
  132|       |    /* when reading the whole file, check for CRC errors */
  133|  18.6k|    needs_crc = ((flags & ZIP_FL_COMPRESSED) == 0 || !compressed) && !partial_data && (st.valid & ZIP_STAT_CRC) != 0;
  ------------------
  |  |   97|  18.6k|#define ZIP_FL_COMPRESSED 4u /* read compressed data */
  ------------------
                  needs_crc = ((flags & ZIP_FL_COMPRESSED) == 0 || !compressed) && !partial_data && (st.valid & ZIP_STAT_CRC) != 0;
  ------------------
  |  |  328|  18.6k|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (133:18): [True: 18.6k, False: 0]
  |  Branch (133:54): [True: 0, False: 0]
  |  Branch (133:70): [True: 18.6k, False: 0]
  |  Branch (133:87): [True: 10.3k, False: 8.31k]
  ------------------
  134|       |
  135|  18.6k|    if (needs_decrypt) {
  ------------------
  |  Branch (135:9): [True: 9.52k, False: 9.09k]
  ------------------
  136|  9.52k|        if (password == NULL) {
  ------------------
  |  Branch (136:13): [True: 0, False: 9.52k]
  ------------------
  137|      0|            password = srcza->default_password;
  138|      0|        }
  139|  9.52k|        if (password == NULL) {
  ------------------
  |  Branch (139:13): [True: 0, False: 9.52k]
  ------------------
  140|      0|            zip_error_set(error, ZIP_ER_NOPASSWD, 0);
  ------------------
  |  |  157|      0|#define ZIP_ER_NOPASSWD 26        /* N No password provided */
  ------------------
  141|      0|            return NULL;
  142|      0|        }
  143|  9.52k|    }
  144|       |
  145|  18.6k|    if ((de = _zip_get_dirent(srcza, srcidx, flags, error)) == NULL) {
  ------------------
  |  Branch (145:9): [True: 0, False: 18.6k]
  ------------------
  146|      0|        return NULL;
  147|      0|    }
  148|  18.6k|    _zip_file_attributes_from_dirent(&attributes, de);
  149|       |
  150|  18.6k|    have_comp_size = (st.valid & ZIP_STAT_COMP_SIZE) != 0;
  ------------------
  |  |  326|  18.6k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  151|  18.6k|    if (needs_decrypt || needs_decompress) {
  ------------------
  |  Branch (151:9): [True: 9.52k, False: 9.09k]
  |  Branch (151:26): [True: 861, False: 8.23k]
  ------------------
  152|  10.3k|        empty_data = (have_comp_size && st.comp_size == 0);
  ------------------
  |  Branch (152:23): [True: 10.3k, False: 0]
  |  Branch (152:41): [True: 0, False: 10.3k]
  ------------------
  153|  10.3k|    }
  154|  8.23k|    else {
  155|  8.23k|        empty_data = (have_size && st.size == 0);
  ------------------
  |  Branch (155:23): [True: 8.23k, False: 0]
  |  Branch (155:36): [True: 7.22k, False: 1.00k]
  ------------------
  156|  8.23k|    }
  157|  18.6k|    if (empty_data) {
  ------------------
  |  Branch (157:9): [True: 7.22k, False: 11.3k]
  ------------------
  158|  7.22k|        src = zip_source_buffer_with_attributes_create(NULL, 0, 0, &attributes, error);
  159|  7.22k|    }
  160|  11.3k|    else {
  161|  11.3k|        src = NULL;
  162|  11.3k|    }
  163|       |
  164|       |
  165|       |    /* If we created source buffer above, we want the window source to take ownership of it. */
  166|  18.6k|    take_ownership = src != NULL;
  167|       |    /* if we created a buffer source above, then treat it as if
  168|       |       reading the changed data - that way we don't need add another
  169|       |       special case to the code below that wraps it in the window
  170|       |       source */
  171|  18.6k|    changed_data = changed_data || (src != NULL);
  ------------------
  |  Branch (171:20): [True: 0, False: 18.6k]
  |  Branch (171:36): [True: 7.22k, False: 11.3k]
  ------------------
  172|       |
  173|  18.6k|    if (partial_data && !needs_decrypt && !needs_decompress) {
  ------------------
  |  Branch (173:9): [True: 0, False: 18.6k]
  |  Branch (173:25): [True: 0, False: 0]
  |  Branch (173:43): [True: 0, False: 0]
  ------------------
  174|      0|        struct zip_stat st2;
  175|      0|        zip_t *source_archive;
  176|      0|        zip_uint64_t source_index;
  177|       |
  178|      0|        if (changed_data) {
  ------------------
  |  Branch (178:13): [True: 0, False: 0]
  ------------------
  179|      0|            if (src == NULL) {
  ------------------
  |  Branch (179:17): [True: 0, False: 0]
  ------------------
  180|      0|                src = srcza->entry[srcidx].source;
  181|      0|            }
  182|      0|            source_archive = NULL;
  183|      0|            source_index = 0;
  184|      0|        }
  185|      0|        else {
  186|      0|            src = srcza->src;
  187|      0|            source_archive = srcza;
  188|      0|            source_index = srcidx;
  189|      0|        }
  190|       |
  191|      0|        st2.comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  192|      0|        st2.valid = ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  193|      0|        if (data_len >= 0) {
  ------------------
  |  Branch (193:13): [True: 0, False: 0]
  ------------------
  194|      0|            st2.size = (zip_uint64_t)data_len;
  195|      0|            st2.comp_size = (zip_uint64_t)data_len;
  196|      0|            st2.valid |= ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                          st2.valid |= ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  197|      0|        }
  198|      0|        if (st.valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (198:13): [True: 0, False: 0]
  ------------------
  199|      0|            st2.mtime = st.mtime;
  200|      0|            st2.valid |= ZIP_STAT_MTIME;
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  201|      0|        }
  202|       |
  203|      0|        s2 = _zip_source_window_new(src, start, data_len, &st2, ZIP_STAT_NAME, &attributes, &de->last_mod, source_archive, source_index, take_ownership, error);
  ------------------
  |  |  323|      0|#define ZIP_STAT_NAME 0x0001u
  ------------------
  204|      0|        if (s2 == NULL) {
  ------------------
  |  Branch (204:13): [True: 0, False: 0]
  ------------------
  205|      0|            if (take_ownership) {
  ------------------
  |  Branch (205:17): [True: 0, False: 0]
  ------------------
  206|      0|                zip_source_free(src);
  207|      0|            }
  208|      0|            return NULL;
  209|      0|        }
  210|      0|        src = s2;
  211|      0|    }
  212|       |    /* here we restrict src to file data, so no point in doing it for
  213|       |       source that already represents only the file data */
  214|  18.6k|    else if (!changed_data) {
  ------------------
  |  Branch (214:14): [True: 11.3k, False: 7.22k]
  ------------------
  215|       |        /* this branch is executed only for archive sources; we know
  216|       |           that stat data come from the archive too, so it's safe to
  217|       |           assume that st has a comp_size specified */
  218|  11.3k|        if (st.comp_size > ZIP_INT64_MAX) {
  ------------------
  |  |   45|  11.3k|#define ZIP_INT64_MAX	 0x7fffffffffffffffLL
  ------------------
  |  Branch (218:13): [True: 0, False: 11.3k]
  ------------------
  219|      0|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  220|      0|            return NULL;
  221|      0|        }
  222|       |        /* despite the fact that we want the whole data file, we still
  223|       |           wrap the source into a window source to add st and
  224|       |           attributes and to have a source that positions the read
  225|       |           offset properly before each read for multiple zip_file_t
  226|       |           referring to the same underlying source */
  227|  11.3k|        if ((src = _zip_source_window_new(srcza->src, 0, (zip_int64_t)st.comp_size, &st, ZIP_STAT_NAME, &attributes, &de->last_mod, srcza, srcidx, take_ownership, error)) == NULL) {
  ------------------
  |  |  323|  11.3k|#define ZIP_STAT_NAME 0x0001u
  ------------------
  |  Branch (227:13): [True: 0, False: 11.3k]
  ------------------
  228|      0|            return NULL;
  229|      0|        }
  230|  11.3k|    }
  231|  7.22k|    else {
  232|       |        /* this branch gets executed when reading the whole changed
  233|       |           data file or when "reading" from a zero-sized source buffer
  234|       |           that we created above */
  235|  7.22k|        if (src == NULL) {
  ------------------
  |  Branch (235:13): [True: 0, False: 7.22k]
  ------------------
  236|      0|            src = srcza->entry[srcidx].source;
  237|      0|        }
  238|       |        /* despite the fact that we want the whole data file, we still
  239|       |           wrap the source into a window source to add st and
  240|       |           attributes and to have a source that positions the read
  241|       |           offset properly before each read for multiple zip_file_t
  242|       |           referring to the same underlying source */
  243|  7.22k|        s2 = _zip_source_window_new(src, 0, data_len, &st, ZIP_STAT_NAME, &attributes, &de->last_mod, NULL, 0, take_ownership, error);
  ------------------
  |  |  323|  7.22k|#define ZIP_STAT_NAME 0x0001u
  ------------------
  244|  7.22k|        if (s2 == NULL) {
  ------------------
  |  Branch (244:13): [True: 0, False: 7.22k]
  ------------------
  245|      0|            if (take_ownership) {
  ------------------
  |  Branch (245:17): [True: 0, False: 0]
  ------------------
  246|      0|                zip_source_free(src);
  247|      0|            }
  248|      0|            return NULL;
  249|      0|        }
  250|  7.22k|        src = s2;
  251|  7.22k|    }
  252|       |
  253|       |    /* In all cases, src is a window source and therefore is owned by this function. */
  254|       |
  255|  18.6k|    if (_zip_source_set_source_archive(src, srcza) < 0) {
  ------------------
  |  Branch (255:9): [True: 0, False: 18.6k]
  ------------------
  256|      0|        zip_source_free(src);
  257|      0|        return NULL;
  258|      0|    }
  259|       |
  260|       |    /* creating a layered source calls zip_keep() on the lower layer, so we free it */
  261|       |
  262|  18.6k|    if (needs_decrypt) {
  ------------------
  |  Branch (262:9): [True: 9.52k, False: 9.09k]
  ------------------
  263|  9.52k|        zip_encryption_implementation enc_impl;
  264|       |
  265|  9.52k|        if ((enc_impl = _zip_get_encryption_implementation(st.encryption_method, ZIP_CODEC_DECODE)) == NULL) {
  ------------------
  |  |  114|  9.52k|#define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */
  ------------------
  |  Branch (265:13): [True: 0, False: 9.52k]
  ------------------
  266|      0|            zip_source_free(src);
  267|      0|            zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
  ------------------
  |  |  155|      0|#define ZIP_ER_ENCRNOTSUPP 24     /* N Encryption method not supported */
  ------------------
  268|      0|            return NULL;
  269|      0|        }
  270|       |
  271|  9.52k|        s2 = enc_impl(srcza, src, st.encryption_method, 0, password);
  272|  9.52k|        if (s2 == NULL) {
  ------------------
  |  Branch (272:13): [True: 0, False: 9.52k]
  ------------------
  273|      0|            zip_source_free(src);
  274|      0|            return NULL;
  275|      0|        }
  276|       |
  277|  9.52k|        src = s2;
  278|  9.52k|    }
  279|  18.6k|    if (needs_decompress) {
  ------------------
  |  Branch (279:9): [True: 3.61k, False: 15.0k]
  ------------------
  280|  3.61k|        s2 = zip_source_decompress(srcza, src, st.comp_method);
  281|  3.61k|        if (s2 == NULL) {
  ------------------
  |  Branch (281:13): [True: 0, False: 3.61k]
  ------------------
  282|      0|            zip_source_free(src);
  283|      0|            return NULL;
  284|      0|        }
  285|  3.61k|        src = s2;
  286|  3.61k|    }
  287|  18.6k|    if (needs_crc) {
  ------------------
  |  Branch (287:9): [True: 10.3k, False: 8.31k]
  ------------------
  288|  10.3k|        s2 = zip_source_crc_create(src, 1, error);
  289|  10.3k|        if (s2 == NULL) {
  ------------------
  |  Branch (289:13): [True: 0, False: 10.3k]
  ------------------
  290|      0|            zip_source_free(src);
  291|      0|            return NULL;
  292|      0|        }
  293|  10.3k|        src = s2;
  294|  10.3k|    }
  295|       |
  296|  18.6k|    if (partial_data && (needs_decrypt || needs_decompress)) {
  ------------------
  |  Branch (296:9): [True: 0, False: 18.6k]
  |  Branch (296:26): [True: 0, False: 0]
  |  Branch (296:43): [True: 0, False: 0]
  ------------------
  297|      0|        zip_stat_t st2;
  298|      0|        zip_stat_init(&st2);
  299|      0|        if (data_len >= 0) {
  ------------------
  |  Branch (299:13): [True: 0, False: 0]
  ------------------
  300|      0|            st2.valid = ZIP_STAT_SIZE;
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  301|      0|            st2.size = (zip_uint64_t)data_len;
  302|      0|        }
  303|      0|        s2 = _zip_source_window_new(src, start, data_len, &st2, ZIP_STAT_NAME, NULL, NULL, NULL, 0, true, error);
  ------------------
  |  |  323|      0|#define ZIP_STAT_NAME 0x0001u
  ------------------
  304|      0|        if (s2 == NULL) {
  ------------------
  |  Branch (304:13): [True: 0, False: 0]
  ------------------
  305|      0|            zip_source_free(src);
  306|      0|            return NULL;
  307|      0|        }
  308|      0|        src = s2;
  309|      0|    }
  310|       |
  311|  18.6k|    return src;
  312|  18.6k|}
zip_source_zip_new.c:_zip_file_attributes_from_dirent:
  314|  18.6k|static void _zip_file_attributes_from_dirent(zip_file_attributes_t *attributes, zip_dirent_t *de) {
  315|  18.6k|    zip_file_attributes_init(attributes);
  316|  18.6k|    attributes->valid = ZIP_FILE_ATTRIBUTES_ASCII | ZIP_FILE_ATTRIBUTES_HOST_SYSTEM | ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  363|  18.6k|#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
  ------------------
                  attributes->valid = ZIP_FILE_ATTRIBUTES_ASCII | ZIP_FILE_ATTRIBUTES_HOST_SYSTEM | ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  362|  18.6k|#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
  ------------------
                  attributes->valid = ZIP_FILE_ATTRIBUTES_ASCII | ZIP_FILE_ATTRIBUTES_HOST_SYSTEM | ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  365|  18.6k|#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
  ------------------
                  attributes->valid = ZIP_FILE_ATTRIBUTES_ASCII | ZIP_FILE_ATTRIBUTES_HOST_SYSTEM | ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES | ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS;
  ------------------
  |  |  366|  18.6k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
  ------------------
  317|  18.6k|    attributes->ascii = de->int_attrib & 1;
  318|  18.6k|    attributes->host_system = de->version_madeby >> 8;
  319|  18.6k|    attributes->external_file_attributes = de->ext_attrib;
  320|  18.6k|    attributes->general_purpose_bit_flags = de->bitflags;
  321|  18.6k|    attributes->general_purpose_bit_mask = ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK;
  ------------------
  |  |  102|  18.6k|#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS_ALLOWED_MASK 0x083e
  ------------------
  322|  18.6k|}

zip_stat_index:
   38|  18.6k|ZIP_EXTERN int zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st) {
   39|  18.6k|    const char *name;
   40|  18.6k|    zip_dirent_t *de;
   41|  18.6k|    zip_entry_t *entry;
   42|       |
   43|  18.6k|    if ((de = _zip_get_dirent(za, index, flags, NULL)) == NULL) {
  ------------------
  |  Branch (43:9): [True: 0, False: 18.6k]
  ------------------
   44|      0|        return -1;
   45|      0|    }
   46|       |
   47|  18.6k|    if ((name = zip_get_name(za, index, flags)) == NULL) {
  ------------------
  |  Branch (47:9): [True: 0, False: 18.6k]
  ------------------
   48|      0|        return -1;
   49|      0|    }
   50|       |
   51|  18.6k|    entry = za->entry + index;
   52|       |
   53|  18.6k|    if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
  ------------------
  |  |   98|  18.6k|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
                  if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
  ------------------
  |  |  518|      0|#define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL)
  |  |  ------------------
  |  |  |  Branch (518:35): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (53:9): [True: 0, False: 18.6k]
  ------------------
   54|      0|        if (zip_source_stat(entry->source, st) < 0) {
  ------------------
  |  Branch (54:13): [True: 0, False: 0]
  ------------------
   55|      0|            zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
  ------------------
  |  |  146|      0|#define ZIP_ER_CHANGED 15         /* N Entry has been changed */
  ------------------
   56|      0|            return -1;
   57|      0|        }
   58|       |
   59|      0|        if (de->comp_method == ZIP_CM_DEFAULT) {
  ------------------
  |  |  178|      0|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  |  Branch (59:13): [True: 0, False: 0]
  ------------------
   60|      0|            if (!(st->valid & ZIP_STAT_COMP_METHOD) || st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                          if (!(st->valid & ZIP_STAT_COMP_METHOD) || st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (60:17): [True: 0, False: 0]
  |  Branch (60:56): [True: 0, False: 0]
  ------------------
   61|      0|                st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                              st->valid &= ~(ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD);
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
   62|      0|            }
   63|      0|        }
   64|      0|        else {
   65|      0|            if ((st->valid & ZIP_STAT_COMP_METHOD) && st->comp_method != de->comp_method) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  |  Branch (65:17): [True: 0, False: 0]
  |  Branch (65:55): [True: 0, False: 0]
  ------------------
   66|      0|                st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
   67|      0|            }
   68|      0|            st->valid |= ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
   69|      0|            st->comp_method = de->comp_method;
   70|      0|        }
   71|       |
   72|      0|        if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  325|      0|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      if (((st->valid & (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) == (ZIP_STAT_COMP_METHOD | ZIP_STAT_SIZE)) && st->comp_method == ZIP_CM_STORE) {
  ------------------
  |  |  179|      0|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  |  Branch (72:13): [True: 0, False: 0]
  |  Branch (72:113): [True: 0, False: 0]
  ------------------
   73|      0|            st->valid |= ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
   74|      0|            st->comp_size = st->size;
   75|      0|        }
   76|       |
   77|      0|        if (entry->changes != NULL && entry->changes->changed & ZIP_DIRENT_LAST_MOD) {
  ------------------
  |  |  341|      0|#define ZIP_DIRENT_LAST_MOD 0x0020u
  ------------------
  |  Branch (77:13): [True: 0, False: 0]
  |  Branch (77:39): [True: 0, False: 0]
  ------------------
   78|      0|            st->mtime = zip_dirent_get_last_mod_mtime(de);
   79|      0|            st->valid |= ZIP_STAT_MTIME;
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
   80|      0|        }
   81|      0|    }
   82|  18.6k|    else {
   83|  18.6k|        zip_stat_init(st);
   84|       |
   85|  18.6k|        st->crc = de->crc;
   86|  18.6k|        st->size = de->uncomp_size;
   87|  18.6k|        st->mtime = zip_dirent_get_last_mod_mtime(de);
   88|  18.6k|        st->comp_size = de->comp_size;
   89|  18.6k|        st->comp_method = (zip_uint16_t)de->comp_method;
   90|  18.6k|        st->encryption_method = de->encryption_method;
   91|  18.6k|        st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  328|  10.3k|#define ZIP_STAT_CRC 0x0020u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  325|  18.6k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  327|  18.6k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  326|  18.6k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  329|  18.6k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
                      st->valid = (de->crc_valid ? ZIP_STAT_CRC : 0) | ZIP_STAT_SIZE | ZIP_STAT_MTIME | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
  ------------------
  |  |  330|  18.6k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  |  Branch (91:22): [True: 10.3k, False: 8.31k]
  ------------------
   92|  18.6k|        if (entry->changes != NULL && entry->changes->changed & ZIP_DIRENT_COMP_METHOD) {
  ------------------
  |  |  336|      0|#define ZIP_DIRENT_COMP_METHOD 0x0001u
  ------------------
  |  Branch (92:13): [True: 0, False: 18.6k]
  |  Branch (92:39): [True: 0, False: 0]
  ------------------
   93|      0|            st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
   94|      0|        }
   95|  18.6k|    }
   96|       |
   97|  18.6k|    if ((za->ch_flags & ZIP_AFL_WANT_TORRENTZIP) && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |  115|  18.6k|#define ZIP_AFL_WANT_TORRENTZIP 8u                        /* write archive in torrentzip format */
  ------------------
                  if ((za->ch_flags & ZIP_AFL_WANT_TORRENTZIP) && (flags & ZIP_FL_UNCHANGED) == 0) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (97:9): [True: 0, False: 18.6k]
  |  Branch (97:53): [True: 0, False: 0]
  ------------------
   98|      0|        if (za->torrent_mtime == 0) {
  ------------------
  |  Branch (98:13): [True: 0, False: 0]
  ------------------
   99|      0|            zip_dostime_t dostime = {0xbc00, 0x2198};
  100|      0|            za->torrent_mtime = _zip_d2u_time(&dostime);
  101|      0|        }
  102|      0|        st->comp_method = ZIP_CM_DEFLATE;
  ------------------
  |  |  187|      0|#define ZIP_CM_DEFLATE 8         /* deflated */
  ------------------
  103|      0|        st->mtime = za->torrent_mtime;
  104|      0|        st->valid |= ZIP_STAT_MTIME | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  327|      0|#define ZIP_STAT_MTIME 0x0010u
  ------------------
                      st->valid |= ZIP_STAT_MTIME | ZIP_STAT_COMP_METHOD;
  ------------------
  |  |  329|      0|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  105|      0|        st->valid &= ~ZIP_STAT_COMP_SIZE;
  ------------------
  |  |  326|      0|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  106|      0|    }
  107|       |
  108|  18.6k|    st->index = index;
  109|  18.6k|    st->name = name;
  110|  18.6k|    st->valid |= ZIP_STAT_INDEX | ZIP_STAT_NAME;
  ------------------
  |  |  324|  18.6k|#define ZIP_STAT_INDEX 0x0002u
  ------------------
                  st->valid |= ZIP_STAT_INDEX | ZIP_STAT_NAME;
  ------------------
  |  |  323|  18.6k|#define ZIP_STAT_NAME 0x0001u
  ------------------
  111|       |
  112|  18.6k|    return 0;
  113|  18.6k|}

zip_stat_init:
   39|   359k|ZIP_EXTERN void zip_stat_init(zip_stat_t *st) {
   40|   359k|    st->valid = 0;
   41|   359k|    st->name = NULL;
   42|   359k|    st->index = ZIP_UINT64_MAX;
  ------------------
  |  |   46|   359k|#define ZIP_UINT64_MAX	 0xffffffffffffffffULL
  ------------------
   43|   359k|    st->crc = 0;
   44|   359k|    st->mtime = (time_t)-1;
   45|   359k|    st->size = 0;
   46|   359k|    st->comp_size = 0;
   47|   359k|    st->comp_method = ZIP_CM_STORE;
  ------------------
  |  |  179|   359k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
   48|   359k|    st->encryption_method = ZIP_EM_NONE;
  ------------------
  |  |  207|   359k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
   49|   359k|}
_zip_stat_merge:
   52|  53.9k|int _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error) {
   53|       |    /* name is not merged, since zip_stat_t doesn't own it, and src may not be valid as long as dst */
   54|  53.9k|    if (src->valid & ZIP_STAT_INDEX) {
  ------------------
  |  |  324|  53.9k|#define ZIP_STAT_INDEX 0x0002u
  ------------------
  |  Branch (54:9): [True: 53.5k, False: 348]
  ------------------
   55|  53.5k|        dst->index = src->index;
   56|  53.5k|    }
   57|  53.9k|    if (src->valid & ZIP_STAT_SIZE) {
  ------------------
  |  |  325|  53.9k|#define ZIP_STAT_SIZE 0x0004u
  ------------------
  |  Branch (57:9): [True: 53.9k, False: 0]
  ------------------
   58|  53.9k|        dst->size = src->size;
   59|  53.9k|    }
   60|  53.9k|    if (src->valid & ZIP_STAT_COMP_SIZE) {
  ------------------
  |  |  326|  53.9k|#define ZIP_STAT_COMP_SIZE 0x0008u
  ------------------
  |  Branch (60:9): [True: 53.5k, False: 348]
  ------------------
   61|  53.5k|        dst->comp_size = src->comp_size;
   62|  53.5k|    }
   63|  53.9k|    if (src->valid & ZIP_STAT_MTIME) {
  ------------------
  |  |  327|  53.9k|#define ZIP_STAT_MTIME 0x0010u
  ------------------
  |  Branch (63:9): [True: 53.5k, False: 348]
  ------------------
   64|  53.5k|        dst->mtime = src->mtime;
   65|  53.5k|    }
   66|  53.9k|    if (src->valid & ZIP_STAT_CRC) {
  ------------------
  |  |  328|  53.9k|#define ZIP_STAT_CRC 0x0020u
  ------------------
  |  Branch (66:9): [True: 35.1k, False: 18.7k]
  ------------------
   67|  35.1k|        dst->crc = src->crc;
   68|  35.1k|    }
   69|  53.9k|    if (src->valid & ZIP_STAT_COMP_METHOD) {
  ------------------
  |  |  329|  53.9k|#define ZIP_STAT_COMP_METHOD 0x0040u
  ------------------
  |  Branch (69:9): [True: 53.5k, False: 348]
  ------------------
   70|  53.5k|        dst->comp_method = src->comp_method;
   71|  53.5k|    }
   72|  53.9k|    if (src->valid & ZIP_STAT_ENCRYPTION_METHOD) {
  ------------------
  |  |  330|  53.9k|#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
  ------------------
  |  Branch (72:9): [True: 53.5k, False: 348]
  ------------------
   73|  53.5k|        dst->encryption_method = src->encryption_method;
   74|  53.5k|    }
   75|  53.9k|    if (src->valid & ZIP_STAT_FLAGS) {
  ------------------
  |  |  331|  53.9k|#define ZIP_STAT_FLAGS 0x0100u
  ------------------
  |  Branch (75:9): [True: 0, False: 53.9k]
  ------------------
   76|      0|        dst->flags = src->flags;
   77|      0|    }
   78|  53.9k|    dst->valid |= src->valid;
   79|       |
   80|  53.9k|    return 0;
   81|  53.9k|}

_zip_string_crc32:
   41|    310|zip_uint32_t _zip_string_crc32(const zip_string_t *s) {
   42|    310|    zip_uint32_t crc;
   43|       |
   44|    310|    crc = (zip_uint32_t)crc32(0L, Z_NULL, 0);
   45|       |
   46|    310|    if (s != NULL) {
  ------------------
  |  Branch (46:9): [True: 307, False: 3]
  ------------------
   47|    307|        crc = (zip_uint32_t)crc32(crc, s->raw, s->length);
   48|    307|    }
   49|       |
   50|    310|    return crc;
   51|    310|}
_zip_string_free:
   69|   143k|void _zip_string_free(zip_string_t *s) {
   70|   143k|    if (s == NULL) {
  ------------------
  |  Branch (70:9): [True: 48.0k, False: 95.5k]
  ------------------
   71|  48.0k|        return;
   72|  48.0k|    }
   73|       |
   74|  95.5k|    free(s->raw);
   75|  95.5k|    free(s->converted);
   76|  95.5k|    free(s);
   77|  95.5k|}
_zip_string_get:
   80|   127k|const zip_uint8_t *_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error) {
   81|   127k|    static const zip_uint8_t empty[1] = "";
   82|       |
   83|   127k|    if (string == NULL) {
  ------------------
  |  Branch (83:9): [True: 0, False: 127k]
  ------------------
   84|      0|        if (lenp) {
  ------------------
  |  Branch (84:13): [True: 0, False: 0]
  ------------------
   85|      0|            *lenp = 0;
   86|      0|        }
   87|      0|        return empty;
   88|      0|    }
   89|       |
   90|   127k|    if ((flags & ZIP_FL_ENC_RAW) == 0) {
  ------------------
  |  |  102|   127k|#define ZIP_FL_ENC_RAW 64u     /* get unmodified string */
  ------------------
  |  Branch (90:9): [True: 127k, False: 204]
  ------------------
   91|       |        /* start guessing */
   92|   127k|        if (string->encoding == ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (92:13): [True: 63.1k, False: 64.0k]
  ------------------
   93|       |            /* guess encoding, sets string->encoding */
   94|  63.1k|            (void)_zip_guess_encoding(string, ZIP_ENCODING_UNKNOWN);
   95|  63.1k|        }
   96|       |
   97|   127k|        if (((flags & ZIP_FL_ENC_STRICT) && string->encoding != ZIP_ENCODING_ASCII && string->encoding != ZIP_ENCODING_UTF8_KNOWN) || (string->encoding == ZIP_ENCODING_CP437)) {
  ------------------
  |  |  103|   127k|#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
  ------------------
  |  Branch (97:14): [True: 0, False: 127k]
  |  Branch (97:45): [True: 0, False: 0]
  |  Branch (97:87): [True: 0, False: 0]
  |  Branch (97:135): [True: 89.0k, False: 38.0k]
  ------------------
   98|  89.0k|            if (string->converted == NULL) {
  ------------------
  |  Branch (98:17): [True: 57.8k, False: 31.1k]
  ------------------
   99|  57.8k|                if ((string->converted = _zip_cp437_to_utf8(string->raw, string->length, &string->converted_length, error)) == NULL) {
  ------------------
  |  Branch (99:21): [True: 0, False: 57.8k]
  ------------------
  100|      0|                    return NULL;
  101|      0|                }
  102|  57.8k|            }
  103|  89.0k|            if (lenp) {
  ------------------
  |  Branch (103:17): [True: 0, False: 89.0k]
  ------------------
  104|      0|                *lenp = string->converted_length;
  105|      0|            }
  106|  89.0k|            return string->converted;
  107|  89.0k|        }
  108|   127k|    }
  109|       |
  110|  38.2k|    if (lenp) {
  ------------------
  |  Branch (110:9): [True: 204, False: 38.0k]
  ------------------
  111|    204|        *lenp = string->length;
  112|    204|    }
  113|  38.2k|    return string->raw;
  114|   127k|}
_zip_string_length:
  131|   107k|zip_uint16_t _zip_string_length(const zip_string_t *s) {
  132|   107k|    if (s == NULL) {
  ------------------
  |  Branch (132:9): [True: 21.0k, False: 86.5k]
  ------------------
  133|  21.0k|        return 0;
  134|  21.0k|    }
  135|       |
  136|  86.5k|    return s->length;
  137|   107k|}
_zip_string_new:
  140|  95.5k|zip_string_t *_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error) {
  141|  95.5k|    zip_string_t *s;
  142|  95.5k|    zip_encoding_type_t expected_encoding;
  143|       |
  144|  95.5k|    if (length == 0) {
  ------------------
  |  Branch (144:9): [True: 1, False: 95.5k]
  ------------------
  145|      1|        return NULL;
  146|      1|    }
  147|       |
  148|  95.5k|    switch (flags & ZIP_FL_ENCODING_ALL) {
  ------------------
  |  |  266|  95.5k|#define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  101|  95.5k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  108|  95.5k|#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
  |  |  ------------------
  |  |               #define ZIP_FL_ENCODING_ALL (ZIP_FL_ENC_GUESS | ZIP_FL_ENC_CP437 | ZIP_FL_ENC_UTF_8)
  |  |  ------------------
  |  |  |  |  107|  95.5k|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  |  |  ------------------
  ------------------
  149|  95.4k|    case ZIP_FL_ENC_GUESS:
  ------------------
  |  |  101|  95.4k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  |  Branch (149:5): [True: 95.4k, False: 104]
  ------------------
  150|  95.4k|        expected_encoding = ZIP_ENCODING_UNKNOWN;
  151|  95.4k|        break;
  152|    104|    case ZIP_FL_ENC_UTF_8:
  ------------------
  |  |  107|    104|#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
  ------------------
  |  Branch (152:5): [True: 104, False: 95.4k]
  ------------------
  153|    104|        expected_encoding = ZIP_ENCODING_UTF8_KNOWN;
  154|    104|        break;
  155|      0|    case ZIP_FL_ENC_CP437:
  ------------------
  |  |  108|      0|#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
  ------------------
  |  Branch (155:5): [True: 0, False: 95.5k]
  ------------------
  156|      0|        expected_encoding = ZIP_ENCODING_CP437;
  157|      0|        break;
  158|      0|    default:
  ------------------
  |  Branch (158:5): [True: 0, False: 95.5k]
  ------------------
  159|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  160|      0|        return NULL;
  161|  95.5k|    }
  162|       |
  163|  95.5k|    if ((s = (zip_string_t *)malloc(sizeof(*s))) == NULL) {
  ------------------
  |  Branch (163:9): [True: 0, False: 95.5k]
  ------------------
  164|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  165|      0|        return NULL;
  166|      0|    }
  167|       |
  168|  95.5k|    if ((s->raw = (zip_uint8_t *)malloc((size_t)length + 1)) == NULL) {
  ------------------
  |  Branch (168:9): [True: 0, False: 95.5k]
  ------------------
  169|      0|        free(s);
  170|      0|        return NULL;
  171|      0|    }
  172|       |
  173|  95.5k|    (void)memcpy_s(s->raw, length + 1, raw, length);
  ------------------
  |  |  202|  95.5k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  174|  95.5k|    s->raw[length] = '\0';
  175|  95.5k|    s->length = length;
  176|  95.5k|    s->encoding = ZIP_ENCODING_UNKNOWN;
  177|  95.5k|    s->converted = NULL;
  178|  95.5k|    s->converted_length = 0;
  179|       |
  180|  95.5k|    if (expected_encoding != ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (180:9): [True: 104, False: 95.4k]
  ------------------
  181|    104|        if (_zip_guess_encoding(s, expected_encoding) == ZIP_ENCODING_ERROR) {
  ------------------
  |  Branch (181:13): [True: 1, False: 103]
  ------------------
  182|      1|            _zip_string_free(s);
  183|      1|            zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      1|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
  184|      1|            return NULL;
  185|      1|        }
  186|    104|    }
  187|       |
  188|  95.5k|    return s;
  189|  95.5k|}
_zip_string_write:
  192|  65.1k|int _zip_string_write(zip_t *za, const zip_string_t *s) {
  193|  65.1k|    if (s == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 65.1k]
  ------------------
  194|      0|        return 0;
  195|      0|    }
  196|       |
  197|  65.1k|    return _zip_write(za, s->raw, s->length);
  198|  65.1k|}

_zip_unchange:
   45|    484|int _zip_unchange(zip_t *za, zip_uint64_t idx, int allow_duplicates) {
   46|    484|    zip_int64_t i;
   47|    484|    bool renamed;
   48|       |
   49|    484|    if (idx >= za->nentry) {
  ------------------
  |  Branch (49:9): [True: 0, False: 484]
  ------------------
   50|      0|        zip_error_set(&za->error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   51|      0|        return -1;
   52|      0|    }
   53|       |
   54|    484|    renamed = za->entry[idx].changes && (za->entry[idx].changes->changed & ZIP_DIRENT_FILENAME);
  ------------------
  |  |  337|    484|#define ZIP_DIRENT_FILENAME 0x0002u
  ------------------
  |  Branch (54:15): [True: 484, False: 0]
  |  Branch (54:41): [True: 484, False: 0]
  ------------------
   55|    484|    if (!allow_duplicates && (renamed || za->entry[idx].deleted)) {
  ------------------
  |  Branch (55:9): [True: 0, False: 484]
  |  Branch (55:31): [True: 0, False: 0]
  |  Branch (55:42): [True: 0, False: 0]
  ------------------
   56|      0|        const char *orig_name = NULL;
   57|      0|        const char *changed_name = NULL;
   58|       |
   59|      0|        if (za->entry[idx].orig != NULL) {
  ------------------
  |  Branch (59:13): [True: 0, False: 0]
  ------------------
   60|      0|            if ((orig_name = _zip_get_name(za, idx, ZIP_FL_UNCHANGED, &za->error)) == NULL) {
  ------------------
  |  |   98|      0|#define ZIP_FL_UNCHANGED 8u  /* use original data, ignoring changes */
  ------------------
  |  Branch (60:17): [True: 0, False: 0]
  ------------------
   61|      0|                return -1;
   62|      0|            }
   63|       |
   64|      0|            i = _zip_name_locate(za, orig_name, 0, NULL);
   65|      0|            if (i >= 0 && (zip_uint64_t)i != idx) {
  ------------------
  |  Branch (65:17): [True: 0, False: 0]
  |  Branch (65:27): [True: 0, False: 0]
  ------------------
   66|      0|                zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
  ------------------
  |  |  141|      0|#define ZIP_ER_EXISTS 10          /* N File already exists */
  ------------------
   67|      0|                return -1;
   68|      0|            }
   69|      0|        }
   70|       |
   71|      0|        if (renamed) {
  ------------------
  |  Branch (71:13): [True: 0, False: 0]
  ------------------
   72|      0|            if ((changed_name = _zip_get_name(za, idx, 0, &za->error)) == NULL) {
  ------------------
  |  Branch (72:17): [True: 0, False: 0]
  ------------------
   73|      0|                return -1;
   74|      0|            }
   75|      0|        }
   76|       |
   77|      0|        if (orig_name) {
  ------------------
  |  Branch (77:13): [True: 0, False: 0]
  ------------------
   78|      0|            if (_zip_hash_add(za->names, (const zip_uint8_t *)orig_name, idx, 0, &za->error) == false) {
  ------------------
  |  Branch (78:17): [True: 0, False: 0]
  ------------------
   79|      0|                return -1;
   80|      0|            }
   81|      0|        }
   82|      0|        if (changed_name) {
  ------------------
  |  Branch (82:13): [True: 0, False: 0]
  ------------------
   83|      0|            if (_zip_hash_delete(za->names, (const zip_uint8_t *)changed_name, &za->error) == false) {
  ------------------
  |  Branch (83:17): [True: 0, False: 0]
  ------------------
   84|      0|                _zip_hash_delete(za->names, (const zip_uint8_t *)orig_name, NULL);
   85|      0|                return -1;
   86|      0|            }
   87|      0|        }
   88|      0|    }
   89|       |
   90|    484|    _zip_dirent_free(za->entry[idx].changes);
   91|    484|    za->entry[idx].changes = NULL;
   92|       |
   93|    484|    _zip_unchange_data(za->entry + idx);
   94|       |
   95|    484|    return 0;
   96|    484|}

_zip_unchange_data:
   37|  50.1M|void _zip_unchange_data(zip_entry_t *ze) {
   38|  50.1M|    if (ze->source) {
  ------------------
  |  Branch (38:9): [True: 25.1k, False: 50.1M]
  ------------------
   39|  25.1k|        zip_source_free(ze->source);
   40|  25.1k|        ze->source = NULL;
   41|  25.1k|    }
   42|       |
   43|  50.1M|    ze->deleted = 0;
   44|  50.1M|}

_zip_guess_encoding:
  103|   219k|zip_encoding_type_t _zip_guess_encoding(zip_string_t *str, zip_encoding_type_t expected_encoding) {
  104|   219k|    zip_encoding_type_t enc;
  105|   219k|    const zip_uint8_t *name;
  106|   219k|    zip_uint32_t i, j, ulen, codepoint;
  107|   219k|    bool can_be_ascii = true;
  108|   219k|    bool can_be_utf8 = true;
  109|   219k|    bool has_control_characters = false;
  110|       |
  111|   219k|    if (str == NULL) {
  ------------------
  |  Branch (111:9): [True: 55.6k, False: 163k]
  ------------------
  112|  55.6k|        return ZIP_ENCODING_ASCII;
  113|  55.6k|    }
  114|       |
  115|   163k|    name = str->raw;
  116|       |
  117|   163k|    if (str->encoding != ZIP_ENCODING_UNKNOWN) {
  ------------------
  |  Branch (117:9): [True: 69.9k, False: 93.8k]
  ------------------
  118|  69.9k|        return str->encoding;
  119|  69.9k|    }
  120|       |
  121|   983k|    for (i = 0; i < str->length; i++) {
  ------------------
  |  Branch (121:17): [True: 936k, False: 46.5k]
  ------------------
  122|   936k|        if (name[i] < 128) {
  ------------------
  |  Branch (122:13): [True: 883k, False: 52.6k]
  ------------------
  123|   883k|            if (name[i] < 32 && name[i] != '\r' && name[i] != '\n' && name[i] != '\t') {
  ------------------
  |  Branch (123:17): [True: 199k, False: 684k]
  |  Branch (123:33): [True: 198k, False: 1.08k]
  |  Branch (123:52): [True: 197k, False: 651]
  |  Branch (123:71): [True: 171k, False: 25.9k]
  ------------------
  124|   171k|                has_control_characters = true;
  125|   171k|            }
  126|   883k|            continue;
  127|   883k|        }
  128|       |
  129|  52.6k|        can_be_ascii = false;
  130|  52.6k|        if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) {
  ------------------
  |  |   89|  52.6k|#define UTF_8_LEN_2_MASK 0xe0
  ------------------
                      if ((name[i] & UTF_8_LEN_2_MASK) == UTF_8_LEN_2_MATCH) {
  ------------------
  |  |   90|  52.6k|#define UTF_8_LEN_2_MATCH 0xc0
  ------------------
  |  Branch (130:13): [True: 13.5k, False: 39.0k]
  ------------------
  131|  13.5k|            ulen = 1;
  132|  13.5k|            codepoint = name[i] & ~UTF_8_LEN_2_MASK;
  ------------------
  |  |   89|  13.5k|#define UTF_8_LEN_2_MASK 0xe0
  ------------------
  133|  13.5k|        }
  134|  39.0k|        else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) {
  ------------------
  |  |   91|  39.0k|#define UTF_8_LEN_3_MASK 0xf0
  ------------------
                      else if ((name[i] & UTF_8_LEN_3_MASK) == UTF_8_LEN_3_MATCH) {
  ------------------
  |  |   92|  39.0k|#define UTF_8_LEN_3_MATCH 0xe0
  ------------------
  |  Branch (134:18): [True: 6.28k, False: 32.8k]
  ------------------
  135|  6.28k|            ulen = 2;
  136|  6.28k|            codepoint = name[i] & ~UTF_8_LEN_3_MASK;
  ------------------
  |  |   91|  6.28k|#define UTF_8_LEN_3_MASK 0xf0
  ------------------
  137|  6.28k|        }
  138|  32.8k|        else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) {
  ------------------
  |  |   93|  32.8k|#define UTF_8_LEN_4_MASK 0xf8
  ------------------
                      else if ((name[i] & UTF_8_LEN_4_MASK) == UTF_8_LEN_4_MATCH) {
  ------------------
  |  |   94|  32.8k|#define UTF_8_LEN_4_MATCH 0xf0
  ------------------
  |  Branch (138:18): [True: 4.15k, False: 28.6k]
  ------------------
  139|  4.15k|            ulen = 3;
  140|  4.15k|            codepoint = name[i] & ~UTF_8_LEN_4_MASK;
  ------------------
  |  |   93|  4.15k|#define UTF_8_LEN_4_MASK 0xf8
  ------------------
  141|  4.15k|        }
  142|  28.6k|        else {
  143|  28.6k|            can_be_utf8 = false;
  144|  28.6k|            break;
  145|  28.6k|        }
  146|       |
  147|  23.9k|        if (i + ulen >= str->length) {
  ------------------
  |  Branch (147:13): [True: 1.22k, False: 22.7k]
  ------------------
  148|  1.22k|            can_be_utf8 = false;
  149|  1.22k|            break;
  150|  1.22k|        }
  151|       |
  152|  32.5k|        for (j = 1; j <= ulen; j++) {
  ------------------
  |  Branch (152:21): [True: 26.9k, False: 5.61k]
  ------------------
  153|  26.9k|            if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
  ------------------
  |  |   95|  26.9k|#define UTF_8_CONTINUE_MASK 0xc0
  ------------------
                          if ((name[i + j] & UTF_8_CONTINUE_MASK) != UTF_8_CONTINUE_MATCH) {
  ------------------
  |  |   96|  26.9k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  |  Branch (153:17): [True: 17.1k, False: 9.79k]
  ------------------
  154|  17.1k|                can_be_utf8 = false;
  155|  17.1k|                goto done;
  156|  17.1k|            }
  157|  9.79k|            codepoint = (codepoint << 6) | (name[i + j] & UTF_8_CONTINUE_VALUE_MASK);
  ------------------
  |  |   97|  9.79k|#define UTF_8_CONTINUE_VALUE_MASK 0x3f
  ------------------
  158|  9.79k|        }
  159|       |
  160|       |        /* reject overlong encodings, surrogate halves, and code points above U+10FFFF */
  161|  5.61k|        if (codepoint < _utf8_minimum_code_point[ulen] || (codepoint >= 0xd800 && codepoint <= 0xdfff) || codepoint > 0x10ffff) {
  ------------------
  |  Branch (161:13): [True: 241, False: 5.37k]
  |  Branch (161:60): [True: 615, False: 4.75k]
  |  Branch (161:83): [True: 32, False: 583]
  |  Branch (161:107): [True: 62, False: 5.27k]
  ------------------
  162|    335|            can_be_utf8 = false;
  163|    335|            goto done;
  164|    335|        }
  165|  5.27k|        i += ulen;
  166|  5.27k|    }
  167|       |
  168|  93.8k|done:
  169|  93.8k|    enc = ZIP_ENCODING_CP437;
  170|       |
  171|  93.8k|    switch (expected_encoding) {
  ------------------
  |  Branch (171:13): [True: 93.8k, False: 0]
  ------------------
  172|    380|    case ZIP_ENCODING_UTF8_KNOWN:
  ------------------
  |  Branch (172:5): [True: 380, False: 93.5k]
  ------------------
  173|    380|    case ZIP_ENCODING_UTF8_GUESSED:
  ------------------
  |  Branch (173:5): [True: 0, False: 93.8k]
  ------------------
  174|    380|        if (can_be_utf8) {
  ------------------
  |  Branch (174:13): [True: 376, False: 4]
  ------------------
  175|    376|            enc = ZIP_ENCODING_UTF8_KNOWN;
  176|    376|        }
  177|      4|        else {
  178|      4|            enc = ZIP_ENCODING_ERROR;
  179|      4|        }
  180|    380|        break;
  181|       |
  182|      0|    case ZIP_ENCODING_ASCII:
  ------------------
  |  Branch (182:5): [True: 0, False: 93.8k]
  ------------------
  183|      0|        if (can_be_ascii && !has_control_characters) {
  ------------------
  |  Branch (183:13): [True: 0, False: 0]
  |  Branch (183:29): [True: 0, False: 0]
  ------------------
  184|      0|            enc = ZIP_ENCODING_ASCII;
  185|      0|        }
  186|      0|        else {
  187|      0|            enc = ZIP_ENCODING_ERROR;
  188|      0|        }
  189|      0|        break;
  190|       |
  191|      0|    case ZIP_ENCODING_CP437:
  ------------------
  |  Branch (191:5): [True: 0, False: 93.8k]
  ------------------
  192|      0|        enc = ZIP_ENCODING_CP437;
  193|      0|        break;
  194|       |
  195|  93.5k|    case ZIP_ENCODING_UNKNOWN:
  ------------------
  |  Branch (195:5): [True: 93.5k, False: 380]
  ------------------
  196|  93.5k|        if (can_be_ascii && !has_control_characters) {
  ------------------
  |  Branch (196:13): [True: 45.0k, False: 48.4k]
  |  Branch (196:29): [True: 31.2k, False: 13.7k]
  ------------------
  197|       |            /* only bytes from 0x20-0x7F */
  198|  31.2k|            enc = ZIP_ENCODING_ASCII;
  199|  31.2k|        }
  200|  62.2k|        else if (can_be_ascii && has_control_characters) {
  ------------------
  |  Branch (200:18): [True: 13.7k, False: 48.4k]
  |  Branch (200:34): [True: 13.7k, False: 0]
  ------------------
  201|       |            /* only bytes from 0x00-0x7F */
  202|  13.7k|            enc = ZIP_ENCODING_CP437;
  203|  13.7k|        }
  204|  48.4k|        else if (can_be_utf8) {
  ------------------
  |  Branch (204:18): [True: 1.10k, False: 47.3k]
  ------------------
  205|       |            /* contains bytes from 0x80-0xFF and is valid UTF-8 */
  206|  1.10k|            enc = ZIP_ENCODING_UTF8_GUESSED;
  207|  1.10k|        }
  208|  47.3k|        else {
  209|       |            /* fallback */
  210|  47.3k|            enc = ZIP_ENCODING_CP437;
  211|  47.3k|        }
  212|  93.5k|        break;
  213|      0|    case ZIP_ENCODING_ERROR:
  ------------------
  |  Branch (213:5): [True: 0, False: 93.8k]
  ------------------
  214|       |        /* invalid, shouldn't happen */
  215|      0|        enc = ZIP_ENCODING_ERROR;
  216|      0|        break;
  217|  93.8k|    }
  218|       |
  219|  93.8k|    str->encoding = enc;
  220|  93.8k|    return enc;
  221|  93.8k|}
_zip_cp437_to_utf8:
  262|  57.8k|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) {
  263|  57.8k|    zip_uint8_t *cp437buf = (zip_uint8_t *)_cp437buf;
  264|  57.8k|    zip_uint8_t *utf8buf;
  265|  57.8k|    zip_uint32_t buflen, i, offset;
  266|       |
  267|  57.8k|    if (len == 0) {
  ------------------
  |  Branch (267:9): [True: 0, False: 57.8k]
  ------------------
  268|      0|        if (utf8_lenp) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  269|      0|            *utf8_lenp = 0;
  270|      0|        }
  271|      0|        return NULL;
  272|      0|    }
  273|       |
  274|  57.8k|    buflen = 1;
  275|  1.72M|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (275:17): [True: 1.66M, False: 57.8k]
  ------------------
  276|  1.66M|        buflen += _zip_unicode_to_utf8_len(_cp437_to_unicode[cp437buf[i]]);
  277|  1.66M|    }
  278|       |
  279|  57.8k|    if ((utf8buf = (zip_uint8_t *)malloc(buflen)) == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 57.8k]
  ------------------
  280|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  281|      0|        return NULL;
  282|      0|    }
  283|       |
  284|  57.8k|    offset = 0;
  285|  1.72M|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (285:17): [True: 1.66M, False: 57.8k]
  ------------------
  286|  1.66M|        offset += _zip_unicode_to_utf8(_cp437_to_unicode[cp437buf[i]], utf8buf + offset);
  287|  1.66M|    }
  288|       |
  289|  57.8k|    utf8buf[buflen - 1] = 0;
  290|  57.8k|    if (utf8_lenp) {
  ------------------
  |  Branch (290:9): [True: 57.8k, False: 0]
  ------------------
  291|  57.8k|        *utf8_lenp = buflen - 1;
  292|  57.8k|    }
  293|  57.8k|    return utf8buf;
  294|  57.8k|}
zip_utf-8.c:_zip_unicode_to_utf8_len:
  224|  1.66M|static zip_uint32_t _zip_unicode_to_utf8_len(zip_uint32_t codepoint) {
  225|  1.66M|    if (codepoint < 0x0080) {
  ------------------
  |  Branch (225:9): [True: 1.09M, False: 568k]
  ------------------
  226|  1.09M|        return 1;
  227|  1.09M|    }
  228|   568k|    if (codepoint < 0x0800) {
  ------------------
  |  Branch (228:9): [True: 158k, False: 410k]
  ------------------
  229|   158k|        return 2;
  230|   158k|    }
  231|   410k|    if (codepoint < 0x10000) {
  ------------------
  |  Branch (231:9): [True: 410k, False: 0]
  ------------------
  232|   410k|        return 3;
  233|   410k|    }
  234|      0|    return 4;
  235|   410k|}
zip_utf-8.c:_zip_unicode_to_utf8:
  238|  1.66M|static zip_uint32_t _zip_unicode_to_utf8(zip_uint32_t codepoint, zip_uint8_t *buf) {
  239|  1.66M|    if (codepoint < 0x0080) {
  ------------------
  |  Branch (239:9): [True: 1.09M, False: 568k]
  ------------------
  240|  1.09M|        buf[0] = codepoint & 0xff;
  241|  1.09M|        return 1;
  242|  1.09M|    }
  243|   568k|    if (codepoint < 0x0800) {
  ------------------
  |  Branch (243:9): [True: 158k, False: 410k]
  ------------------
  244|   158k|        buf[0] = (zip_uint8_t)(UTF_8_LEN_2_MATCH | ((codepoint >> 6) & 0x1f));
  ------------------
  |  |   90|   158k|#define UTF_8_LEN_2_MATCH 0xc0
  ------------------
  245|   158k|        buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
  ------------------
  |  |   96|   158k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  246|   158k|        return 2;
  247|   158k|    }
  248|   410k|    if (codepoint < 0x10000) {
  ------------------
  |  Branch (248:9): [True: 410k, False: 0]
  ------------------
  249|   410k|        buf[0] = (zip_uint8_t)(UTF_8_LEN_3_MATCH | ((codepoint >> 12) & 0x0f));
  ------------------
  |  |   92|   410k|#define UTF_8_LEN_3_MATCH 0xe0
  ------------------
  250|   410k|        buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f));
  ------------------
  |  |   96|   410k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  251|   410k|        buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
  ------------------
  |  |   96|   410k|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  252|   410k|        return 3;
  253|   410k|    }
  254|      0|    buf[0] = (zip_uint8_t)(UTF_8_LEN_4_MATCH | ((codepoint >> 18) & 0x07));
  ------------------
  |  |   94|      0|#define UTF_8_LEN_4_MATCH 0xf0
  ------------------
  255|      0|    buf[1] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 12) & 0x3f));
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  256|      0|    buf[2] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | ((codepoint >> 6) & 0x3f));
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  257|      0|    buf[3] = (zip_uint8_t)(UTF_8_CONTINUE_MATCH | (codepoint & 0x3f));
  ------------------
  |  |   96|      0|#define UTF_8_CONTINUE_MATCH 0x80
  ------------------
  258|      0|    return 4;
  259|   410k|}

_zip_winzip_aes_new:
   76|  16.8k|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 encryption_method, zip_uint8_t *password_verify, zip_error_t *error) {
   77|  16.8k|    zip_winzip_aes_t *ctx;
   78|  16.8k|    zip_uint8_t buffer[2 * (MAX_KEY_LENGTH / 8) + WINZIP_AES_PASSWORD_VERIFY_LENGTH];
   79|  16.8k|    zip_uint16_t key_size = 0; /* in bits */
   80|  16.8k|    zip_uint16_t key_length;   /* in bytes */
   81|       |
   82|  16.8k|    switch (encryption_method) {
  ------------------
  |  Branch (82:13): [True: 16.8k, False: 0]
  ------------------
   83|  3.94k|    case ZIP_EM_AES_128:
  ------------------
  |  |  220|  3.94k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
  |  Branch (83:5): [True: 3.94k, False: 12.9k]
  ------------------
   84|  3.94k|        key_size = 128;
   85|  3.94k|        break;
   86|      0|    case ZIP_EM_AES_192:
  ------------------
  |  |  221|      0|#define ZIP_EM_AES_192 0x0102
  ------------------
  |  Branch (86:5): [True: 0, False: 16.8k]
  ------------------
   87|      0|        key_size = 192;
   88|      0|        break;
   89|  12.9k|    case ZIP_EM_AES_256:
  ------------------
  |  |  222|  12.9k|#define ZIP_EM_AES_256 0x0103
  ------------------
  |  Branch (89:5): [True: 12.9k, False: 3.94k]
  ------------------
   90|  12.9k|        key_size = 256;
   91|  12.9k|        break;
   92|  16.8k|    }
   93|       |
   94|  16.8k|    if (key_size == 0 || salt == NULL || password == NULL || password_length == 0) {
  ------------------
  |  Branch (94:9): [True: 0, False: 16.8k]
  |  Branch (94:26): [True: 0, False: 16.8k]
  |  Branch (94:42): [True: 0, False: 16.8k]
  |  Branch (94:62): [True: 0, False: 16.8k]
  ------------------
   95|      0|        zip_error_set(error, ZIP_ER_INVAL, 0);
  ------------------
  |  |  149|      0|#define ZIP_ER_INVAL 18           /* N Invalid argument */
  ------------------
   96|      0|        return NULL;
   97|      0|    }
   98|       |
   99|  16.8k|    key_length = key_size / 8;
  100|       |
  101|  16.8k|    if ((ctx = (zip_winzip_aes_t *)malloc(sizeof(*ctx))) == NULL) {
  ------------------
  |  Branch (101:9): [True: 0, False: 16.8k]
  ------------------
  102|      0|        zip_error_set(error, ZIP_ER_MEMORY, 0);
  ------------------
  |  |  145|      0|#define ZIP_ER_MEMORY 14          /* N Malloc failure */
  ------------------
  103|      0|        return NULL;
  104|      0|    }
  105|       |
  106|  16.8k|    memset(ctx->counter, 0, sizeof(ctx->counter));
  107|  16.8k|    ctx->pad_offset = ZIP_CRYPTO_AES_BLOCK_LENGTH;
  ------------------
  |  |   38|  16.8k|#define ZIP_CRYPTO_AES_BLOCK_LENGTH 16
  ------------------
  108|       |
  109|  16.8k|    if (!_zip_crypto_pbkdf2(password, password_length, salt, key_length / 2, PBKDF2_ITERATIONS, buffer, 2 * key_length + WINZIP_AES_PASSWORD_VERIFY_LENGTH)) {
  ------------------
  |  |   71|  16.8k|#define _zip_crypto_pbkdf2(key, key_length, salt, salt_length, iterations, output, output_length) (PKCS5_PBKDF2_HMAC_SHA1((const char *)(key), (key_length), (salt), (salt_length), (iterations), (output_length), (output)))
  ------------------
  |  Branch (109:9): [True: 0, False: 16.8k]
  ------------------
  110|      0|        free(ctx);
  111|      0|        return NULL;
  112|      0|    }
  113|       |
  114|  16.8k|    if ((ctx->aes = _zip_crypto_aes_new(buffer, key_size, error)) == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 16.8k]
  ------------------
  115|      0|        _zip_crypto_clear(buffer, sizeof(buffer));
  ------------------
  |  |  533|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  116|      0|        _zip_crypto_clear(ctx, sizeof(*ctx));
  ------------------
  |  |  533|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  117|      0|        free(ctx);
  118|      0|        return NULL;
  119|      0|    }
  120|  16.8k|    if ((ctx->hmac = _zip_crypto_hmac_new(buffer + key_length, key_length, error)) == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 16.8k]
  ------------------
  121|      0|        _zip_crypto_clear(buffer, sizeof(buffer));
  ------------------
  |  |  533|      0|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  122|      0|        _zip_crypto_aes_free(ctx->aes);
  123|      0|        free(ctx);
  124|      0|        return NULL;
  125|      0|    }
  126|       |
  127|  16.8k|    if (password_verify) {
  ------------------
  |  Branch (127:9): [True: 16.8k, False: 0]
  ------------------
  128|  16.8k|        (void)memcpy_s(password_verify, WINZIP_AES_PASSWORD_VERIFY_LENGTH, buffer + (2 * key_size / 8), WINZIP_AES_PASSWORD_VERIFY_LENGTH);
  ------------------
  |  |  202|  16.8k|#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
  ------------------
  129|  16.8k|    }
  130|       |
  131|  16.8k|    _zip_crypto_clear(buffer, sizeof(buffer));
  ------------------
  |  |  533|  16.8k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  132|       |
  133|  16.8k|    return ctx;
  134|  16.8k|}
_zip_winzip_aes_encrypt:
  137|  8.56k|bool _zip_winzip_aes_encrypt(zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length) {
  138|  8.56k|    return aes_crypt(ctx, data, length) && _zip_crypto_hmac(ctx->hmac, data, length);
  ------------------
  |  |   60|  17.1k|#define _zip_crypto_hmac(hmac, data, length) (HMAC_Update((hmac), (data), (length)) == 1)
  |  |  ------------------
  |  |  |  Branch (60:46): [True: 8.56k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (138:12): [True: 8.56k, False: 0]
  ------------------
  139|  8.56k|}
_zip_winzip_aes_decrypt:
  142|  7.82k|bool _zip_winzip_aes_decrypt(zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length) {
  143|  7.82k|    return _zip_crypto_hmac(ctx->hmac, data, length) && aes_crypt(ctx, data, length);
  ------------------
  |  |   60|  15.6k|#define _zip_crypto_hmac(hmac, data, length) (HMAC_Update((hmac), (data), (length)) == 1)
  |  |  ------------------
  |  |  |  Branch (60:46): [True: 7.82k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (143:57): [True: 7.82k, False: 0]
  ------------------
  144|  7.82k|}
_zip_winzip_aes_finish:
  147|  16.3k|bool _zip_winzip_aes_finish(zip_winzip_aes_t *ctx, zip_uint8_t *hmac) {
  148|  16.3k|    return _zip_crypto_hmac_output(ctx->hmac, hmac);
  149|  16.3k|}
_zip_winzip_aes_free:
  152|  33.2k|void _zip_winzip_aes_free(zip_winzip_aes_t *ctx) {
  153|  33.2k|    if (ctx == NULL) {
  ------------------
  |  Branch (153:9): [True: 16.3k, False: 16.8k]
  ------------------
  154|  16.3k|        return;
  155|  16.3k|    }
  156|       |
  157|  16.8k|    _zip_crypto_aes_free(ctx->aes);
  158|  16.8k|    _zip_crypto_hmac_free(ctx->hmac);
  159|  16.8k|    _zip_crypto_clear(ctx, sizeof(*ctx));
  ------------------
  |  |  533|  16.8k|#define _zip_crypto_clear(b, l) memset((b), 0, (l))
  ------------------
  160|  16.8k|    free(ctx);
  161|  16.8k|}
zip_winzip_aes.c:aes_crypt:
   53|  16.3k|static bool aes_crypt(zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length) {
   54|  16.3k|    zip_uint64_t i, j;
   55|       |
   56|  24.1M|    for (i = 0; i < length; i++) {
  ------------------
  |  Branch (56:17): [True: 24.1M, False: 16.3k]
  ------------------
   57|  24.1M|        if (ctx->pad_offset == AES_BLOCK_SIZE) {
  ------------------
  |  |   83|  24.1M|#define AES_BLOCK_SIZE 16
  ------------------
  |  Branch (57:13): [True: 1.51M, False: 22.6M]
  ------------------
   58|  1.51M|            for (j = 0; j < 8; j++) {
  ------------------
  |  Branch (58:25): [True: 1.51M, False: 0]
  ------------------
   59|  1.51M|                ctx->counter[j]++;
   60|  1.51M|                if (ctx->counter[j] != 0) {
  ------------------
  |  Branch (60:21): [True: 1.51M, False: 68]
  ------------------
   61|  1.51M|                    break;
   62|  1.51M|                }
   63|  1.51M|            }
   64|  1.51M|            if (!_zip_crypto_aes_encrypt_block(ctx->aes, ctx->counter, ctx->pad)) {
  ------------------
  |  Branch (64:17): [True: 0, False: 1.51M]
  ------------------
   65|      0|                return false;
   66|      0|            }
   67|  1.51M|            ctx->pad_offset = 0;
   68|  1.51M|        }
   69|  24.1M|        data[i] ^= ctx->pad[ctx->pad_offset++];
   70|  24.1M|    }
   71|       |
   72|  16.3k|    return true;
   73|  16.3k|}

LLVMFuzzerTestOneInput:
   79|  4.98k|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   80|  4.98k|    zip_error_t error;
   81|  4.98k|    zip_source_t *src;
   82|  4.98k|    zip_t *za;
   83|  4.98k|    stream_t st;
   84|  4.98k|    int nops, i;
   85|       |
   86|  4.98k|    zip_error_init(&error);
   87|       |
   88|       |    /* Empty, growable, writable in-memory archive. */
   89|  4.98k|    src = zip_source_buffer_create(NULL, 0, 0, &error);
   90|  4.98k|    if (src == NULL) {
  ------------------
  |  Branch (90:9): [True: 0, False: 4.98k]
  ------------------
   91|      0|        zip_error_fini(&error);
   92|      0|        return 0;
   93|      0|    }
   94|       |    /* Keep an extra reference so the buffer survives the write zip_close()
   95|       |       and we can reopen it for the read-back round trip. */
   96|  4.98k|    zip_source_keep(src);
   97|       |
   98|  4.98k|    za = zip_open_from_source(src, ZIP_TRUNCATE, &error);
  ------------------
  |  |   89|  4.98k|#define ZIP_TRUNCATE 8
  ------------------
   99|  4.98k|    if (za == NULL) {
  ------------------
  |  Branch (99:9): [True: 0, False: 4.98k]
  ------------------
  100|      0|        zip_source_free(src); /* release our keep reference */
  101|      0|        zip_error_fini(&error);
  102|      0|        return 0;
  103|      0|    }
  104|  4.98k|    zip_error_fini(&error);
  105|       |
  106|  4.98k|    zip_set_default_password(za, PASSWORD);
  107|       |
  108|  4.98k|    st.p = data;
  109|  4.98k|    st.len = size;
  110|  4.98k|    st.pos = 0;
  111|       |
  112|  4.98k|    nops = (int)(u8(&st) % 32) + 1;
  113|  39.3k|    for (i = 0; i < nops && st.pos < st.len; i++) {
  ------------------
  |  Branch (113:17): [True: 38.9k, False: 412]
  |  Branch (113:29): [True: 34.3k, False: 4.57k]
  ------------------
  114|  34.3k|        uint8_t op = u8(&st) % 7;
  115|  34.3k|        char name[64];
  116|  34.3k|        size_t nlen = u8(&st) % (sizeof(name) - 1);
  117|  34.3k|        size_t k;
  118|   586k|        for (k = 0; k < nlen; k++) {
  ------------------
  |  Branch (118:21): [True: 551k, False: 34.3k]
  ------------------
  119|       |            /* avoid embedded NUL so it stays a valid C string */
  120|   551k|            name[k] = (char)(u8(&st) | 0x01);
  121|   551k|        }
  122|  34.3k|        name[nlen] = '\0';
  123|  34.3k|        if (name[0] == '\0') {
  ------------------
  |  Branch (123:13): [True: 12.1k, False: 22.1k]
  ------------------
  124|  12.1k|            name[0] = 'f';
  125|  12.1k|            name[1] = '\0';
  126|  12.1k|        }
  127|       |
  128|  34.3k|        switch (op) {
  ------------------
  |  Branch (128:17): [True: 34.3k, False: 0]
  ------------------
  129|  14.7k|        case 0:
  ------------------
  |  Branch (129:9): [True: 14.7k, False: 19.6k]
  ------------------
  130|  18.2k|        case 1: {
  ------------------
  |  Branch (130:9): [True: 3.54k, False: 30.8k]
  ------------------
  131|       |            /* add a file whose data is a slice of the input */
  132|  18.2k|            size_t dlen;
  133|  18.2k|            const uint8_t *slice = take(&st, u16(&st) % 4096u, &dlen);
  134|  18.2k|            void *buf = malloc(dlen ? dlen : 1);
  ------------------
  |  Branch (134:32): [True: 11.6k, False: 6.61k]
  ------------------
  135|  18.2k|            zip_source_t *fs;
  136|  18.2k|            zip_int64_t idx;
  137|  18.2k|            zip_int32_t methods[3];
  138|  18.2k|            zip_uint16_t ems[4];
  139|       |
  140|  18.2k|            if (buf == NULL) {
  ------------------
  |  Branch (140:17): [True: 0, False: 18.2k]
  ------------------
  141|      0|                break;
  142|      0|            }
  143|  18.2k|            if (dlen) {
  ------------------
  |  Branch (143:17): [True: 11.6k, False: 6.61k]
  ------------------
  144|  11.6k|                memcpy(buf, slice, dlen);
  145|  11.6k|            }
  146|       |            /* freep = 1: libzip owns buf and frees it with the source */
  147|  18.2k|            fs = zip_source_buffer(za, buf, dlen, 1);
  148|  18.2k|            if (fs == NULL) {
  ------------------
  |  Branch (148:17): [True: 0, False: 18.2k]
  ------------------
  149|      0|                free(buf);
  150|      0|                break;
  151|      0|            }
  152|  18.2k|            idx = zip_file_add(za, name, fs, ZIP_FL_OVERWRITE | ZIP_FL_ENC_GUESS);
  ------------------
  |  |  109|  18.2k|#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
  ------------------
                          idx = zip_file_add(za, name, fs, ZIP_FL_OVERWRITE | ZIP_FL_ENC_GUESS);
  ------------------
  |  |  101|  18.2k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  153|  18.2k|            if (idx < 0) {
  ------------------
  |  Branch (153:17): [True: 0, False: 18.2k]
  ------------------
  154|      0|                zip_source_free(fs);
  155|      0|                break;
  156|      0|            }
  157|  18.2k|            methods[0] = ZIP_CM_STORE;
  ------------------
  |  |  179|  18.2k|#define ZIP_CM_STORE 0    /* stored (uncompressed) */
  ------------------
  158|  18.2k|            methods[1] = ZIP_CM_DEFLATE;
  ------------------
  |  |  187|  18.2k|#define ZIP_CM_DEFLATE 8         /* deflated */
  ------------------
  159|  18.2k|            methods[2] = ZIP_CM_DEFAULT;
  ------------------
  |  |  178|  18.2k|#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
  ------------------
  160|  18.2k|            zip_set_file_compression(za, (zip_uint64_t)idx, methods[u8(&st) % 3], u8(&st) % 10);
  161|       |
  162|  18.2k|            ems[0] = ZIP_EM_NONE;
  ------------------
  |  |  207|  18.2k|#define ZIP_EM_NONE 0         /* not encrypted */
  ------------------
  163|  18.2k|            ems[1] = ZIP_EM_AES_128;
  ------------------
  |  |  220|  18.2k|#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
  ------------------
  164|  18.2k|            ems[2] = ZIP_EM_AES_256;
  ------------------
  |  |  222|  18.2k|#define ZIP_EM_AES_256 0x0103
  ------------------
  165|  18.2k|            ems[3] = ZIP_EM_TRAD_PKWARE;
  ------------------
  |  |  208|  18.2k|#define ZIP_EM_TRAD_PKWARE 1  /* traditional PKWARE encryption */
  ------------------
  166|  18.2k|            zip_file_set_encryption(za, (zip_uint64_t)idx, ems[u8(&st) % 4], PASSWORD);
  167|  18.2k|            break;
  168|  18.2k|        }
  169|       |
  170|  7.65k|        case 2:
  ------------------
  |  Branch (170:9): [True: 7.65k, False: 26.6k]
  ------------------
  171|  7.65k|            zip_dir_add(za, name, ZIP_FL_ENC_GUESS);
  ------------------
  |  |  101|  7.65k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  172|  7.65k|            break;
  173|       |
  174|  1.57k|        case 3: {
  ------------------
  |  Branch (174:9): [True: 1.57k, False: 32.7k]
  ------------------
  175|  1.57k|            size_t clen;
  176|  1.57k|            const uint8_t *c = take(&st, u8(&st) % 200u, &clen);
  177|  1.57k|            zip_set_archive_comment(za, (const char *)c, (zip_uint16_t)clen);
  178|  1.57k|            break;
  179|  18.2k|        }
  180|       |
  181|  4.91k|        case 4: {
  ------------------
  |  Branch (181:9): [True: 4.91k, False: 29.4k]
  ------------------
  182|  4.91k|            zip_int64_t n = zip_get_num_entries(za, 0);
  183|  4.91k|            zip_uint64_t idx;
  184|  4.91k|            if (n <= 0) {
  ------------------
  |  Branch (184:17): [True: 145, False: 4.76k]
  ------------------
  185|    145|                break;
  186|    145|            }
  187|  4.76k|            idx = u16(&st) % (zip_uint64_t)n;
  188|  4.76k|            if (u8(&st) & 1) {
  ------------------
  |  Branch (188:17): [True: 2.89k, False: 1.86k]
  ------------------
  189|  2.89k|                size_t clen;
  190|  2.89k|                const uint8_t *c = take(&st, u8(&st) % 200u, &clen);
  191|  2.89k|                zip_file_set_comment(za, idx, (const char *)c, (zip_uint16_t)clen, ZIP_FL_ENC_GUESS);
  ------------------
  |  |  101|  2.89k|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  192|  2.89k|            }
  193|  1.86k|            else {
  194|  1.86k|                zip_uint16_t efid = u16(&st);
  195|  1.86k|                size_t eflen;
  196|  1.86k|                const uint8_t *ef = take(&st, u8(&st) % 200u, &eflen);
  197|  1.86k|                zip_file_extra_field_set(za, idx, efid, ZIP_EXTRA_FIELD_NEW, ef, (zip_uint16_t)eflen, ZIP_FL_LOCAL);
  ------------------
  |  |  122|  1.86k|#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX
  |  |  ------------------
  |  |  |  |   38|  1.86k|#define ZIP_UINT16_MAX	 0xffff
  |  |  ------------------
  ------------------
                              zip_file_extra_field_set(za, idx, efid, ZIP_EXTRA_FIELD_NEW, ef, (zip_uint16_t)eflen, ZIP_FL_LOCAL);
  ------------------
  |  |  104|  1.86k|#define ZIP_FL_LOCAL 256u      /* in local header */
  ------------------
  198|  1.86k|            }
  199|  4.76k|            break;
  200|  4.91k|        }
  201|       |
  202|  1.04k|        case 5: {
  ------------------
  |  Branch (202:9): [True: 1.04k, False: 33.3k]
  ------------------
  203|  1.04k|            zip_int64_t n = zip_get_num_entries(za, 0);
  204|  1.04k|            if (n <= 0) {
  ------------------
  |  Branch (204:17): [True: 122, False: 923]
  ------------------
  205|    122|                break;
  206|    122|            }
  207|    923|            zip_file_rename(za, u16(&st) % (zip_uint64_t)n, name, ZIP_FL_ENC_GUESS);
  ------------------
  |  |  101|    923|#define ZIP_FL_ENC_GUESS 0u    /* guess string encoding (is default) */
  ------------------
  208|    923|            break;
  209|  1.04k|        }
  210|       |
  211|    884|        case 6: {
  ------------------
  |  Branch (211:9): [True: 884, False: 33.4k]
  ------------------
  212|    884|            zip_int64_t n = zip_get_num_entries(za, 0);
  213|    884|            if (n <= 0) {
  ------------------
  |  Branch (213:17): [True: 215, False: 669]
  ------------------
  214|    215|                break;
  215|    215|            }
  216|    669|            zip_delete(za, u16(&st) % (zip_uint64_t)n);
  217|    669|            break;
  218|    884|        }
  219|  34.3k|        }
  220|  34.3k|    }
  221|       |
  222|       |    /* Serialize: the write/encode path under test. */
  223|  4.98k|    if (zip_close(za) < 0) {
  ------------------
  |  Branch (223:9): [True: 0, False: 4.98k]
  ------------------
  224|      0|        zip_discard(za);
  225|      0|        zip_source_free(src); /* release keep reference */
  226|      0|        return 0;
  227|      0|    }
  228|       |
  229|       |    /* Round trip: reopen the freshly written archive and read it back.
  230|       |       zip_open_from_source() takes ownership of one source reference and
  231|       |       releases it on zip_close()/zip_discard(); keep one more reference so
  232|       |       our own reference survives this second open/close cycle. */
  233|  4.98k|    zip_source_keep(src);
  234|  4.98k|    zip_error_init(&error);
  235|  4.98k|    za = zip_open_from_source(src, 0, &error);
  236|  4.98k|    if (za == NULL) {
  ------------------
  |  Branch (236:9): [True: 2.34k, False: 2.64k]
  ------------------
  237|  2.34k|        zip_source_free(src); /* undo the keep above */
  238|  2.34k|        zip_source_free(src); /* release our original reference */
  239|  2.34k|        zip_error_fini(&error);
  240|  2.34k|        return 0;
  241|  2.34k|    }
  242|  2.64k|    zip_error_fini(&error);
  243|       |
  244|  2.64k|    zip_set_default_password(za, PASSWORD);
  245|  2.64k|    {
  246|  2.64k|        zip_int64_t n = zip_get_num_entries(za, 0);
  247|  2.64k|        zip_int64_t j;
  248|  2.64k|        char rbuf[8192];
  249|  21.2k|        for (j = 0; j < n; j++) {
  ------------------
  |  Branch (249:21): [True: 18.6k, False: 2.64k]
  ------------------
  250|  18.6k|            zip_file_t *f = zip_fopen_index(za, (zip_uint64_t)j, 0);
  251|  18.6k|            if (f == NULL) {
  ------------------
  |  Branch (251:17): [True: 0, False: 18.6k]
  ------------------
  252|      0|                continue;
  253|      0|            }
  254|  27.7k|            while (zip_fread(f, rbuf, sizeof(rbuf)) > 0) {
  ------------------
  |  Branch (254:20): [True: 9.14k, False: 18.6k]
  ------------------
  255|  9.14k|                ;
  256|  9.14k|            }
  257|  18.6k|            zip_fclose(f);
  258|  18.6k|        }
  259|  2.64k|    }
  260|       |
  261|  2.64k|    if (zip_close(za) < 0) {
  ------------------
  |  Branch (261:9): [True: 0, False: 2.64k]
  ------------------
  262|      0|        zip_discard(za);
  263|      0|    }
  264|  2.64k|    zip_source_free(src); /* release keep reference */
  265|  2.64k|    return 0;
  266|  4.98k|}
zip_write_roundtrip_fuzzer.c:_ZL2u8P8stream_t:
   47|   744k|u8(stream_t *s) {
   48|   744k|    return s->pos < s->len ? s->p[s->pos++] : 0;
  ------------------
  |  Branch (48:12): [True: 718k, False: 26.4k]
  ------------------
   49|   744k|}
zip_write_roundtrip_fuzzer.c:_ZL4takeP8stream_tmPm:
   60|  24.6k|take(stream_t *s, size_t max, size_t *out_len) {
   61|  24.6k|    size_t avail = s->len - s->pos;
   62|  24.6k|    size_t n = max;
   63|  24.6k|    if (n > avail) {
  ------------------
  |  Branch (63:9): [True: 2.99k, False: 21.6k]
  ------------------
   64|  2.99k|        n = avail;
   65|  2.99k|    }
   66|  24.6k|    const uint8_t *r = s->p + s->pos;
   67|  24.6k|    s->pos += n;
   68|  24.6k|    *out_len = n;
   69|  24.6k|    return r;
   70|  24.6k|}
zip_write_roundtrip_fuzzer.c:_ZL3u16P8stream_t:
   52|  26.5k|u16(stream_t *s) {
   53|  26.5k|    uint16_t v = u8(s);
   54|  26.5k|    v = (uint16_t)(v | ((uint16_t)u8(s) << 8));
   55|  26.5k|    return v;
   56|  26.5k|}

