]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_match: Use correct data type for iterator
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 24 May 2025 10:29:36 +0000 (12:29 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 24 May 2025 10:35:32 +0000 (12:35 +0200)
Iterating over a size_t with unsigned could lead to an endless loop
while adding uid/gid to a list which already counts 4 billion
entries.

I doubt that this can ever happen, given that the routines become
very slow with insertions, but better be safe than sorry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_match.c

index 67fc16fe956fc389b661cf1e856d6595f5b22a6f..2215f9a0c77a2602362b169087e9591d60245a80 100644 (file)
@@ -1680,7 +1680,7 @@ archive_match_owner_excluded(struct archive *_a,
 static int
 add_owner_id(struct archive_match *a, struct id_array *ids, int64_t id)
 {
-       unsigned i;
+       size_t i;
 
        if (ids->count + 1 >= ids->size) {
                void *p;
@@ -1717,10 +1717,10 @@ add_owner_id(struct archive_match *a, struct id_array *ids, int64_t id)
 static int
 match_owner_id(struct id_array *ids, int64_t id)
 {
-       unsigned b, m, t;
+       size_t b, m, t;
 
        t = 0;
-       b = (unsigned)ids->count;
+       b = ids->count;
        while (t < b) {
                m = (t + b)>>1;
                if (ids->ids[m] == id)