Repository navigation
install: verify the gzip trailer of package tarballs #41503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f77419c
install: verify the gzip trailer of package tarballs
robobun 340f552
install: remove the temp extraction directory when the buffered extra…
robobun b62c8f3
install: check the gzip trailer after consuming it
robobun eccc24e
install: shorten the temp dir comments in extract
robobun 6173d95
test: cover a tar that ends on the gzip filter buffer boundary
robobun ea9e373
install: regenerate the gzip trailer patch for libarchive 3.8.9
robobun 085cbbc
install: remove the temp extraction directory when the move into the …
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
| --- a/libarchive/archive_read_support_filter_gzip.c | ||
| +++ b/libarchive/archive_read_support_filter_gzip.c | ||
| @@ -67,6 +67,11 @@ struct gzip { | ||
| * a gzip header). | ||
| */ | ||
| char trailer_pending; | ||
| + /* | ||
| + * BUN PATCH: uncompressed byte count of the current member, | ||
| + * modulo 2^32, checked against the ISIZE trailer field. | ||
| + */ | ||
| + uint32_t member_isize; | ||
| }; | ||
|
|
||
| /* Gzip Filter. */ | ||
| @@ -374,6 +379,7 @@ consume_header(struct archive_read_filter *f) | ||
|
|
||
| /* Initialize CRC accumulator. */ | ||
| gzip->crc = crc32(0L, NULL, 0); | ||
| + gzip->member_isize = 0; | ||
|
|
||
| /* | ||
| * BUN PATCH: Initialize compression library. next_in / avail_in | ||
| @@ -459,6 +465,18 @@ consume_trailer(struct archive_read_filter *f) | ||
|
|
||
| /* We've verified the trailer, so consume it now. */ | ||
| __archive_read_filter_consume(f->upstream, 8); | ||
| + /* | ||
| + * BUN PATCH: compare the trailer with what was inflated. Upstream | ||
| + * skips this, so a corrupted member decompressed without any | ||
| + * error. `p` is still readable: consume only moves the cursor. | ||
| + */ | ||
| + if (archive_le32dec(p) != (uint32_t)gzip->crc || | ||
| + archive_le32dec(p + 4) != gzip->member_isize) { | ||
| + archive_set_error(&f->archive->archive, | ||
| + ARCHIVE_ERRNO_MISC, | ||
| + "gzip trailer mismatch: bad CRC32 or uncompressed size"); | ||
| + return (ARCHIVE_FATAL); | ||
| + } | ||
| gzip->trailer_pending = 0; | ||
|
|
||
| return (ARCHIVE_OK); | ||
| @@ -470,6 +488,8 @@ gzip_filter_read(struct archive_read_filter *f, const void **p) | ||
| struct gzip *gzip = f->data; | ||
| size_t decompressed; | ||
| ssize_t avail_in, max_in; | ||
| + unsigned char *out_before; | ||
| + size_t produced; | ||
| int ret; | ||
|
|
||
| /* Empty our output buffer. */ | ||
| @@ -532,7 +552,11 @@ gzip_filter_read(struct archive_read_filter *f, const void **p) | ||
| gzip->stream.avail_in = (uInt)avail_in; | ||
|
|
||
| /* Decompress and consume some of that data. */ | ||
| + out_before = gzip->stream.next_out; | ||
| ret = inflate(&(gzip->stream), 0); | ||
| + produced = gzip->stream.next_out - out_before; | ||
| + gzip->crc = crc32(gzip->crc, out_before, (uInt)produced); | ||
| + gzip->member_isize += (uint32_t)produced; | ||
| switch (ret) { | ||
| case Z_OK: /* Decompressor made some progress. */ | ||
| __archive_read_filter_consume(f->upstream, | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.