]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix unchecked calloc result in make_table (rar)
authorTim Kientzle <kientzle@acm.org>
Sat, 16 May 2026 17:03:31 +0000 (10:03 -0700)
committerTim Kientzle <kientzle@acm.org>
Sat, 16 May 2026 17:03:31 +0000 (10:03 -0700)
If calloc fails, code->table would be NULL and passed directly to
make_table_recurse, causing a NULL dereference.

libarchive/archive_read_support_format_rar.c

index 3315c55a3fb8d441bfacfc5c3def0849e120ecb1..26a3e1e3b1ce086bc45baef796542236e5314653 100644 (file)
@@ -2840,6 +2840,10 @@ make_table(struct archive_read *a, struct huffman_code *code)
     code->tablesize = code->maxlength;
 
   code->table = calloc(((size_t)1U) << code->tablesize, sizeof(*code->table));
+  if (code->table == NULL) {
+    archive_set_error(&a->archive, ENOMEM, "Can't allocate memory");
+    return (ARCHIVE_FATAL);
+  }
 
   return make_table_recurse(a, code, 0, code->table, 0, code->tablesize);
 }