Skip to content

Commit

Permalink
rar: Avoid overwriting data at "end" of circular window buffer (libar…
Browse files Browse the repository at this point in the history
…chive#2124)

fix "File CRC Error" when extracting specific rar4 archives

Fixes libarchive#1794
  • Loading branch information
dunhor committed Apr 23, 2024
1 parent 91ba8ce commit ce5d6b6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libarchive/archive_read_support_format_rar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,19 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size,
{
start = rar->offset;
end = start + rar->dictionary_size;

/* We don't want to overflow the window and overwrite data that we write
* at 'start'. Therefore, reduce the end length by the maximum match size,
* which is 260 bytes. You can compute this maximum by looking at the
* definition of 'expand', in particular when 'symbol >= 271'. */
/* NOTE: It's possible for 'dictionary_size' to be less than this 260
* value, however that will only be the case when 'unp_size' is small,
* which should only happen when the entry size is small and there's no
* risk of overflowing the buffer */
if (rar->dictionary_size > 260) {
end -= 260;
}

if (rar->filters.filterstart < end) {
end = rar->filters.filterstart;
}
Expand Down

0 comments on commit ce5d6b6

Please sign in to comment.