eb2f1cc
From e1fdaa2f5c9b35fb0442c1b99bcac63f46a4e21b Mon Sep 17 00:00:00 2001
eb2f1cc
From: Ondrej Dubaj <odubaj@redhat.com>
eb2f1cc
Date: Mon, 18 Nov 2019 12:06:29 +0100
eb2f1cc
Subject: [PATCH] RAR reader: fix use after free
eb2f1cc
eb2f1cc
If read_data_compressed() returns ARCHIVE_FAILED, the caller is allowed
eb2f1cc
to continue with next archive headers. We need to set rar->start_new_table
eb2f1cc
after the ppmd7_context got freed, otherwise it won't be allocated again.
eb2f1cc
---
eb2f1cc
 libarchive/archive_read_support_format_rar.c | 4 +++-
eb2f1cc
 1 file changed, 3 insertions(+), 1 deletion(-)
eb2f1cc
eb2f1cc
diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c
eb2f1cc
index a8cc5c9..4936087 100644
eb2f1cc
--- a/libarchive/archive_read_support_format_rar.c
eb2f1cc
+++ b/libarchive/archive_read_support_format_rar.c
eb2f1cc
@@ -1024,8 +1024,10 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff,
eb2f1cc
   case COMPRESS_METHOD_GOOD:
eb2f1cc
   case COMPRESS_METHOD_BEST:
eb2f1cc
     ret = read_data_compressed(a, buff, size, offset);
eb2f1cc
-    if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN)
eb2f1cc
+    if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) {
eb2f1cc
       __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context);
eb2f1cc
+      rar->start_new_table = 1;
eb2f1cc
+    }
eb2f1cc
     break;
eb2f1cc
 
eb2f1cc
   default:
eb2f1cc
-- 
eb2f1cc
2.19.1
eb2f1cc