]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
fix: OOB in rar delta filter (#2148)
authorWei-Cheng Pan <legnaleurc@gmail.com>
Sun, 28 Apr 2024 21:50:22 +0000 (06:50 +0900)
committerGitHub <noreply@github.com>
Sun, 28 Apr 2024 21:50:22 +0000 (23:50 +0200)
Ensure that `src` won't move ahead of `dst`, so `src` will not OOB.
Since `dst` won't move in this function, and we are only increasing `src`
position, this check should be enough. It should be safe to early return
because this function does not allocate resources.

libarchive/archive_read_support_format_rar.c

index 79669a8f40f9511d4e2a04e621d328136dace262..619ee81e2b5924b9d41d55bd353211b84ccbee08 100644 (file)
@@ -3612,7 +3612,15 @@ execute_filter_delta(struct rar_filter *filter, struct rar_virtual_machine *vm)
   {
     uint8_t lastbyte = 0;
     for (idx = i; idx < length; idx += numchannels)
+    {
+      /*
+       * The src block should not overlap with the dst block.
+       * If so it would be better to consider this archive is broken.
+       */
+      if (src >= dst)
+        return 0;
       lastbyte = dst[idx] = lastbyte - *src++;
+    }
   }
 
   filter->filteredblockaddress = length;