{
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;
}