It is possible to trigger a call stack overflow by repeatedly entering
the rar_read_ahead function. In normal circumstances, this recursion is
optimized away by common compilers, but default settings with MSVC keep
the recursion in place. Explicitly turn the recursion into a goto-loop
to avoid the overflow even with no compiler optimizations.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
{
struct rar *rar = (struct rar *)(a->format->data);
- const void *h = __archive_read_ahead(a, min, avail);
+ const void *h;
int ret;
+
+again:
+ h = __archive_read_ahead(a, min, avail);
+
if (avail)
{
if (a->archive.read_data_is_posix_read && *avail > (ssize_t)a->archive.read_data_requested)
rar->filename_must_match = 0;
if (ret != (ARCHIVE_OK))
return NULL;
- return rar_read_ahead(a, min, avail);
+ goto again;
}
}
return h;