You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.3 KiB

  1. From 021efa522ad729ff0f5806c4ce53e4a6cc1daa31 Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Tue, 20 Nov 2018 17:56:29 +1100
  4. Subject: [PATCH] Avoid a double-free when a window size of 0 is specified
  5. new_size can be 0 with a malicious or corrupted RAR archive.
  6. realloc(area, 0) is equivalent to free(area), so the region would
  7. be free()d here and the free()d again in the cleanup function.
  8. Found with a setup running AFL, afl-rb, and qsym.
  9. ---
  10. libarchive/archive_read_support_format_rar.c | 5 +++++
  11. 1 file changed, 5 insertions(+)
  12. diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c
  13. index 234522229..6f419c270 100644
  14. --- a/libarchive/archive_read_support_format_rar.c
  15. +++ b/libarchive/archive_read_support_format_rar.c
  16. @@ -2300,6 +2300,11 @@ parse_codes(struct archive_read *a)
  17. new_size = DICTIONARY_MAX_SIZE;
  18. else
  19. new_size = rar_fls((unsigned int)rar->unp_size) << 1;
  20. + if (new_size == 0) {
  21. + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
  22. + "Zero window size is invalid.");
  23. + return (ARCHIVE_FATAL);
  24. + }
  25. new_window = realloc(rar->lzss.window, new_size);
  26. if (new_window == NULL) {
  27. archive_set_error(&a->archive, ENOMEM,