From: AZero13 Date: Thu, 6 Nov 2025 15:46:27 +0000 (-0500) Subject: Add error handling X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=daf5abf802d3aafd473ab0ba4c5d35d06d89dce3;p=thirdparty%2Flibarchive.git Add error handling --- diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index 72dde0730..7cd292f25 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -107,6 +107,8 @@ #define O_CLOEXEC 0 #endif +#define MAX_FILESYSTEM_ID 1000000 + #if defined(__hpux) && !defined(HAVE_DIRFD) #define dirfd(x) ((x)->__dd_fd) #define HAVE_DIRFD @@ -1412,6 +1414,10 @@ update_current_filesystem(struct archive_read_disk *a, int64_t dev) * This is the new filesystem which we have to generate a new ID for. */ fid = t->max_filesystem_id++; + if (fid > MAX_FILESYSTEM_ID) { + archive_set_error(&a->archive, ENOMEM, "Too many filesystems"); + return (ARCHIVE_FATAL); + } if (t->max_filesystem_id > t->allocated_filesystem) { int s; void *p; diff --git a/libarchive/archive_read_disk_windows.c b/libarchive/archive_read_disk_windows.c index 689a45958..17557a891 100644 --- a/libarchive/archive_read_disk_windows.c +++ b/libarchive/archive_read_disk_windows.c @@ -53,6 +53,8 @@ /* To deal with absolute symlink issues */ #define START_ABSOLUTE_SYMLINK_REPARSE L"\\??\\" +#define MAX_FILESYSTEM_ID 1000000 + /*- * This is a new directory-walking system that addresses a number * of problems I've had with fts(3). In particular, it has no @@ -1449,8 +1451,12 @@ update_current_filesystem(struct archive_read_disk *a, int64_t dev) * There is a new filesystem, we generate a new ID for. */ fid = t->max_filesystem_id++; + if (fid > MAX_FILESYSTEM_ID) { + archive_set_error(&a->archive, ENOMEM, "Too many filesystems"); + return (ARCHIVE_FATAL); + } if (t->max_filesystem_id > t->allocated_filesystem) { - size_t s; + int s; void *p; s = t->max_filesystem_id * 2;