14
14
15
15
using namespace xamarin ::android::internal;
16
16
17
- using read_count_type = size_t ;
18
-
19
17
force_inline bool
20
18
EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8_t > const & buf, dynamic_local_string<SENSIBLE_PATH_MAX> &entry_name, ZipEntryLoadState &state) noexcept
21
19
{
@@ -157,7 +155,7 @@ EmbeddedAssemblies::zip_load_individual_assembly_entries (std::vector<uint8_t> c
157
155
// However, clang-tidy can't know that the value is owned by Mono and we must not free it, thus the suppression.
158
156
//
159
157
// NOLINTNEXTLINE(clang-analyzer-unix.Malloc)
160
- for (size_t i = 0 ; i < num_entries; i++) {
158
+ for (size_t i = 0uz ; i < num_entries; i++) {
161
159
bool interesting_entry = zip_load_entry_common (i, buf, entry_name, state);
162
160
if (!interesting_entry) {
163
161
continue ;
@@ -260,7 +258,7 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const&
260
258
bool assembly_store_found = false ;
261
259
262
260
log_debug (LOG_ASSEMBLY, " Looking for assembly stores in APK ('%s)" , assembly_store_file_path.data ());
263
- for (size_t i = 0 ; i < num_entries; i++) {
261
+ for (size_t i = 0uz ; i < num_entries; i++) {
264
262
if (all_required_zip_entries_found ()) {
265
263
need_to_scan_more_apks = false ;
266
264
break ;
@@ -341,17 +339,17 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
341
339
.file_name = apk_name,
342
340
.prefix = prefix,
343
341
.prefix_len = prefix_len,
344
- .buf_offset = 0 ,
345
- .compression_method = 0 ,
346
- .local_header_offset = 0 ,
347
- .data_offset = 0 ,
348
- .file_size = 0 ,
342
+ .buf_offset = 0uz ,
343
+ .compression_method = 0u ,
344
+ .local_header_offset = 0u ,
345
+ .data_offset = 0u ,
346
+ .file_size = 0u ,
349
347
.bundled_assemblies_slow_path = false ,
350
- .max_assembly_name_size = 0 ,
351
- .max_assembly_file_name_size = 0 ,
348
+ .max_assembly_name_size = 0u ,
349
+ .max_assembly_file_name_size = 0u ,
352
350
};
353
351
354
- ssize_t nread = read (fd, buf.data (), static_cast <read_count_type>( buf.size () ));
352
+ ssize_t nread = read (fd, buf.data (), buf.size ());
355
353
if (static_cast <size_t >(nread) != cd_size) {
356
354
Helpers::abort_application (
357
355
LOG_ASSEMBLY,
@@ -424,14 +422,14 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
424
422
}
425
423
426
424
std::array<uint8_t , ZIP_EOCD_LEN> eocd;
427
- ssize_t nread = ::read (fd, eocd.data (), static_cast <read_count_type>( eocd.size () ));
425
+ ssize_t nread = ::read (fd, eocd.data (), eocd.size ());
428
426
if (nread < 0 || nread != eocd.size ()) {
429
427
log_error (LOG_ASSEMBLY, " Failed to read EOCD from the APK: %s (nread: %d; errno: %d)" , std::strerror (errno), nread, errno);
430
428
return false ;
431
429
}
432
430
433
- size_t index = 0 ; // signature
434
- std::array<uint8_t , 4 > signature;
431
+ size_t index = 0uz ; // signature
432
+ std::array<uint8_t , 4uz > signature;
435
433
436
434
if (!zip_read_field (eocd, index , signature)) {
437
435
log_error (LOG_ASSEMBLY, " Failed to read EOCD signature" );
@@ -443,7 +441,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
443
441
}
444
442
445
443
// Most probably a ZIP with comment
446
- constexpr size_t alloc_size = 65535 + ZIP_EOCD_LEN; // 64k is the biggest comment size allowed
444
+ constexpr size_t alloc_size = 65535uz + ZIP_EOCD_LEN; // 64k is the biggest comment size allowed
447
445
ret = ::lseek (fd, static_cast <off_t >(-alloc_size), SEEK_END);
448
446
if (ret < 0 ) {
449
447
log_error (LOG_ASSEMBLY, " Unable to seek into the file to find ECOD before APK comment: %s (ret: %d; errno: %d)" , std::strerror (errno), ret, errno);
@@ -452,7 +450,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
452
450
453
451
std::vector<uint8_t > buf (alloc_size);
454
452
455
- nread = ::read (fd, buf.data (), static_cast <read_count_type>( buf.size () ));
453
+ nread = ::read (fd, buf.data (), buf.size ());
456
454
457
455
if (nread < 0 || static_cast <size_t >(nread) != alloc_size) {
458
456
log_error (LOG_ASSEMBLY, " Failed to read EOCD and comment from the APK: %s (nread: %d; errno: %d)" , std::strerror (errno), nread, errno);
@@ -462,7 +460,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
462
460
// We scan from the end to save time
463
461
bool found = false ;
464
462
const uint8_t * data = buf.data ();
465
- for (ssize_t i = static_cast <ssize_t >(alloc_size - (ZIP_EOCD_LEN + 2 )); i >= 0 ; i--) {
463
+ for (ssize_t i = static_cast <ssize_t >(alloc_size - (ZIP_EOCD_LEN + 2 )); i >= 0z ; i--) {
466
464
if (memcmp (data + i, ZIP_EOCD_MAGIC.data (), sizeof (ZIP_EOCD_MAGIC)) != 0 )
467
465
continue ;
468
466
@@ -482,8 +480,8 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
482
480
bool
483
481
EmbeddedAssemblies::zip_adjust_data_offset (int fd, ZipEntryLoadState &state)
484
482
{
485
- static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26 ;
486
- static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28 ;
483
+ static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26uz ;
484
+ static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28uz ;
487
485
488
486
off_t result = ::lseek (fd, static_cast <off_t >(state.local_header_offset ), SEEK_SET);
489
487
if (result < 0 ) {
@@ -534,9 +532,9 @@ template<size_t BufSize>
534
532
bool
535
533
EmbeddedAssemblies::zip_extract_cd_info (std::array<uint8_t , BufSize> const & buf, uint32_t & cd_offset, uint32_t & cd_size, uint16_t & cd_entries)
536
534
{
537
- constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10 ;
538
- constexpr size_t EOCD_CD_SIZE_OFFSET = 12 ;
539
- constexpr size_t EOCD_CD_START_OFFSET = 16 ;
535
+ constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10uz ;
536
+ constexpr size_t EOCD_CD_SIZE_OFFSET = 12uz ;
537
+ constexpr size_t EOCD_CD_START_OFFSET = 16uz ;
540
538
541
539
static_assert (BufSize >= ZIP_EOCD_LEN, " Buffer too short for EOCD" );
542
540
@@ -627,12 +625,12 @@ EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dy
627
625
bool
628
626
EmbeddedAssemblies::zip_read_entry_info (std::vector<uint8_t > const & buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state)
629
627
{
630
- constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10 ;
631
- constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24 ;
632
- constexpr size_t CD_FILENAME_LENGTH_OFFSET = 28 ;
633
- constexpr size_t CD_EXTRA_LENGTH_OFFSET = 30 ;
634
- constexpr size_t CD_LOCAL_HEADER_POS_OFFSET = 42 ;
635
- constexpr size_t CD_COMMENT_LENGTH_OFFSET = 32 ;
628
+ constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10uz ;
629
+ constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24uz ;
630
+ constexpr size_t CD_FILENAME_LENGTH_OFFSET = 28uz ;
631
+ constexpr size_t CD_EXTRA_LENGTH_OFFSET = 30uz ;
632
+ constexpr size_t CD_LOCAL_HEADER_POS_OFFSET = 42uz ;
633
+ constexpr size_t CD_COMMENT_LENGTH_OFFSET = 32uz ;
636
634
637
635
size_t index = state.buf_offset ;
638
636
zip_ensure_valid_params (buf, index , ZIP_CENTRAL_LEN);
0 commit comments