diff --git a/dir.c b/dir.c index f6066cc01d835b..914060edfd635e 100644 --- a/dir.c +++ b/dir.c @@ -30,6 +30,7 @@ #include "symlinks.h" #include "trace2.h" #include "tree.h" +#include "hex.h" /* * Tells read_directory_recursive how a file or directory should be treated. @@ -1148,6 +1149,12 @@ static int add_patterns(const char *fname, const char *base, int baselen, } } + if (size > INT_MAX) { + warning("ignoring excessively large pattern file: %s", fname); + free(buf); + return -1; + } + add_patterns_from_buffer(buf, size, base, baselen, pl); return 0; } @@ -1204,6 +1211,13 @@ int add_patterns_from_blob_to_list( if (r != 1) return r; + if (size > INT_MAX) { + warning("ignoring excessively large pattern blob: %s", + oid_to_hex(oid)); + free(buf); + return -1; + } + add_patterns_from_buffer(buf, size, base, baselen, pl); return 0; }