forked from libarchive/libarchive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanity-check gzip header field length
OSS-Fuzz managed to construct a small gzip input that decompresses into another gzip input with an extremely large filename field. This causes libarchive to hang processing the inner gzip. Address this by rejecting any gzip input where the filename or comment fields exceed 1MiB. Credit: OSS-Fuzz
- Loading branch information
Showing
5 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*- | ||
* Copyright (c) 2003-2024 Tim Kientzle | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
#include "test.h" | ||
|
||
DEFINE_TEST(test_read_filter_gzip_recursive) | ||
{ | ||
const char *name = "test_read_filter_gzip_recursive.gz"; | ||
struct archive *a; | ||
|
||
if (!canGzip()) { | ||
skipping("gzip not available"); | ||
return; | ||
} | ||
|
||
assert((a = archive_read_new()) != NULL); | ||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); | ||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); | ||
extract_reference_file(name); | ||
assertEqualIntA(a, ARCHIVE_FATAL, | ||
archive_read_open_filename(a, name, 200)); | ||
|
||
/* Verify that the filter detection worked. */ | ||
assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_GZIP); | ||
assertEqualString(archive_filter_name(a, 0), "gzip"); | ||
|
||
assertEqualInt(ARCHIVE_OK, archive_read_close(a)); | ||
assertEqualInt(ARCHIVE_OK, archive_read_free(a)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
From oss-fuzz: | ||
|
||
clusterfuzz-testcase-minimized-libarchive_fuzzer-5138261947580416 | ||
|
||
This is a gzip input that expands to a gzip, etc, in such a way that | ||
the "filename" field in the nested gzip header ends up being extremely | ||
large (> 500 MiB). This caused headaches for the gzip filter before I | ||
implemented a sanity limit on filename and comment sizes. | ||
|
||
begin 644 test_read_filter_gzip_recursive.gz | ||
M'XL(`5`M[_<\`'#_``#_'XL("0!D0`GK_W,)&P!P_P``_Q^+"`@(`%$`"0D< | ||
M`'#_``#_'XL($?\'_^_W/`!P_P``_Q^+"`D`9$`)Z_]S[AL`</\``/\?BP@( | ||
M"`!1``D)'`!P_P``_Q^+"!'_!___ZP$)=Q'_!___<PD;`'#_``#_'XL("`@` | ||
M40`)"1P`</\``/\?BP@1_P?_[_<\`'#_``#_'XL("0!D0`GK_SP`</\``/\? | ||
MBP@)`&1`">O_<^YC:&$!"7<1_P?__W,)&P!P_P``_Q^+"`@(`%$`"0D<`'#_ | ||
M``#_'XL($?\'_^_W/`!P_P``_Q^+"`D`9$`)Z_\\@</"P\/#P\/#P\/!P\/# | ||
7P\/#P\/#P\/EP\/#B`$`PT.?"`M=P\,` | ||
` | ||
end |