Skip to content

Commit d3ae416

Browse files
authored
Merge pull request libarchive#1570 from ferivoz/mac
Fix size_t cast in read_mac_metadata_blob
2 parents 3aeea1e + a7ce8a6 commit d3ae416

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

libarchive/archive_read_support_format_tar.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ read_mac_metadata_blob(struct archive_read *a, struct tar *tar,
13961396
struct archive_entry *entry, const void *h, size_t *unconsumed)
13971397
{
13981398
int64_t size;
1399+
size_t msize;
13991400
const void *data;
14001401
const char *p, *name;
14011402
const wchar_t *wp, *wname;
@@ -1434,6 +1435,11 @@ read_mac_metadata_blob(struct archive_read *a, struct tar *tar,
14341435

14351436
/* Read the body as a Mac OS metadata blob. */
14361437
size = archive_entry_size(entry);
1438+
msize = (size_t)size;
1439+
if (size < 0 || (uintmax_t)msize != (uintmax_t)size) {
1440+
*unconsumed = 0;
1441+
return (ARCHIVE_FATAL);
1442+
}
14371443

14381444
/*
14391445
* TODO: Look beyond the body here to peek at the next header.
@@ -1447,13 +1453,13 @@ read_mac_metadata_blob(struct archive_read *a, struct tar *tar,
14471453
* Q: Is the above idea really possible? Even
14481454
* when there are GNU or pax extension entries?
14491455
*/
1450-
data = __archive_read_ahead(a, (size_t)size, NULL);
1456+
data = __archive_read_ahead(a, msize, NULL);
14511457
if (data == NULL) {
14521458
*unconsumed = 0;
14531459
return (ARCHIVE_FATAL);
14541460
}
1455-
archive_entry_copy_mac_metadata(entry, data, (size_t)size);
1456-
*unconsumed = (size_t)((size + 511) & ~ 511);
1461+
archive_entry_copy_mac_metadata(entry, data, msize);
1462+
*unconsumed = (msize + 511) & ~ 511;
14571463
tar_flush_unconsumed(a, unconsumed);
14581464
return (tar_read_header(a, tar, entry, unconsumed));
14591465
}

0 commit comments

Comments
 (0)