]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
warc: consume data once read 1105/head
authorDaniel Axtens <dja@axtens.net>
Tue, 4 Dec 2018 05:33:42 +0000 (16:33 +1100)
committerDaniel Axtens <dja@axtens.net>
Tue, 11 Dec 2018 02:58:11 +0000 (13:58 +1100)
The warc decoder only used read ahead, it wouldn't actually consume
data that had previously been printed. This means that if you specify
an invalid content length, it will just reprint the same data over
and over and over again until it hits the desired length.

This means that a WARC resource with e.g.
Content-Length: 666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665
but only a few hundred bytes of data, causes a quasi-infinite loop.

Consume data in subsequent calls to _warc_read.

Found with an AFL + afl-rb + qsym setup.

libarchive/archive_read_support_format_warc.c

index e8753853f3c8637eca42c8fdefa40ad91592b8e8..e8fc8428b41ed79bf969d776add480ad89081b1b 100644 (file)
@@ -386,6 +386,11 @@ _warc_read(struct archive_read *a, const void **buf, size_t *bsz, int64_t *off)
                return (ARCHIVE_EOF);
        }
 
+       if (w->unconsumed) {
+               __archive_read_consume(a, w->unconsumed);
+               w->unconsumed = 0U;
+       }
+
        rab = __archive_read_ahead(a, 1U, &nrd);
        if (nrd < 0) {
                *bsz = 0U;