From 227d33aef2b3fb3a2367e3511a36e90db7d2be78 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Wed, 6 Sep 2017 22:48:44 +0200 Subject: [PATCH] Place a limit on the mtree line length to make fuzzers happy. Reported-By: OSS-Fuzz issue 2936 --- libarchive/archive_read_support_format_mtree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 44b6083cb..5af0a1c66 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -77,6 +77,8 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011 #define MTREE_HASHTABLE_SIZE 1024 +#define MAX_LINE_LEN (1024 * 1024) + struct mtree_option { struct mtree_option *next; char *value; @@ -334,6 +336,14 @@ next_line(struct archive_read *a, size_t nbytes_req = (*ravail+1023) & ~1023U; ssize_t tested; + /* + * Place an arbitrary limit on the line length. + * mtree is almost free-form input and without line length limits, + * it can consume a lot of memory. + */ + if (len >= MAX_LINE_LEN) + return (-1); + /* Increase reading bytes if it is not enough to at least * new two lines. */ if (nbytes_req < (size_t)*ravail + 160) -- 2.47.2