]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_match: Allow arbitrarily long match lists
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 24 May 2025 10:28:08 +0000 (12:28 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 24 May 2025 10:28:08 +0000 (12:28 +0200)
Turn unmatched_count into a size_t to support as many entries as
possible on the machine.

If more than INT_MAX entries are not matched, truncate the result
of archive_match_path_unmatched_inclusions for external callers.

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

index cefdf458d6cb6b60c94a3c37571146b7b83424d7..67fc16fe956fc389b661cf1e856d6595f5b22a6f 100644 (file)
@@ -35,6 +35,9 @@
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
 
 #include "archive.h"
 #include "archive_private.h"
@@ -53,7 +56,7 @@ struct match {
 struct match_list {
        struct match            *first;
        struct match            **last;
-       int                      unmatched_count;
+       size_t                   unmatched_count;
        struct match            *unmatched_next;
        int                      unmatched_eof;
 };
@@ -508,7 +511,9 @@ archive_match_path_unmatched_inclusions(struct archive *_a)
            ARCHIVE_STATE_NEW, "archive_match_unmatched_inclusions");
        a = (struct archive_match *)_a;
 
-       return (a->inclusions.unmatched_count);
+       if (a->inclusions.unmatched_count > (size_t)INT_MAX)
+               return INT_MAX;
+       return (int)(a->inclusions.unmatched_count);
 }
 
 int