|
|
f485a7 |
From 88311f46cdfc719d26bb99d3b47944eb92ceae02 Mon Sep 17 00:00:00 2001
|
|
|
f485a7 |
From: Ondrej Dubaj <odubaj@redhat.com>
|
|
|
f485a7 |
Date: Tue, 30 Apr 2019 11:50:33 +0200
|
|
|
f485a7 |
Subject: [PATCH] Avoid a double-free when a window size of 0 is specified
|
|
|
f485a7 |
|
|
|
f485a7 |
new_size can be 0 with a malicious or corrupted RAR archive.
|
|
|
f485a7 |
|
|
|
f485a7 |
realloc(area, 0) is equivalent to free(area), so the region would
|
|
|
f485a7 |
be free()d here and the free()d again in the cleanup function.
|
|
|
f485a7 |
|
|
|
f485a7 |
Found with a setup running AFL, afl-rb, and qsym.
|
|
|
f485a7 |
---
|
|
|
f485a7 |
libarchive/archive_read_support_format_rar.c | 5 +++++
|
|
|
f485a7 |
1 file changed, 5 insertions(+)
|
|
|
f485a7 |
|
|
|
f485a7 |
diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c
|
|
|
f485a7 |
index c4a8278..3f88eef 100644
|
|
|
f485a7 |
--- a/libarchive/archive_read_support_format_rar.c
|
|
|
f485a7 |
+++ b/libarchive/archive_read_support_format_rar.c
|
|
|
f485a7 |
@@ -2317,6 +2317,11 @@ parse_codes(struct archive_read *a)
|
|
|
f485a7 |
new_size = DICTIONARY_MAX_SIZE;
|
|
|
f485a7 |
else
|
|
|
f485a7 |
new_size = rar_fls((unsigned int)rar->unp_size) << 1;
|
|
|
f485a7 |
+ if (new_size == 0) {
|
|
|
f485a7 |
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
|
|
|
f485a7 |
+ "Zero window size is invalid.");
|
|
|
f485a7 |
+ return (ARCHIVE_FATAL);
|
|
|
f485a7 |
+ }
|
|
|
f485a7 |
new_window = realloc(rar->lzss.window, new_size);
|
|
|
f485a7 |
if (new_window == NULL) {
|
|
|
f485a7 |
archive_set_error(&a->archive, ENOMEM,
|
|
|
f485a7 |
--
|
|
|
f485a7 |
2.17.1
|
|
|
f485a7 |
|