filter: Use f as filter variable name
- If filter is meant, use "f" instead of "self" or "filter". - If bidder is meant, use "b" instead of "self". Matches writer filter style. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
This commit is contained in:
1 parent
12ba7fdf05
commit
88df4c92f7
14 files changed
+627
-628
No files matched your search
+136
-136
@@ -176,28 +176,28 @@ archive_read_open2(struct archive *a, void *client_data,
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
client_read_proxy(struct archive_read_filter *self, const void **buff)
|
||||
client_read_proxy(struct archive_read_filter *f, const void **buff)
|
||||
{
|
||||
ssize_t r;
|
||||
r = (self->archive->client.reader)(&self->archive->archive,
|
||||
self->data, buff);
|
||||
r = (f->archive->client.reader)(&f->archive->archive,
|
||||
f->data, buff);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static int64_t
|
||||
client_skip_proxy(struct archive_read_filter *self, int64_t request)
|
||||
client_skip_proxy(struct archive_read_filter *f, int64_t request)
|
||||
{
|
||||
if (request < 0)
|
||||
__archive_errx(1, "Negative skip requested");
|
||||
if (request == 0)
|
||||
return 0;
|
||||
|
||||
if (self->archive->client.skipper != NULL) {
|
||||
if (f->archive->client.skipper != NULL) {
|
||||
int64_t total = 0;
|
||||
for (;;) {
|
||||
int64_t get, ask = request;
|
||||
get = (self->archive->client.skipper)
|
||||
(&self->archive->archive, self->data, ask);
|
||||
get = (f->archive->client.skipper)
|
||||
(&f->archive->archive, f->data, ask);
|
||||
total += get;
|
||||
if (get == 0 || get == request)
|
||||
return (total);
|
||||
@@ -205,7 +205,7 @@ client_skip_proxy(struct archive_read_filter *self, int64_t request)
|
||||
return ARCHIVE_FATAL;
|
||||
request -= get;
|
||||
}
|
||||
} else if (self->archive->client.seeker != NULL
|
||||
} else if (f->archive->client.seeker != NULL
|
||||
&& request > 64 * 1024) {
|
||||
/* If the client provided a seeker but not a skipper,
|
||||
* we can use the seeker to skip forward.
|
||||
@@ -218,9 +218,9 @@ client_skip_proxy(struct archive_read_filter *self, int64_t request)
|
||||
* to just reading and discarding. That's why we
|
||||
* only do this for skips of over 64k.
|
||||
*/
|
||||
int64_t before = self->position;
|
||||
int64_t after = (self->archive->client.seeker)
|
||||
(&self->archive->archive, self->data, request, SEEK_CUR);
|
||||
int64_t before = f->position;
|
||||
int64_t after = (f->archive->client.seeker)
|
||||
(&f->archive->archive, f->data, request, SEEK_CUR);
|
||||
if (after != before + request)
|
||||
return ARCHIVE_FATAL;
|
||||
return after - before;
|
||||
@@ -229,20 +229,20 @@ client_skip_proxy(struct archive_read_filter *self, int64_t request)
|
||||
}
|
||||
|
||||
static int64_t
|
||||
client_seek_proxy(struct archive_read_filter *self, int64_t offset, int whence)
|
||||
client_seek_proxy(struct archive_read_filter *f, int64_t offset, int whence)
|
||||
{
|
||||
/* DO NOT use the skipper here! If we transparently handled
|
||||
* forward seek here by using the skipper, that will break
|
||||
* other libarchive code that assumes a successful forward
|
||||
* seek means it can also seek backwards.
|
||||
*/
|
||||
if (self->archive->client.seeker == NULL) {
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
if (f->archive->client.seeker == NULL) {
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Current client reader does not support seeking a device");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
return (self->archive->client.seeker)(&self->archive->archive,
|
||||
self->data, offset, whence);
|
||||
return (f->archive->client.seeker)(&f->archive->archive,
|
||||
f->data, offset, whence);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -264,21 +264,21 @@ read_client_close_proxy(struct archive_read *a)
|
||||
}
|
||||
|
||||
static int
|
||||
client_close_proxy(struct archive_read_filter *self)
|
||||
client_close_proxy(struct archive_read_filter *f)
|
||||
{
|
||||
return read_client_close_proxy(self->archive);
|
||||
return read_client_close_proxy(f->archive);
|
||||
}
|
||||
|
||||
static int
|
||||
client_switch_proxy(struct archive_read_filter *self, unsigned int iindex)
|
||||
client_switch_proxy(struct archive_read_filter *f, unsigned int iindex)
|
||||
{
|
||||
struct archive_read *a;
|
||||
int r1 = ARCHIVE_OK, r2 = ARCHIVE_OK;
|
||||
void *data2;
|
||||
|
||||
while (self->upstream != NULL)
|
||||
self = self->upstream;
|
||||
a = self->archive;
|
||||
while (f->upstream != NULL)
|
||||
f = f->upstream;
|
||||
a = f->archive;
|
||||
|
||||
/* Don't do anything if already in the specified data node */
|
||||
if (a->client.cursor == iindex)
|
||||
@@ -289,19 +289,19 @@ client_switch_proxy(struct archive_read_filter *self, unsigned int iindex)
|
||||
if (a->client.switcher != NULL)
|
||||
{
|
||||
r1 = r2 = (a->client.switcher)
|
||||
((struct archive *)a, self->data, data2);
|
||||
self->data = data2;
|
||||
((struct archive *)a, f->data, data2);
|
||||
f->data = data2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Attempt to call close and open instead */
|
||||
if (a->client.closer != NULL)
|
||||
r1 = (a->client.closer)
|
||||
((struct archive *)a, self->data);
|
||||
self->data = data2;
|
||||
((struct archive *)a, f->data);
|
||||
f->data = data2;
|
||||
if (a->client.opener != NULL)
|
||||
r2 = (a->client.opener)
|
||||
((struct archive *)a, self->data);
|
||||
((struct archive *)a, f->data);
|
||||
}
|
||||
return (r1 < r2) ? r1 : r2;
|
||||
}
|
||||
@@ -1384,13 +1384,13 @@ __archive_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
|
||||
}
|
||||
|
||||
const void *
|
||||
__archive_read_filter_ahead(struct archive_read_filter *filter,
|
||||
__archive_read_filter_ahead(struct archive_read_filter *f,
|
||||
size_t min, ssize_t *avail)
|
||||
{
|
||||
ssize_t bytes_read;
|
||||
size_t tocopy;
|
||||
|
||||
if (filter->fatal) {
|
||||
if (f->fatal) {
|
||||
if (avail)
|
||||
*avail = ARCHIVE_FATAL;
|
||||
return (NULL);
|
||||
@@ -1407,79 +1407,79 @@ __archive_read_filter_ahead(struct archive_read_filter *filter,
|
||||
* note that min == 0 is a perfectly well-defined
|
||||
* request.
|
||||
*/
|
||||
if (filter->avail >= min && filter->avail > 0) {
|
||||
if (f->avail >= min && f->avail > 0) {
|
||||
if (avail != NULL)
|
||||
*avail = filter->avail;
|
||||
return (filter->next);
|
||||
*avail = f->avail;
|
||||
return (f->next);
|
||||
}
|
||||
|
||||
/*
|
||||
* We can satisfy directly from client buffer if everything
|
||||
* currently in the copy buffer is still in the client buffer.
|
||||
*/
|
||||
if (filter->client_total >= filter->client_avail + filter->avail
|
||||
&& filter->client_avail + filter->avail >= min) {
|
||||
if (f->client_total >= f->client_avail + f->avail
|
||||
&& f->client_avail + f->avail >= min) {
|
||||
/* "Roll back" to client buffer. */
|
||||
filter->client_avail += filter->avail;
|
||||
filter->client_next -= filter->avail;
|
||||
f->client_avail += f->avail;
|
||||
f->client_next -= f->avail;
|
||||
/* Copy buffer is now empty. */
|
||||
filter->avail = 0;
|
||||
filter->next = filter->buffer;
|
||||
f->avail = 0;
|
||||
f->next = f->buffer;
|
||||
/* Return data from client buffer. */
|
||||
if (avail != NULL)
|
||||
*avail = filter->client_avail;
|
||||
return (filter->client_next);
|
||||
*avail = f->client_avail;
|
||||
return (f->client_next);
|
||||
}
|
||||
|
||||
/* Move data forward in copy buffer if necessary. */
|
||||
if (filter->next > filter->buffer &&
|
||||
min > filter->buffer_size - (filter->next - filter->buffer)) {
|
||||
if (filter->avail > 0)
|
||||
memmove(filter->buffer, filter->next,
|
||||
filter->avail);
|
||||
filter->next = filter->buffer;
|
||||
if (f->next > f->buffer &&
|
||||
min > f->buffer_size - (f->next - f->buffer)) {
|
||||
if (f->avail > 0)
|
||||
memmove(f->buffer, f->next,
|
||||
f->avail);
|
||||
f->next = f->buffer;
|
||||
}
|
||||
|
||||
/* If we've used up the client data, get more. */
|
||||
if (filter->client_avail <= 0) {
|
||||
if (filter->end_of_file) {
|
||||
if (f->client_avail <= 0) {
|
||||
if (f->end_of_file) {
|
||||
if (avail != NULL)
|
||||
*avail = filter->avail;
|
||||
*avail = f->avail;
|
||||
return (NULL);
|
||||
}
|
||||
bytes_read = (filter->vtable->read)(filter,
|
||||
&filter->client_buff);
|
||||
bytes_read = (f->vtable->read)(f,
|
||||
&f->client_buff);
|
||||
if (bytes_read < 0) { /* Read error. */
|
||||
filter->client_total = filter->client_avail = 0;
|
||||
filter->client_next =
|
||||
filter->client_buff = NULL;
|
||||
filter->fatal = 1;
|
||||
f->client_total = f->client_avail = 0;
|
||||
f->client_next =
|
||||
f->client_buff = NULL;
|
||||
f->fatal = 1;
|
||||
if (avail != NULL)
|
||||
*avail = ARCHIVE_FATAL;
|
||||
return (NULL);
|
||||
}
|
||||
if (bytes_read == 0) {
|
||||
/* Check for another client object first */
|
||||
if (filter->archive->client.cursor !=
|
||||
filter->archive->client.nodes - 1) {
|
||||
if (client_switch_proxy(filter,
|
||||
filter->archive->client.cursor + 1)
|
||||
if (f->archive->client.cursor !=
|
||||
f->archive->client.nodes - 1) {
|
||||
if (client_switch_proxy(f,
|
||||
f->archive->client.cursor + 1)
|
||||
== ARCHIVE_OK)
|
||||
continue;
|
||||
}
|
||||
/* Premature end-of-file. */
|
||||
filter->client_total = filter->client_avail = 0;
|
||||
filter->client_next =
|
||||
filter->client_buff = NULL;
|
||||
filter->end_of_file = 1;
|
||||
f->client_total = f->client_avail = 0;
|
||||
f->client_next =
|
||||
f->client_buff = NULL;
|
||||
f->end_of_file = 1;
|
||||
/* Return whatever we do have. */
|
||||
if (avail != NULL)
|
||||
*avail = filter->avail;
|
||||
*avail = f->avail;
|
||||
return (NULL);
|
||||
}
|
||||
filter->client_total = bytes_read;
|
||||
filter->client_avail = filter->client_total;
|
||||
filter->client_next = filter->client_buff;
|
||||
f->client_total = bytes_read;
|
||||
f->client_avail = f->client_total;
|
||||
f->client_next = f->client_buff;
|
||||
} else {
|
||||
/*
|
||||
* We can't satisfy the request from the copy
|
||||
@@ -1489,23 +1489,23 @@ __archive_read_filter_ahead(struct archive_read_filter *filter,
|
||||
*/
|
||||
|
||||
/* Ensure the buffer is big enough. */
|
||||
if (min > filter->buffer_size) {
|
||||
if (min > f->buffer_size) {
|
||||
size_t s;
|
||||
char *p;
|
||||
|
||||
/* Double the buffer; watch for overflow. */
|
||||
s = filter->buffer_size;
|
||||
s = f->buffer_size;
|
||||
if (s == 0)
|
||||
s = min;
|
||||
while (s < min) {
|
||||
if (archive_ckd_mul_size(&s, s, 2)) {
|
||||
/* Integer overflow! */
|
||||
archive_set_error(
|
||||
&filter->archive->archive,
|
||||
&f->archive->archive,
|
||||
ENOMEM,
|
||||
"Unable to allocate copy"
|
||||
" buffer");
|
||||
filter->fatal = 1;
|
||||
f->fatal = 1;
|
||||
if (avail != NULL)
|
||||
*avail = ARCHIVE_FATAL;
|
||||
return (NULL);
|
||||
@@ -1515,40 +1515,40 @@ __archive_read_filter_ahead(struct archive_read_filter *filter,
|
||||
p = malloc(s);
|
||||
if (p == NULL) {
|
||||
archive_set_error(
|
||||
&filter->archive->archive,
|
||||
&f->archive->archive,
|
||||
ENOMEM,
|
||||
"Unable to allocate copy buffer");
|
||||
filter->fatal = 1;
|
||||
f->fatal = 1;
|
||||
if (avail != NULL)
|
||||
*avail = ARCHIVE_FATAL;
|
||||
return (NULL);
|
||||
}
|
||||
/* Move data into newly-enlarged buffer. */
|
||||
if (filter->avail > 0)
|
||||
memmove(p, filter->next, filter->avail);
|
||||
free(filter->buffer);
|
||||
filter->next = filter->buffer = p;
|
||||
filter->buffer_size = s;
|
||||
if (f->avail > 0)
|
||||
memmove(p, f->next, f->avail);
|
||||
free(f->buffer);
|
||||
f->next = f->buffer = p;
|
||||
f->buffer_size = s;
|
||||
}
|
||||
|
||||
/* We can add client data to copy buffer. */
|
||||
/* First estimate: copy to fill rest of buffer. */
|
||||
tocopy = (filter->buffer + filter->buffer_size)
|
||||
- (filter->next + filter->avail);
|
||||
tocopy = (f->buffer + f->buffer_size)
|
||||
- (f->next + f->avail);
|
||||
/* Don't waste time buffering more than we need to. */
|
||||
if (tocopy + filter->avail > min)
|
||||
tocopy = min - filter->avail;
|
||||
if (tocopy + f->avail > min)
|
||||
tocopy = min - f->avail;
|
||||
/* Don't copy more than is available. */
|
||||
if (tocopy > filter->client_avail)
|
||||
tocopy = filter->client_avail;
|
||||
if (tocopy > f->client_avail)
|
||||
tocopy = f->client_avail;
|
||||
|
||||
memcpy(filter->next + filter->avail,
|
||||
filter->client_next, tocopy);
|
||||
memcpy(f->next + f->avail,
|
||||
f->client_next, tocopy);
|
||||
/* Remove this data from client buffer. */
|
||||
filter->client_next += tocopy;
|
||||
filter->client_avail -= tocopy;
|
||||
f->client_next += tocopy;
|
||||
f->client_avail -= tocopy;
|
||||
/* add it to copy buffer. */
|
||||
filter->avail += tocopy;
|
||||
f->avail += tocopy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1593,45 +1593,45 @@ __archive_read_filter_consume(struct archive_read_filter * filter,
|
||||
* Returns a negative value if there's an I/O error.
|
||||
*/
|
||||
static int64_t
|
||||
advance_file_pointer(struct archive_read_filter *filter, int64_t request)
|
||||
advance_file_pointer(struct archive_read_filter *f, int64_t request)
|
||||
{
|
||||
int64_t bytes_skipped, total_bytes_skipped = 0;
|
||||
ssize_t bytes_read;
|
||||
size_t min;
|
||||
|
||||
if (filter->fatal)
|
||||
if (f->fatal)
|
||||
return (-1);
|
||||
|
||||
/* Use up the copy buffer first. */
|
||||
if (filter->avail > 0) {
|
||||
min = (size_t)minimum(request, (int64_t)filter->avail);
|
||||
filter->next += min;
|
||||
filter->avail -= min;
|
||||
if (f->avail > 0) {
|
||||
min = (size_t)minimum(request, (int64_t)f->avail);
|
||||
f->next += min;
|
||||
f->avail -= min;
|
||||
request -= min;
|
||||
filter->position += min;
|
||||
f->position += min;
|
||||
total_bytes_skipped += min;
|
||||
}
|
||||
|
||||
/* Then use up the client buffer. */
|
||||
if (filter->client_avail > 0) {
|
||||
min = (size_t)minimum(request, (int64_t)filter->client_avail);
|
||||
filter->client_next += min;
|
||||
filter->client_avail -= min;
|
||||
if (f->client_avail > 0) {
|
||||
min = (size_t)minimum(request, (int64_t)f->client_avail);
|
||||
f->client_next += min;
|
||||
f->client_avail -= min;
|
||||
request -= min;
|
||||
filter->position += min;
|
||||
f->position += min;
|
||||
total_bytes_skipped += min;
|
||||
}
|
||||
if (request == 0)
|
||||
return (total_bytes_skipped);
|
||||
|
||||
/* If there's an optimized skip function, use it. */
|
||||
if (filter->can_skip != 0) {
|
||||
bytes_skipped = client_skip_proxy(filter, request);
|
||||
if (f->can_skip != 0) {
|
||||
bytes_skipped = client_skip_proxy(f, request);
|
||||
if (bytes_skipped < 0) { /* error */
|
||||
filter->fatal = 1;
|
||||
f->fatal = 1;
|
||||
return (bytes_skipped);
|
||||
}
|
||||
filter->position += bytes_skipped;
|
||||
f->position += bytes_skipped;
|
||||
total_bytes_skipped += bytes_skipped;
|
||||
request -= bytes_skipped;
|
||||
if (request == 0)
|
||||
@@ -1640,37 +1640,37 @@ advance_file_pointer(struct archive_read_filter *filter, int64_t request)
|
||||
|
||||
/* Use ordinary reads as necessary to complete the request. */
|
||||
for (;;) {
|
||||
bytes_read = (filter->vtable->read)(filter, &filter->client_buff);
|
||||
bytes_read = (f->vtable->read)(f, &f->client_buff);
|
||||
if (bytes_read < 0) {
|
||||
filter->client_buff = NULL;
|
||||
filter->fatal = 1;
|
||||
f->client_buff = NULL;
|
||||
f->fatal = 1;
|
||||
return (bytes_read);
|
||||
}
|
||||
|
||||
if (bytes_read == 0) {
|
||||
if (filter->archive->client.cursor !=
|
||||
filter->archive->client.nodes - 1) {
|
||||
if (client_switch_proxy(filter,
|
||||
filter->archive->client.cursor + 1)
|
||||
if (f->archive->client.cursor !=
|
||||
f->archive->client.nodes - 1) {
|
||||
if (client_switch_proxy(f,
|
||||
f->archive->client.cursor + 1)
|
||||
== ARCHIVE_OK)
|
||||
continue;
|
||||
}
|
||||
filter->client_buff = NULL;
|
||||
filter->end_of_file = 1;
|
||||
f->client_buff = NULL;
|
||||
f->end_of_file = 1;
|
||||
return (total_bytes_skipped);
|
||||
}
|
||||
|
||||
if (bytes_read >= request) {
|
||||
filter->client_next =
|
||||
((const char *)filter->client_buff) + request;
|
||||
filter->client_avail = (size_t)(bytes_read - request);
|
||||
filter->client_total = bytes_read;
|
||||
f->client_next =
|
||||
((const char *)f->client_buff) + request;
|
||||
f->client_avail = (size_t)(bytes_read - request);
|
||||
f->client_total = bytes_read;
|
||||
total_bytes_skipped += request;
|
||||
filter->position += request;
|
||||
f->position += request;
|
||||
return (total_bytes_skipped);
|
||||
}
|
||||
|
||||
filter->position += bytes_read;
|
||||
f->position += bytes_read;
|
||||
total_bytes_skipped += bytes_read;
|
||||
request -= bytes_read;
|
||||
}
|
||||
@@ -1686,23 +1686,23 @@ __archive_read_seek(struct archive_read *a, int64_t offset, int whence)
|
||||
}
|
||||
|
||||
int64_t
|
||||
__archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
|
||||
__archive_read_filter_seek(struct archive_read_filter *f, int64_t offset,
|
||||
int whence)
|
||||
{
|
||||
struct archive_read_client *client;
|
||||
int64_t r;
|
||||
unsigned int cursor;
|
||||
|
||||
if (filter->closed || filter->fatal)
|
||||
if (f->closed || f->fatal)
|
||||
return (ARCHIVE_FATAL);
|
||||
if (filter->can_seek == 0)
|
||||
if (f->can_seek == 0)
|
||||
return (ARCHIVE_FAILED);
|
||||
|
||||
client = &(filter->archive->client);
|
||||
client = &(f->archive->client);
|
||||
switch (whence) {
|
||||
case SEEK_CUR:
|
||||
/* Adjust the offset and use SEEK_SET instead */
|
||||
offset += filter->position;
|
||||
offset += f->position;
|
||||
__LA_FALLTHROUGH;
|
||||
case SEEK_SET:
|
||||
cursor = 0;
|
||||
@@ -1719,10 +1719,10 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
|
||||
client->dataset[++cursor].begin_position = r;
|
||||
}
|
||||
while (1) {
|
||||
r = client_switch_proxy(filter, cursor);
|
||||
r = client_switch_proxy(f, cursor);
|
||||
if (r != ARCHIVE_OK)
|
||||
return r;
|
||||
if ((r = client_seek_proxy(filter, 0, SEEK_END)) < 0)
|
||||
if ((r = client_seek_proxy(f, 0, SEEK_END)) < 0)
|
||||
return r;
|
||||
client->dataset[cursor].total_size = r;
|
||||
if (client->dataset[cursor].begin_position +
|
||||
@@ -1737,7 +1737,7 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
|
||||
if (offset < 0
|
||||
|| offset > client->dataset[cursor].total_size)
|
||||
return ARCHIVE_FATAL;
|
||||
if ((r = client_seek_proxy(filter, offset, SEEK_SET)) < 0)
|
||||
if ((r = client_seek_proxy(f, offset, SEEK_SET)) < 0)
|
||||
return r;
|
||||
break;
|
||||
|
||||
@@ -1753,10 +1753,10 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
|
||||
client->dataset[++cursor].begin_position = r;
|
||||
}
|
||||
while (1) {
|
||||
r = client_switch_proxy(filter, cursor);
|
||||
r = client_switch_proxy(f, cursor);
|
||||
if (r != ARCHIVE_OK)
|
||||
return r;
|
||||
if ((r = client_seek_proxy(filter, 0, SEEK_END)) < 0)
|
||||
if ((r = client_seek_proxy(f, 0, SEEK_END)) < 0)
|
||||
return r;
|
||||
client->dataset[cursor].total_size = r;
|
||||
r = client->dataset[cursor].begin_position +
|
||||
@@ -1777,9 +1777,9 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
|
||||
client->dataset[cursor].total_size;
|
||||
}
|
||||
offset = (r + offset) - client->dataset[cursor].begin_position;
|
||||
if ((r = client_switch_proxy(filter, cursor)) != ARCHIVE_OK)
|
||||
if ((r = client_switch_proxy(f, cursor)) != ARCHIVE_OK)
|
||||
return r;
|
||||
r = client_seek_proxy(filter, offset, SEEK_SET);
|
||||
r = client_seek_proxy(f, offset, SEEK_SET);
|
||||
if (r < ARCHIVE_OK)
|
||||
return r;
|
||||
break;
|
||||
@@ -1807,10 +1807,10 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
|
||||
* size is (r - offset). Can we use that to simplify
|
||||
* the TODO items above?
|
||||
*/
|
||||
filter->avail = filter->client_avail = 0;
|
||||
filter->next = filter->buffer;
|
||||
filter->position = r;
|
||||
filter->end_of_file = 0;
|
||||
f->avail = f->client_avail = 0;
|
||||
f->next = f->buffer;
|
||||
f->position = r;
|
||||
f->end_of_file = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@@ -76,10 +76,10 @@ struct archive_read_filter_bidder {
|
||||
struct archive_read_filter_vtable {
|
||||
/* Return next block. */
|
||||
ssize_t (*read)(struct archive_read_filter *, const void **);
|
||||
/* Close (just this filter) and free(self). */
|
||||
int (*close)(struct archive_read_filter *self);
|
||||
/* Close (just this filter) and free(filter). */
|
||||
int (*close)(struct archive_read_filter *);
|
||||
/* Read any header metadata if available. */
|
||||
int (*read_header)(struct archive_read_filter *self, struct archive_entry *entry);
|
||||
int (*read_header)(struct archive_read_filter *, struct archive_entry *);
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -112,15 +112,15 @@ archive_read_support_filter_bzip2(struct archive *_a)
|
||||
* from verifying as much as we would like.
|
||||
*/
|
||||
static int
|
||||
bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_filter *filter)
|
||||
bzip2_reader_bid(struct archive_read_filter_bidder *b, struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
int bits_checked;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
/* Minimal bzip2 archive is 14 bytes. */
|
||||
buffer = __archive_read_filter_ahead(filter, 14, NULL);
|
||||
buffer = __archive_read_filter_ahead(f, 14, NULL);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -156,16 +156,16 @@ bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_fi
|
||||
* in case that's available.
|
||||
*/
|
||||
static int
|
||||
bzip2_reader_init(struct archive_read_filter *self)
|
||||
bzip2_reader_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "bzip2 -d");
|
||||
r = __archive_read_program(f, "bzip2 -d");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_BZIP2;
|
||||
self->name = "bzip2";
|
||||
f->code = ARCHIVE_FILTER_BZIP2;
|
||||
f->name = "bzip2";
|
||||
return (r);
|
||||
}
|
||||
|
||||
@@ -182,29 +182,29 @@ bzip2_reader_vtable = {
|
||||
* Setup the callbacks.
|
||||
*/
|
||||
static int
|
||||
bzip2_reader_init(struct archive_read_filter *self)
|
||||
bzip2_reader_init(struct archive_read_filter *f)
|
||||
{
|
||||
static const size_t out_block_size = 64 * 1024;
|
||||
void *out_block;
|
||||
struct bzip2 *bzip2;
|
||||
|
||||
self->code = ARCHIVE_FILTER_BZIP2;
|
||||
self->name = "bzip2";
|
||||
f->code = ARCHIVE_FILTER_BZIP2;
|
||||
f->name = "bzip2";
|
||||
|
||||
bzip2 = calloc(1, sizeof(*bzip2));
|
||||
out_block = malloc(out_block_size);
|
||||
if (bzip2 == NULL || out_block == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for bzip2 decompression");
|
||||
free(out_block);
|
||||
free(bzip2);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = bzip2;
|
||||
f->data = bzip2;
|
||||
bzip2->out_block_size = out_block_size;
|
||||
bzip2->out_block = out_block;
|
||||
self->vtable = &bzip2_reader_vtable;
|
||||
f->vtable = &bzip2_reader_vtable;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
@@ -213,9 +213,9 @@ bzip2_reader_init(struct archive_read_filter *self)
|
||||
* Return the next block of decompressed data.
|
||||
*/
|
||||
static ssize_t
|
||||
bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
bzip2_filter_read(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct bzip2 *bzip2 = self->data;
|
||||
struct bzip2 *bzip2 = f->data;
|
||||
size_t decompressed;
|
||||
const char *read_buf;
|
||||
ssize_t ret;
|
||||
@@ -234,7 +234,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
ssize_t max_in;
|
||||
|
||||
if (!bzip2->valid) {
|
||||
if (bzip2_reader_bid(self->bidder, self->upstream) == 0) {
|
||||
if (bzip2_reader_bid(f->bidder, f->upstream) == 0) {
|
||||
bzip2->eof = 1;
|
||||
*p = bzip2->out_block;
|
||||
decompressed = bzip2->stream.next_out
|
||||
@@ -267,7 +267,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
detail = "mis-compiled library";
|
||||
break;
|
||||
}
|
||||
archive_set_error(&self->archive->archive, err,
|
||||
archive_set_error(&f->archive->archive, err,
|
||||
"Internal error initializing decompressor%s%s",
|
||||
detail == NULL ? "" : ": ",
|
||||
detail);
|
||||
@@ -279,9 +279,9 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
/* stream.next_in is really const, but bzlib
|
||||
* doesn't declare it so. <sigh> */
|
||||
read_buf =
|
||||
__archive_read_filter_ahead(self->upstream, 1, &ret);
|
||||
__archive_read_filter_ahead(f->upstream, 1, &ret);
|
||||
if (read_buf == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"truncated bzip2 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -297,7 +297,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
|
||||
/* Decompress as much as we can in one pass. */
|
||||
ret = BZ2_bzDecompress(&(bzip2->stream));
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
bzip2->stream.next_in - read_buf);
|
||||
|
||||
switch (ret) {
|
||||
@@ -306,7 +306,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
case BZ_OK:
|
||||
break;
|
||||
default:
|
||||
archive_set_error(&(self->archive->archive),
|
||||
archive_set_error(&(f->archive->archive),
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Failed to clean up decompressor");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -323,7 +323,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
}
|
||||
break;
|
||||
default: /* Return an error. */
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "bzip decompression failed");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -334,9 +334,9 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
||||
* Clean up the decompressor.
|
||||
*/
|
||||
static int
|
||||
bzip2_filter_close(struct archive_read_filter *self)
|
||||
bzip2_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct bzip2 *bzip2 = self->data;
|
||||
struct bzip2 *bzip2 = f->data;
|
||||
int ret = ARCHIVE_OK;
|
||||
|
||||
if (bzip2->valid) {
|
||||
@@ -344,7 +344,7 @@ bzip2_filter_close(struct archive_read_filter *self)
|
||||
case BZ_OK:
|
||||
break;
|
||||
default:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Failed to clean up decompressor");
|
||||
ret = ARCHIVE_FATAL;
|
||||
|
||||
@@ -169,16 +169,16 @@ archive_read_support_filter_compress(struct archive *_a)
|
||||
* This logic returns zero if any part of the signature fails.
|
||||
*/
|
||||
static int
|
||||
compress_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
compress_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
int bits_checked;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
/* Shortest valid compress file is 3 bytes. */
|
||||
buffer = __archive_read_filter_ahead(filter, 3, NULL);
|
||||
buffer = __archive_read_filter_ahead(f, 3, NULL);
|
||||
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -207,49 +207,49 @@ compress_reader_vtable = {
|
||||
* Setup the callbacks.
|
||||
*/
|
||||
static int
|
||||
compress_bidder_init(struct archive_read_filter *self)
|
||||
compress_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct compress *compress;
|
||||
static const size_t out_block_size = 64 * 1024;
|
||||
void *out_block;
|
||||
|
||||
self->code = ARCHIVE_FILTER_COMPRESS;
|
||||
self->name = "compress (.Z)";
|
||||
f->code = ARCHIVE_FILTER_COMPRESS;
|
||||
f->name = "compress (.Z)";
|
||||
|
||||
compress = calloc(1, sizeof(*compress));
|
||||
out_block = malloc(out_block_size);
|
||||
if (compress == NULL || out_block == NULL) {
|
||||
free(out_block);
|
||||
free(compress);
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for %s decompression",
|
||||
self->name);
|
||||
f->name);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = compress;
|
||||
f->data = compress;
|
||||
compress->out_block_size = out_block_size;
|
||||
compress->out_block = out_block;
|
||||
self->vtable = &compress_reader_vtable;
|
||||
f->vtable = &compress_reader_vtable;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
compress_filter_init(struct archive_read_filter *self)
|
||||
compress_filter_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct compress *compress = self->data;
|
||||
struct compress *compress = f->data;
|
||||
int code;
|
||||
|
||||
compress->initialized = 1;
|
||||
|
||||
(void)getbits(self, 8); /* Skip first signature byte. */
|
||||
(void)getbits(self, 8); /* Skip second signature byte. */
|
||||
(void)getbits(f, 8); /* Skip first signature byte. */
|
||||
(void)getbits(f, 8); /* Skip second signature byte. */
|
||||
|
||||
/* Get compression parameters. */
|
||||
code = getbits(self, 8);
|
||||
code = getbits(f, 8);
|
||||
if (code < 0 || (code & 0x1f) > 16) {
|
||||
archive_set_error(&self->archive->archive, -1,
|
||||
archive_set_error(&f->archive->archive, -1,
|
||||
"Invalid compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -269,7 +269,7 @@ compress_filter_init(struct archive_read_filter *self)
|
||||
compress->prefix[code] = 0;
|
||||
compress->suffix[code] = code;
|
||||
}
|
||||
next_code(self);
|
||||
next_code(f);
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
@@ -279,14 +279,14 @@ compress_filter_init(struct archive_read_filter *self)
|
||||
* as necessary.
|
||||
*/
|
||||
static ssize_t
|
||||
compress_filter_read(struct archive_read_filter *self, const void **pblock)
|
||||
compress_filter_read(struct archive_read_filter *f, const void **pblock)
|
||||
{
|
||||
struct compress *compress = self->data;
|
||||
struct compress *compress = f->data;
|
||||
unsigned char *p, *start, *end;
|
||||
int ret;
|
||||
|
||||
if (!compress->initialized) {
|
||||
ret = compress_filter_init(self);
|
||||
ret = compress_filter_init(f);
|
||||
if (ret != ARCHIVE_OK)
|
||||
return (ret);
|
||||
}
|
||||
@@ -301,7 +301,7 @@ compress_filter_read(struct archive_read_filter *self, const void **pblock)
|
||||
if (compress->stackp > compress->stack) {
|
||||
*p++ = *--compress->stackp;
|
||||
} else {
|
||||
ret = next_code(self);
|
||||
ret = next_code(f);
|
||||
if (ret == -1)
|
||||
compress->end_of_stream = ret;
|
||||
else if (ret != ARCHIVE_OK)
|
||||
@@ -317,9 +317,9 @@ compress_filter_read(struct archive_read_filter *self, const void **pblock)
|
||||
* Close and release the filter.
|
||||
*/
|
||||
static int
|
||||
compress_filter_close(struct archive_read_filter *self)
|
||||
compress_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct compress *compress = self->data;
|
||||
struct compress *compress = f->data;
|
||||
|
||||
free(compress->out_block);
|
||||
free(compress);
|
||||
@@ -332,13 +332,13 @@ compress_filter_close(struct archive_read_filter *self)
|
||||
* format error, ARCHIVE_EOF if we hit end of data, ARCHIVE_OK otherwise.
|
||||
*/
|
||||
static int
|
||||
next_code(struct archive_read_filter *self)
|
||||
next_code(struct archive_read_filter *f)
|
||||
{
|
||||
struct compress *compress = self->data;
|
||||
struct compress *compress = f->data;
|
||||
int code, newcode;
|
||||
|
||||
again:
|
||||
code = newcode = getbits(self, compress->bits);
|
||||
code = newcode = getbits(f, compress->bits);
|
||||
if (code < 0)
|
||||
return (code);
|
||||
|
||||
@@ -356,7 +356,7 @@ again:
|
||||
skip_bytes %= compress->bits;
|
||||
compress->bits_avail = 0; /* Discard rest of this byte. */
|
||||
while (skip_bytes-- > 0) {
|
||||
code = getbits(self, 8);
|
||||
code = getbits(f, 8);
|
||||
if (code < 0)
|
||||
return (code);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ again:
|
||||
if (code > compress->free_ent
|
||||
|| (code == compress->free_ent && compress->oldcode < 0)) {
|
||||
/* An invalid code is a fatal error. */
|
||||
archive_set_error(&(self->archive->archive), -1,
|
||||
archive_set_error(&(f->archive->archive), -1,
|
||||
"Invalid compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -417,9 +417,9 @@ again:
|
||||
* -1 indicates end of available data.
|
||||
*/
|
||||
static int
|
||||
getbits(struct archive_read_filter *self, int n)
|
||||
getbits(struct archive_read_filter *f, int n)
|
||||
{
|
||||
struct compress *compress = self->data;
|
||||
struct compress *compress = f->data;
|
||||
int code;
|
||||
ssize_t ret;
|
||||
static const int mask[] = {
|
||||
@@ -430,12 +430,12 @@ getbits(struct archive_read_filter *self, int n)
|
||||
while (compress->bits_avail < n) {
|
||||
if (compress->avail_in <= 0) {
|
||||
if (compress->consume_unnotified) {
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
compress->consume_unnotified);
|
||||
compress->consume_unnotified = 0;
|
||||
}
|
||||
compress->next_in
|
||||
= __archive_read_filter_ahead(self->upstream,
|
||||
= __archive_read_filter_ahead(f->upstream,
|
||||
1, &ret);
|
||||
if (ret == 0)
|
||||
return (-1);
|
||||
|
||||
@@ -76,14 +76,14 @@ archive_read_support_filter_grzip(struct archive *_a)
|
||||
* Bidder just verifies the header and returns the number of verified bits.
|
||||
*/
|
||||
static int
|
||||
grzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
grzip_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *p;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
p = __archive_read_filter_ahead(filter, sizeof(grzip_magic), NULL);
|
||||
p = __archive_read_filter_ahead(f, sizeof(grzip_magic), NULL);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -94,15 +94,15 @@ grzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
}
|
||||
|
||||
static int
|
||||
grzip_bidder_init(struct archive_read_filter *self)
|
||||
grzip_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "grzip -d");
|
||||
r = __archive_read_program(f, "grzip -d");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_GRZIP;
|
||||
self->name = "grzip";
|
||||
f->code = ARCHIVE_FILTER_GRZIP;
|
||||
f->name = "grzip";
|
||||
return (r);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ archive_read_support_filter_gzip(struct archive *_a)
|
||||
#define MAX_FILENAME_LENGTH (1024 * 1024L)
|
||||
#define MAX_COMMENT_LENGTH (1024 * 1024L)
|
||||
static ssize_t
|
||||
peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
peek_at_header(struct archive_read_filter *f, int *pbits,
|
||||
#ifdef HAVE_ZLIB_H
|
||||
struct gzip *gzip
|
||||
#else
|
||||
@@ -139,7 +139,7 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
/* Start by looking at the first ten bytes of the header, which
|
||||
* is all fixed layout. */
|
||||
len = 10;
|
||||
p = __archive_read_filter_ahead(filter, len, &avail);
|
||||
p = __archive_read_filter_ahead(f, len, &avail);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
/* We only support deflation- third byte must be 0x08. */
|
||||
@@ -162,7 +162,7 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
|
||||
/* Optional extra data: 2 byte length plus variable body. */
|
||||
if (header_flags & 4) {
|
||||
p = __archive_read_filter_ahead(filter, len + 2, &avail);
|
||||
p = __archive_read_filter_ahead(f, len + 2, &avail);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
len += archive_le16dec(p + len);
|
||||
@@ -180,7 +180,7 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
if (avail > MAX_FILENAME_LENGTH) {
|
||||
return (0);
|
||||
}
|
||||
p = __archive_read_filter_ahead(filter,
|
||||
p = __archive_read_filter_ahead(f,
|
||||
len, &avail);
|
||||
}
|
||||
if (p == NULL)
|
||||
@@ -204,7 +204,7 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
if (avail > MAX_COMMENT_LENGTH) {
|
||||
return (0);
|
||||
}
|
||||
p = __archive_read_filter_ahead(filter,
|
||||
p = __archive_read_filter_ahead(f,
|
||||
len, &avail);
|
||||
}
|
||||
if (p == NULL)
|
||||
@@ -214,7 +214,7 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
|
||||
/* Optional header CRC */
|
||||
if ((header_flags & 2)) {
|
||||
p = __archive_read_filter_ahead(filter, len + 2, &avail);
|
||||
p = __archive_read_filter_ahead(f, len + 2, &avail);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
#if 0
|
||||
@@ -236,14 +236,14 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
|
||||
* Bidder just verifies the header and returns the number of verified bits.
|
||||
*/
|
||||
static int
|
||||
gzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
gzip_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
int bits_checked;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
if (peek_at_header(filter, &bits_checked, NULL))
|
||||
if (peek_at_header(f, &bits_checked, NULL))
|
||||
return (bits_checked);
|
||||
return (0);
|
||||
}
|
||||
@@ -256,25 +256,25 @@ gzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
* in case that's available.
|
||||
*/
|
||||
static int
|
||||
gzip_bidder_init(struct archive_read_filter *self)
|
||||
gzip_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "gzip -d");
|
||||
r = __archive_read_program(f, "gzip -d");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_GZIP;
|
||||
self->name = "gzip";
|
||||
f->code = ARCHIVE_FILTER_GZIP;
|
||||
f->name = "gzip";
|
||||
return (r);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int
|
||||
gzip_read_header(struct archive_read_filter *self, struct archive_entry *entry)
|
||||
gzip_read_header(struct archive_read_filter *f, struct archive_entry *entry)
|
||||
{
|
||||
struct gzip *gzip = self->data;
|
||||
struct gzip *gzip = f->data;
|
||||
|
||||
/* An mtime of 0 is considered invalid/missing. */
|
||||
if (gzip->mtime != 0)
|
||||
@@ -300,29 +300,29 @@ gzip_reader_vtable = {
|
||||
* Initialize the filter object.
|
||||
*/
|
||||
static int
|
||||
gzip_bidder_init(struct archive_read_filter *self)
|
||||
gzip_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct gzip *gzip;
|
||||
static const size_t out_block_size = 64 * 1024;
|
||||
void *out_block;
|
||||
|
||||
self->code = ARCHIVE_FILTER_GZIP;
|
||||
self->name = "gzip";
|
||||
f->code = ARCHIVE_FILTER_GZIP;
|
||||
f->name = "gzip";
|
||||
|
||||
gzip = calloc(1, sizeof(*gzip));
|
||||
out_block = malloc(out_block_size);
|
||||
if (gzip == NULL || out_block == NULL) {
|
||||
free(out_block);
|
||||
free(gzip);
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for gzip decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = gzip;
|
||||
f->data = gzip;
|
||||
gzip->out_block_size = out_block_size;
|
||||
gzip->out_block = out_block;
|
||||
self->vtable = &gzip_reader_vtable;
|
||||
f->vtable = &gzip_reader_vtable;
|
||||
|
||||
gzip->in_stream = 0; /* We're not actually within a stream yet. */
|
||||
|
||||
@@ -330,27 +330,27 @@ gzip_bidder_init(struct archive_read_filter *self)
|
||||
}
|
||||
|
||||
static int
|
||||
consume_header(struct archive_read_filter *self)
|
||||
consume_header(struct archive_read_filter *f)
|
||||
{
|
||||
struct gzip *gzip = self->data;
|
||||
struct gzip *gzip = f->data;
|
||||
ssize_t avail, max_in;
|
||||
size_t len;
|
||||
int ret;
|
||||
|
||||
/* If this is a real header, consume it. */
|
||||
len = peek_at_header(self->upstream, NULL, gzip);
|
||||
len = peek_at_header(f->upstream, NULL, gzip);
|
||||
if (len == 0)
|
||||
return (ARCHIVE_EOF);
|
||||
__archive_read_filter_consume(self->upstream, len);
|
||||
__archive_read_filter_consume(f->upstream, len);
|
||||
|
||||
/* Initialize CRC accumulator. */
|
||||
gzip->crc = crc32(0L, NULL, 0);
|
||||
|
||||
/* Initialize compression library. */
|
||||
gzip->stream.next_in = (unsigned char *)(uintptr_t)
|
||||
__archive_read_filter_ahead(self->upstream, 1, &avail);
|
||||
__archive_read_filter_ahead(f->upstream, 1, &avail);
|
||||
if (avail < 0) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Failed to read gzip input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -371,24 +371,24 @@ consume_header(struct archive_read_filter *self)
|
||||
gzip->in_stream = 1;
|
||||
return (ARCHIVE_OK);
|
||||
case Z_STREAM_ERROR:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Internal error initializing compression library: "
|
||||
"invalid setup parameter");
|
||||
break;
|
||||
case Z_MEM_ERROR:
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Internal error initializing compression library: "
|
||||
"out of memory");
|
||||
break;
|
||||
case Z_VERSION_ERROR:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Internal error initializing compression library: "
|
||||
"invalid library version");
|
||||
break;
|
||||
default:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Internal error initializing compression library: "
|
||||
" Zlib error %d", ret);
|
||||
@@ -398,9 +398,9 @@ consume_header(struct archive_read_filter *self)
|
||||
}
|
||||
|
||||
static int
|
||||
consume_trailer(struct archive_read_filter *self)
|
||||
consume_trailer(struct archive_read_filter *f)
|
||||
{
|
||||
struct gzip *gzip = self->data;
|
||||
struct gzip *gzip = f->data;
|
||||
const unsigned char *p;
|
||||
|
||||
gzip->in_stream = 0;
|
||||
@@ -408,29 +408,29 @@ consume_trailer(struct archive_read_filter *self)
|
||||
case Z_OK:
|
||||
break;
|
||||
default:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Failed to clean up gzip decompressor");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
/* GZip trailer is a fixed 8 byte structure. */
|
||||
p = __archive_read_filter_ahead(self->upstream, 8, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 8, NULL);
|
||||
if (p == NULL)
|
||||
return (ARCHIVE_FATAL);
|
||||
|
||||
/* XXX TODO: Verify the length and CRC. */
|
||||
|
||||
/* We've verified the trailer, so consume it now. */
|
||||
__archive_read_filter_consume(self->upstream, 8);
|
||||
__archive_read_filter_consume(f->upstream, 8);
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
gzip_filter_read(struct archive_read_filter *self, const void **p)
|
||||
gzip_filter_read(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct gzip *gzip = self->data;
|
||||
struct gzip *gzip = f->data;
|
||||
size_t decompressed;
|
||||
ssize_t avail_in, max_in;
|
||||
int ret;
|
||||
@@ -444,7 +444,7 @@ gzip_filter_read(struct archive_read_filter *self, const void **p)
|
||||
/* If we're not in a stream, read a header
|
||||
* and initialize the decompression library. */
|
||||
if (!gzip->in_stream) {
|
||||
ret = consume_header(self);
|
||||
ret = consume_header(f);
|
||||
if (ret == ARCHIVE_EOF) {
|
||||
gzip->eof = 1;
|
||||
break;
|
||||
@@ -457,9 +457,9 @@ gzip_filter_read(struct archive_read_filter *self, const void **p)
|
||||
/* ZLib treats stream.next_in as const but doesn't declare
|
||||
* it so, hence this ugly cast. */
|
||||
gzip->stream.next_in = (unsigned char *)(uintptr_t)
|
||||
__archive_read_filter_ahead(self->upstream, 1, &avail_in);
|
||||
__archive_read_filter_ahead(f->upstream, 1, &avail_in);
|
||||
if (gzip->stream.next_in == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"truncated gzip input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -476,21 +476,21 @@ gzip_filter_read(struct archive_read_filter *self, const void **p)
|
||||
ret = inflate(&(gzip->stream), 0);
|
||||
switch (ret) {
|
||||
case Z_OK: /* Decompressor made some progress. */
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
avail_in - gzip->stream.avail_in);
|
||||
break;
|
||||
case Z_STREAM_END: /* Found end of stream. */
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
avail_in - gzip->stream.avail_in);
|
||||
/* Consume the stream trailer; release the
|
||||
* decompression library. */
|
||||
ret = consume_trailer(self);
|
||||
ret = consume_trailer(f);
|
||||
if (ret < ARCHIVE_OK)
|
||||
return (ret);
|
||||
break;
|
||||
default:
|
||||
/* Return an error. */
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"gzip decompression failed");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -510,9 +510,9 @@ gzip_filter_read(struct archive_read_filter *self, const void **p)
|
||||
* Clean up the decompressor.
|
||||
*/
|
||||
static int
|
||||
gzip_filter_close(struct archive_read_filter *self)
|
||||
gzip_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct gzip *gzip = self->data;
|
||||
struct gzip *gzip = f->data;
|
||||
int ret;
|
||||
|
||||
ret = ARCHIVE_OK;
|
||||
@@ -522,7 +522,7 @@ gzip_filter_close(struct archive_read_filter *self)
|
||||
case Z_OK:
|
||||
break;
|
||||
default:
|
||||
archive_set_error(&(self->archive->archive),
|
||||
archive_set_error(&(f->archive->archive),
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Failed to clean up gzip compressor");
|
||||
ret = ARCHIVE_FATAL;
|
||||
|
||||
@@ -75,18 +75,18 @@ archive_read_support_filter_lrzip(struct archive *_a)
|
||||
* Bidder just verifies the header and returns the number of verified bits.
|
||||
*/
|
||||
static int
|
||||
lrzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
lrzip_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *p;
|
||||
ssize_t len;
|
||||
int i;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
/* Start by looking at the first six bytes of the header, which
|
||||
* is all fixed layout. */
|
||||
len = 6;
|
||||
p = __archive_read_filter_ahead(filter, len, NULL);
|
||||
p = __archive_read_filter_ahead(f, len, NULL);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -105,15 +105,15 @@ lrzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
}
|
||||
|
||||
static int
|
||||
lrzip_bidder_init(struct archive_read_filter *self)
|
||||
lrzip_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "lrzip -d -q");
|
||||
r = __archive_read_program(f, "lrzip -d -q");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_LRZIP;
|
||||
self->name = "lrzip";
|
||||
f->code = ARCHIVE_FILTER_LRZIP;
|
||||
f->name = "lrzip";
|
||||
return (r);
|
||||
}
|
||||
@@ -139,8 +139,8 @@ archive_read_support_filter_lz4(struct archive *_a)
|
||||
* from verifying as much as we would like.
|
||||
*/
|
||||
static int
|
||||
lz4_reader_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
lz4_reader_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
ssize_t avail;
|
||||
@@ -159,7 +159,7 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
|
||||
const size_t max_lookahead = 64 * 1024;
|
||||
uint32_t magic_number;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
/*
|
||||
* Zstd and LZ4 skippable frame magic numbers are identical. To
|
||||
@@ -168,7 +168,7 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
|
||||
*/
|
||||
|
||||
/* Minimal lz4 archive is 11 bytes. */
|
||||
buffer = __archive_read_filter_ahead(filter, min_lz4_archive_size,
|
||||
buffer = __archive_read_filter_ahead(f, min_lz4_archive_size,
|
||||
&avail);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -184,7 +184,7 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
|
||||
|
||||
/* Ensure that we can read another 4 bytes. */
|
||||
if (offset_in_buffer + 4 > (size_t)avail) {
|
||||
buffer = __archive_read_filter_ahead(filter,
|
||||
buffer = __archive_read_filter_ahead(f,
|
||||
offset_in_buffer + 4, &avail);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -212,7 +212,7 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
|
||||
if (min > max_lookahead)
|
||||
return (0);
|
||||
|
||||
buffer = __archive_read_filter_ahead(filter,
|
||||
buffer = __archive_read_filter_ahead(f,
|
||||
min, &avail);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -271,16 +271,16 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
|
||||
* in case that's available.
|
||||
*/
|
||||
static int
|
||||
lz4_reader_init(struct archive_read_filter *self)
|
||||
lz4_reader_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "lz4 -d -q");
|
||||
r = __archive_read_program(f, "lz4 -d -q");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_LZ4;
|
||||
self->name = "lz4";
|
||||
f->code = ARCHIVE_FILTER_LZ4;
|
||||
f->name = "lz4";
|
||||
return (r);
|
||||
}
|
||||
|
||||
@@ -297,31 +297,31 @@ lz4_reader_vtable = {
|
||||
* Setup the callbacks.
|
||||
*/
|
||||
static int
|
||||
lz4_reader_init(struct archive_read_filter *self)
|
||||
lz4_reader_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct lz4 *lz4;
|
||||
|
||||
self->code = ARCHIVE_FILTER_LZ4;
|
||||
self->name = "lz4";
|
||||
f->code = ARCHIVE_FILTER_LZ4;
|
||||
f->name = "lz4";
|
||||
|
||||
lz4 = calloc(1, sizeof(*lz4));
|
||||
if (lz4 == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for lz4 decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = lz4;
|
||||
f->data = lz4;
|
||||
lz4->stage = SELECT_STREAM;
|
||||
self->vtable = &lz4_reader_vtable;
|
||||
f->vtable = &lz4_reader_vtable;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
lz4_allocate_out_block(struct archive_read_filter *self)
|
||||
lz4_allocate_out_block(struct archive_read_filter *f)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
size_t out_block_size = lz4->flags.block_maximum_size;
|
||||
void *out_block;
|
||||
|
||||
@@ -333,7 +333,7 @@ lz4_allocate_out_block(struct archive_read_filter *self)
|
||||
out_block = malloc(out_block_size);
|
||||
if (out_block == NULL) {
|
||||
lz4->out_block_size = 0;
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for lz4 decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -346,9 +346,9 @@ lz4_allocate_out_block(struct archive_read_filter *self)
|
||||
}
|
||||
|
||||
static int
|
||||
lz4_allocate_out_block_for_legacy(struct archive_read_filter *self)
|
||||
lz4_allocate_out_block_for_legacy(struct archive_read_filter *f)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
size_t out_block_size = LEGACY_BLOCK_SIZE;
|
||||
void *out_block;
|
||||
|
||||
@@ -358,7 +358,7 @@ lz4_allocate_out_block_for_legacy(struct archive_read_filter *self)
|
||||
out_block = malloc(out_block_size);
|
||||
if (out_block == NULL) {
|
||||
lz4->out_block_size = 0;
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for lz4 decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -372,9 +372,9 @@ lz4_allocate_out_block_for_legacy(struct archive_read_filter *self)
|
||||
* Return the next block of decompressed data.
|
||||
*/
|
||||
static ssize_t
|
||||
lz4_filter_read(struct archive_read_filter *self, const void **p)
|
||||
lz4_filter_read(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
ssize_t ret;
|
||||
|
||||
if (lz4->eof) {
|
||||
@@ -382,7 +382,7 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
|
||||
return (0);
|
||||
}
|
||||
|
||||
__archive_read_filter_consume(self->upstream, lz4->unconsumed);
|
||||
__archive_read_filter_consume(f->upstream, lz4->unconsumed);
|
||||
lz4->unconsumed = 0;
|
||||
|
||||
switch (lz4->stage) {
|
||||
@@ -391,21 +391,21 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
|
||||
case READ_DEFAULT_STREAM:
|
||||
case READ_LEGACY_STREAM:
|
||||
/* Reading an lz4 stream already failed. */
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Invalid sequence");
|
||||
return (ARCHIVE_FATAL);
|
||||
case READ_DEFAULT_BLOCK:
|
||||
ret = lz4_filter_read_default_stream(self, p);
|
||||
ret = lz4_filter_read_default_stream(f, p);
|
||||
if (ret != 0 || lz4->stage != SELECT_STREAM)
|
||||
return ret;
|
||||
break;
|
||||
case READ_LEGACY_BLOCK:
|
||||
ret = lz4_filter_read_legacy_stream(self, p);
|
||||
ret = lz4_filter_read_legacy_stream(f, p);
|
||||
if (ret != 0 || lz4->stage != SELECT_STREAM)
|
||||
return ret;
|
||||
break;
|
||||
default:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Program error");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -414,7 +414,7 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
|
||||
const char *read_buf;
|
||||
|
||||
/* Read a magic number. */
|
||||
read_buf = __archive_read_filter_ahead(self->upstream, 4,
|
||||
read_buf = __archive_read_filter_ahead(f->upstream, 4,
|
||||
NULL);
|
||||
if (read_buf == NULL) {
|
||||
lz4->eof = 1;
|
||||
@@ -422,26 +422,26 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
|
||||
return (0);
|
||||
}
|
||||
uint32_t number = archive_le32dec(read_buf);
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
if (number == LZ4_MAGICNUMBER)
|
||||
return lz4_filter_read_default_stream(self, p);
|
||||
return lz4_filter_read_default_stream(f, p);
|
||||
else if (number == LZ4_LEGACY)
|
||||
return lz4_filter_read_legacy_stream(self, p);
|
||||
return lz4_filter_read_legacy_stream(f, p);
|
||||
else if ((number & LZ4_SKIPPABLE_MASK) == LZ4_SKIPPABLE_START) {
|
||||
read_buf = __archive_read_filter_ahead(
|
||||
self->upstream, 4, NULL);
|
||||
f->upstream, 4, NULL);
|
||||
if (read_buf == NULL) {
|
||||
archive_set_error(
|
||||
&self->archive->archive,
|
||||
&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Malformed lz4 data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
int64_t skip_bytes = archive_le32dec(read_buf);
|
||||
if (__archive_read_filter_consume(self->upstream,
|
||||
if (__archive_read_filter_consume(f->upstream,
|
||||
4 + skip_bytes) < 0) {
|
||||
archive_set_error(
|
||||
&self->archive->archive,
|
||||
&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Malformed lz4 data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -459,9 +459,9 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
|
||||
}
|
||||
|
||||
static int
|
||||
lz4_filter_read_descriptor(struct archive_read_filter *self)
|
||||
lz4_filter_read_descriptor(struct archive_read_filter *f)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
const char *read_buf;
|
||||
ssize_t bytes_remaining;
|
||||
ssize_t descriptor_bytes;
|
||||
@@ -469,10 +469,10 @@ lz4_filter_read_descriptor(struct archive_read_filter *self)
|
||||
unsigned int chsum, chsum_verifier;
|
||||
|
||||
/* Make sure we have 2 bytes for flags. */
|
||||
read_buf = __archive_read_filter_ahead(self->upstream, 2,
|
||||
read_buf = __archive_read_filter_ahead(f->upstream, 2,
|
||||
&bytes_remaining);
|
||||
if (read_buf == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"truncated lz4 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -524,10 +524,10 @@ lz4_filter_read_descriptor(struct archive_read_filter *self)
|
||||
if (lz4->flags.preset_dictionary)
|
||||
descriptor_bytes += 4;
|
||||
if (bytes_remaining < descriptor_bytes) {
|
||||
read_buf = __archive_read_filter_ahead(self->upstream,
|
||||
read_buf = __archive_read_filter_ahead(f->upstream,
|
||||
descriptor_bytes, &bytes_remaining);
|
||||
if (read_buf == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"truncated lz4 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -542,10 +542,10 @@ lz4_filter_read_descriptor(struct archive_read_filter *self)
|
||||
goto malformed_error;
|
||||
#endif
|
||||
|
||||
__archive_read_filter_consume(self->upstream, descriptor_bytes);
|
||||
__archive_read_filter_consume(f->upstream, descriptor_bytes);
|
||||
|
||||
/* Make sure we have a large enough buffer for uncompressed data. */
|
||||
if (lz4_allocate_out_block(self) != ARCHIVE_OK)
|
||||
if (lz4_allocate_out_block(f) != ARCHIVE_OK)
|
||||
return (ARCHIVE_FATAL);
|
||||
if (lz4->flags.stream_checksum) {
|
||||
lz4->xxh32_state = __archive_xxhash.XXH32_init(0);
|
||||
@@ -557,15 +557,15 @@ lz4_filter_read_descriptor(struct archive_read_filter *self)
|
||||
/* Success */
|
||||
return (ARCHIVE_OK);
|
||||
malformed_error:
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"malformed lz4 data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
|
||||
lz4_filter_read_data_block(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
ssize_t compressed_size;
|
||||
const char *read_buf;
|
||||
int checksum_size;
|
||||
@@ -575,7 +575,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
|
||||
*p = NULL;
|
||||
|
||||
/* Make sure we have 4 bytes for a block size. */
|
||||
read_buf = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
read_buf = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (read_buf == NULL)
|
||||
goto truncated_error;
|
||||
compressed_size = archive_le32dec(read_buf);
|
||||
@@ -583,7 +583,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
|
||||
goto malformed_error;
|
||||
/* A compressed size == 0 means the end of stream blocks. */
|
||||
if (compressed_size == 0) {
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
|
||||
for its decompression speed, so we read a whole block and allocate
|
||||
a huge buffer used for decoded data.
|
||||
*/
|
||||
read_buf = __archive_read_filter_ahead(self->upstream,
|
||||
read_buf = __archive_read_filter_ahead(f->upstream,
|
||||
4 + compressed_size + checksum_size, NULL);
|
||||
if (read_buf == NULL)
|
||||
goto truncated_error;
|
||||
@@ -684,7 +684,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
|
||||
|
||||
/* Check if an error occurred in the decompression process. */
|
||||
if (uncompressed_size < 0) {
|
||||
archive_set_error(&(self->archive->archive),
|
||||
archive_set_error(&(f->archive->archive),
|
||||
ARCHIVE_ERRNO_MISC, "lz4 decompression failed");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -695,31 +695,31 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
|
||||
return uncompressed_size;
|
||||
|
||||
malformed_error:
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"malformed lz4 data");
|
||||
return (ARCHIVE_FATAL);
|
||||
truncated_error:
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"truncated lz4 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
lz4_filter_read_default_stream(struct archive_read_filter *self, const void **p)
|
||||
lz4_filter_read_default_stream(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
const char *read_buf;
|
||||
ssize_t ret;
|
||||
|
||||
if (lz4->stage == SELECT_STREAM) {
|
||||
lz4->stage = READ_DEFAULT_STREAM;
|
||||
/* First, read a descriptor. */
|
||||
if((ret = lz4_filter_read_descriptor(self)) != ARCHIVE_OK)
|
||||
if((ret = lz4_filter_read_descriptor(f)) != ARCHIVE_OK)
|
||||
return (ret);
|
||||
lz4->stage = READ_DEFAULT_BLOCK;
|
||||
}
|
||||
/* Decompress a block. */
|
||||
ret = lz4_filter_read_data_block(self, p);
|
||||
ret = lz4_filter_read_data_block(f, p);
|
||||
|
||||
/* If the end of block is detected, change the filter status
|
||||
to read next stream. */
|
||||
@@ -731,21 +731,21 @@ lz4_filter_read_default_stream(struct archive_read_filter *self, const void **p)
|
||||
if (lz4->stage == SELECT_STREAM) {
|
||||
unsigned int checksum;
|
||||
unsigned int checksum_stream;
|
||||
read_buf = __archive_read_filter_ahead(self->upstream,
|
||||
read_buf = __archive_read_filter_ahead(f->upstream,
|
||||
4, NULL);
|
||||
if (read_buf == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "truncated lz4 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
checksum = archive_le32dec(read_buf);
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
checksum_stream = __archive_xxhash.XXH32_digest(
|
||||
lz4->xxh32_state);
|
||||
lz4->xxh32_state = NULL;
|
||||
if (checksum != checksum_stream) {
|
||||
#ifndef DONT_FAIL_ON_CRC_ERROR
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"lz4 stream checksum error");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -759,24 +759,24 @@ lz4_filter_read_default_stream(struct archive_read_filter *self, const void **p)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
lz4_filter_read_legacy_stream(struct archive_read_filter *self, const void **p)
|
||||
lz4_filter_read_legacy_stream(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
uint32_t compressed;
|
||||
const char *read_buf;
|
||||
ssize_t ret;
|
||||
|
||||
*p = NULL;
|
||||
ret = lz4_allocate_out_block_for_legacy(self);
|
||||
ret = lz4_allocate_out_block_for_legacy(f);
|
||||
if (ret != ARCHIVE_OK)
|
||||
return ret;
|
||||
|
||||
/* Make sure we have 4 bytes for a block size. */
|
||||
read_buf = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
read_buf = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (read_buf == NULL) {
|
||||
if (lz4->stage == SELECT_STREAM) {
|
||||
lz4->stage = READ_LEGACY_STREAM;
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"truncated lz4 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -792,17 +792,17 @@ lz4_filter_read_legacy_stream(struct archive_read_filter *self, const void **p)
|
||||
}
|
||||
|
||||
/* Make sure we have a whole block. */
|
||||
read_buf = __archive_read_filter_ahead(self->upstream,
|
||||
read_buf = __archive_read_filter_ahead(f->upstream,
|
||||
4 + compressed, NULL);
|
||||
if (read_buf == NULL) {
|
||||
archive_set_error(&(self->archive->archive),
|
||||
archive_set_error(&(f->archive->archive),
|
||||
ARCHIVE_ERRNO_MISC, "truncated lz4 input");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
ret = LZ4_decompress_safe(read_buf + 4, lz4->out_block,
|
||||
compressed, (int)lz4->out_block_size);
|
||||
if (ret < 0) {
|
||||
archive_set_error(&(self->archive->archive),
|
||||
archive_set_error(&(f->archive->archive),
|
||||
ARCHIVE_ERRNO_MISC, "lz4 decompression failed");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -815,9 +815,9 @@ lz4_filter_read_legacy_stream(struct archive_read_filter *self, const void **p)
|
||||
* Clean up the decompressor.
|
||||
*/
|
||||
static int
|
||||
lz4_filter_close(struct archive_read_filter *self)
|
||||
lz4_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct lz4 *lz4 = self->data;
|
||||
struct lz4 *lz4 = f->data;
|
||||
int ret = ARCHIVE_OK;
|
||||
|
||||
free(lz4->xxh32_state);
|
||||
|
||||
@@ -127,14 +127,14 @@ archive_read_support_filter_lzop(struct archive *_a)
|
||||
* Bidder just verifies the header and returns the number of verified bits.
|
||||
*/
|
||||
static int
|
||||
lzop_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
lzop_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *p;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
p = __archive_read_filter_ahead(filter, LZOP_HEADER_MAGIC_LEN, NULL);
|
||||
p = __archive_read_filter_ahead(f, LZOP_HEADER_MAGIC_LEN, NULL);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -151,16 +151,16 @@ lzop_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
* in case that's available.
|
||||
*/
|
||||
static int
|
||||
lzop_bidder_init(struct archive_read_filter *self)
|
||||
lzop_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "lzop -d");
|
||||
r = __archive_read_program(f, "lzop -d");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_LZOP;
|
||||
self->name = "lzop";
|
||||
f->code = ARCHIVE_FILTER_LZOP;
|
||||
f->name = "lzop";
|
||||
return (r);
|
||||
}
|
||||
#else
|
||||
@@ -175,47 +175,47 @@ lzop_reader_vtable = {
|
||||
* Initialize the filter object.
|
||||
*/
|
||||
static int
|
||||
lzop_bidder_init(struct archive_read_filter *self)
|
||||
lzop_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct lzop *lzop;
|
||||
|
||||
self->code = ARCHIVE_FILTER_LZOP;
|
||||
self->name = "lzop";
|
||||
f->code = ARCHIVE_FILTER_LZOP;
|
||||
f->name = "lzop";
|
||||
|
||||
lzop = calloc(1, sizeof(*lzop));
|
||||
if (lzop == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for lzop decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = lzop;
|
||||
self->vtable = &lzop_reader_vtable;
|
||||
f->data = lzop;
|
||||
f->vtable = &lzop_reader_vtable;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
consume_header(struct archive_read_filter *self)
|
||||
consume_header(struct archive_read_filter *f)
|
||||
{
|
||||
struct lzop *lzop = self->data;
|
||||
struct lzop *lzop = f->data;
|
||||
const unsigned char *p, *_p;
|
||||
unsigned checksum, flags, len, method, version;
|
||||
|
||||
/*
|
||||
* Check LZOP magic code.
|
||||
*/
|
||||
p = __archive_read_filter_ahead(self->upstream,
|
||||
p = __archive_read_filter_ahead(f->upstream,
|
||||
LZOP_HEADER_MAGIC_LEN, NULL);
|
||||
if (p == NULL)
|
||||
return (ARCHIVE_EOF);
|
||||
|
||||
if (memcmp(p, LZOP_HEADER_MAGIC, LZOP_HEADER_MAGIC_LEN))
|
||||
return (ARCHIVE_EOF);
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
LZOP_HEADER_MAGIC_LEN);
|
||||
|
||||
p = __archive_read_filter_ahead(self->upstream, 29, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 29, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
_p = p;
|
||||
@@ -225,7 +225,7 @@ consume_header(struct archive_read_filter *self)
|
||||
if (version >= 0x940) {
|
||||
unsigned reqversion = archive_be16dec(p); p += 2;
|
||||
if (reqversion < 0x900) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Invalid required version");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
@@ -233,7 +233,7 @@ consume_header(struct archive_read_filter *self)
|
||||
|
||||
method = *p++;
|
||||
if (method < 1 || method > 3) {
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Unsupported method");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ consume_header(struct archive_read_filter *self)
|
||||
;/* NOP */
|
||||
#endif
|
||||
else if (level > 9) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Invalid level");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
@@ -270,7 +270,7 @@ consume_header(struct archive_read_filter *self)
|
||||
len = *p++; /* Read filename length */
|
||||
len += p - _p;
|
||||
/* Make sure we have all bytes we need to calculate checksum. */
|
||||
p = __archive_read_filter_ahead(self->upstream, len + 4, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, len + 4, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
if (flags & CRC32_HEADER)
|
||||
@@ -281,92 +281,92 @@ consume_header(struct archive_read_filter *self)
|
||||
if (archive_be32dec(p + len) != checksum)
|
||||
goto corrupted;
|
||||
#endif
|
||||
__archive_read_filter_consume(self->upstream, len + 4);
|
||||
__archive_read_filter_consume(f->upstream, len + 4);
|
||||
if (flags & EXTRA_FIELD) {
|
||||
/* Skip extra field */
|
||||
p = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
len = archive_be32dec(p);
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
(int64_t)len + 4 + 4);
|
||||
}
|
||||
lzop->flags = flags;
|
||||
lzop->in_stream = 1;
|
||||
return (ARCHIVE_OK);
|
||||
truncated:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzop data");
|
||||
return (ARCHIVE_FAILED);
|
||||
corrupted:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT, "Corrupted lzop header");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
|
||||
static int
|
||||
consume_block_info(struct archive_read_filter *self)
|
||||
consume_block_info(struct archive_read_filter *f)
|
||||
{
|
||||
struct lzop *lzop = self->data;
|
||||
struct lzop *lzop = f->data;
|
||||
const unsigned char *p;
|
||||
unsigned flags = lzop->flags;
|
||||
|
||||
p = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
lzop->uncompressed_size = archive_be32dec(p);
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
if (lzop->uncompressed_size == 0)
|
||||
return (ARCHIVE_EOF);
|
||||
if (lzop->uncompressed_size > MAX_BLOCK_SIZE)
|
||||
goto corrupted;
|
||||
|
||||
p = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
lzop->compressed_size = archive_be32dec(p);
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
if (lzop->compressed_size > lzop->uncompressed_size)
|
||||
goto corrupted;
|
||||
|
||||
if (flags & (CRC32_UNCOMPRESSED | ADLER32_UNCOMPRESSED)) {
|
||||
p = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
lzop->compressed_cksum = lzop->uncompressed_cksum =
|
||||
archive_be32dec(p);
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
}
|
||||
if ((flags & (CRC32_COMPRESSED | ADLER32_COMPRESSED)) &&
|
||||
lzop->compressed_size < lzop->uncompressed_size) {
|
||||
p = __archive_read_filter_ahead(self->upstream, 4, NULL);
|
||||
p = __archive_read_filter_ahead(f->upstream, 4, NULL);
|
||||
if (p == NULL)
|
||||
goto truncated;
|
||||
lzop->compressed_cksum = archive_be32dec(p);
|
||||
__archive_read_filter_consume(self->upstream, 4);
|
||||
__archive_read_filter_consume(f->upstream, 4);
|
||||
}
|
||||
return (ARCHIVE_OK);
|
||||
truncated:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzop data");
|
||||
return (ARCHIVE_FAILED);
|
||||
corrupted:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT, "Corrupted lzop header");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
lzop_filter_read(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct lzop *lzop = self->data;
|
||||
struct lzop *lzop = f->data;
|
||||
const void *b;
|
||||
lzo_uint out_size;
|
||||
uint32_t cksum;
|
||||
int ret, r;
|
||||
|
||||
if (lzop->unconsumed_bytes) {
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
lzop->unconsumed_bytes);
|
||||
lzop->unconsumed_bytes = 0;
|
||||
}
|
||||
@@ -375,7 +375,7 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
|
||||
for (;;) {
|
||||
if (!lzop->in_stream) {
|
||||
ret = consume_header(self);
|
||||
ret = consume_header(f);
|
||||
if (ret < ARCHIVE_OK)
|
||||
return (ret);
|
||||
if (ret == ARCHIVE_EOF) {
|
||||
@@ -383,7 +383,7 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
ret = consume_block_info(self);
|
||||
ret = consume_block_info(f);
|
||||
if (ret < ARCHIVE_OK)
|
||||
return (ret);
|
||||
if (ret == ARCHIVE_EOF)
|
||||
@@ -398,7 +398,7 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
|
||||
new_block = realloc(lzop->out_block, lzop->uncompressed_size);
|
||||
if (new_block == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for lzop decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -406,10 +406,10 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
lzop->out_block_size = lzop->uncompressed_size;
|
||||
}
|
||||
|
||||
b = __archive_read_filter_ahead(self->upstream,
|
||||
b = __archive_read_filter_ahead(f->upstream,
|
||||
lzop->compressed_size, NULL);
|
||||
if (b == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzop data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -420,7 +420,7 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
else
|
||||
cksum = lzop->compressed_cksum;
|
||||
if (cksum != lzop->compressed_cksum) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Corrupted data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -445,15 +445,15 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
case LZO_E_OK:
|
||||
if (out_size == lzop->uncompressed_size)
|
||||
break;
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Corrupted data");
|
||||
return (ARCHIVE_FATAL);
|
||||
case LZO_E_OUT_OF_MEMORY:
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"lzop decompression failed: out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
default:
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"lzop decompression failed: %d", r);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -467,12 +467,12 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
else
|
||||
cksum = lzop->uncompressed_cksum;
|
||||
if (cksum != lzop->uncompressed_cksum) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC, "Corrupted data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
__archive_read_filter_consume(self->upstream, lzop->compressed_size);
|
||||
__archive_read_filter_consume(f->upstream, lzop->compressed_size);
|
||||
*p = lzop->out_block;
|
||||
return ((ssize_t)out_size);
|
||||
}
|
||||
@@ -481,9 +481,9 @@ lzop_filter_read(struct archive_read_filter *self, const void **p)
|
||||
* Clean up the decompressor.
|
||||
*/
|
||||
static int
|
||||
lzop_filter_close(struct archive_read_filter *self)
|
||||
lzop_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct lzop *lzop = self->data;
|
||||
struct lzop *lzop = f->data;
|
||||
|
||||
free(lzop->out_block);
|
||||
free(lzop);
|
||||
|
||||
@@ -168,9 +168,9 @@ memerr:
|
||||
}
|
||||
|
||||
static void
|
||||
program_bidder_free(struct archive_read_filter_bidder *self)
|
||||
program_bidder_free(struct archive_read_filter_bidder *b)
|
||||
{
|
||||
struct program_bidder *state = (struct program_bidder *)self->data;
|
||||
struct program_bidder *state = (struct program_bidder *)b->data;
|
||||
|
||||
free_state(state);
|
||||
}
|
||||
@@ -193,15 +193,15 @@ free_state(struct program_bidder *state)
|
||||
* we're called, then never bid again.
|
||||
*/
|
||||
static int
|
||||
program_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *upstream)
|
||||
program_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
struct program_bidder *state = self->data;
|
||||
struct program_bidder *state = b->data;
|
||||
const char *p;
|
||||
|
||||
/* If we have a signature, use that to match. */
|
||||
if (state->signature_len > 0) {
|
||||
p = __archive_read_filter_ahead(upstream,
|
||||
p = __archive_read_filter_ahead(f,
|
||||
state->signature_len, NULL);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
@@ -226,7 +226,7 @@ program_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
* (including error message if the child came to a bad end).
|
||||
*/
|
||||
static int
|
||||
child_stop(struct archive_read_filter *self, struct program *program)
|
||||
child_stop(struct archive_read_filter *f, struct program *program)
|
||||
{
|
||||
/* Close our side of the I/O with the child. */
|
||||
if (program->child_stdin != -1) {
|
||||
@@ -249,7 +249,7 @@ child_stop(struct archive_read_filter *self, struct program *program)
|
||||
|
||||
if (program->waitpid_return < 0) {
|
||||
/* waitpid() failed? This is ugly. */
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Error closing child process");
|
||||
return (ARCHIVE_WARN);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ child_stop(struct archive_read_filter *self, struct program *program)
|
||||
if (WTERMSIG(program->exit_status) == SIGPIPE)
|
||||
return (ARCHIVE_OK);
|
||||
#endif
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Child process exited with signal %d",
|
||||
WTERMSIG(program->exit_status));
|
||||
return (ARCHIVE_WARN);
|
||||
@@ -277,7 +277,7 @@ child_stop(struct archive_read_filter *self, struct program *program)
|
||||
if (WEXITSTATUS(program->exit_status) == 0)
|
||||
return (ARCHIVE_OK);
|
||||
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Child process exited with status %d",
|
||||
WEXITSTATUS(program->exit_status));
|
||||
@@ -291,9 +291,9 @@ child_stop(struct archive_read_filter *self, struct program *program)
|
||||
* Use select() to decide whether the child is ready for read or write.
|
||||
*/
|
||||
static ssize_t
|
||||
child_read(struct archive_read_filter *self, char *buf, size_t buf_len)
|
||||
child_read(struct archive_read_filter *f, char *buf, size_t buf_len)
|
||||
{
|
||||
struct program *program = self->data;
|
||||
struct program *program = f->data;
|
||||
ssize_t ret, requested, avail;
|
||||
const char *p;
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
@@ -333,7 +333,7 @@ child_read(struct archive_read_filter *self, char *buf, size_t buf_len)
|
||||
if (ret == 0 || (ret == -1 && errno == EPIPE))
|
||||
/* Child has closed its output; reap the child
|
||||
* and return the status. */
|
||||
return (child_stop(self, program));
|
||||
return (child_stop(f, program));
|
||||
if (ret == -1 && errno != EAGAIN)
|
||||
return (-1);
|
||||
|
||||
@@ -345,7 +345,7 @@ child_read(struct archive_read_filter *self, char *buf, size_t buf_len)
|
||||
}
|
||||
|
||||
/* Get some more data from upstream. */
|
||||
p = __archive_read_filter_ahead(self->upstream, 1, &avail);
|
||||
p = __archive_read_filter_ahead(f->upstream, 1, &avail);
|
||||
if (p == NULL) {
|
||||
close(program->child_stdin);
|
||||
program->child_stdin = -1;
|
||||
@@ -361,7 +361,7 @@ child_read(struct archive_read_filter *self, char *buf, size_t buf_len)
|
||||
|
||||
if (ret > 0) {
|
||||
/* Consume whatever we managed to write. */
|
||||
__archive_read_filter_consume(self->upstream, ret);
|
||||
__archive_read_filter_consume(f->upstream, ret);
|
||||
} else if (ret == -1 && errno == EAGAIN) {
|
||||
/* Block until child has some I/O ready. */
|
||||
__archive_check_child(program->child_stdin,
|
||||
@@ -387,7 +387,7 @@ program_reader_vtable = {
|
||||
};
|
||||
|
||||
int
|
||||
__archive_read_program(struct archive_read_filter *self, const char *cmd)
|
||||
__archive_read_program(struct archive_read_filter *f, const char *cmd)
|
||||
{
|
||||
struct program *program;
|
||||
static const size_t out_buf_len = 65536;
|
||||
@@ -401,7 +401,7 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd)
|
||||
out_buf = malloc(out_buf_len);
|
||||
if (program == NULL || out_buf == NULL ||
|
||||
archive_string_ensure(&program->description, l) == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate input data");
|
||||
if (program != NULL) {
|
||||
archive_string_free(&program->description);
|
||||
@@ -413,8 +413,8 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd)
|
||||
archive_strcpy(&program->description, prefix);
|
||||
archive_strcat(&program->description, cmd);
|
||||
|
||||
self->code = ARCHIVE_FILTER_PROGRAM;
|
||||
self->name = program->description.s;
|
||||
f->code = ARCHIVE_FILTER_PROGRAM;
|
||||
f->name = program->description.s;
|
||||
|
||||
program->out_buf = out_buf;
|
||||
program->out_buf_len = out_buf_len;
|
||||
@@ -425,32 +425,32 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd)
|
||||
free(program->out_buf);
|
||||
archive_string_free(&program->description);
|
||||
free(program);
|
||||
archive_set_error(&self->archive->archive, EINVAL,
|
||||
archive_set_error(&f->archive->archive, EINVAL,
|
||||
"Can't initialize filter; unable to run program \"%s\"",
|
||||
cmd);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = program;
|
||||
self->vtable = &program_reader_vtable;
|
||||
f->data = program;
|
||||
f->vtable = &program_reader_vtable;
|
||||
|
||||
/* XXX Check that we can read at least one byte? */
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
program_bidder_init(struct archive_read_filter *self)
|
||||
program_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct program_bidder *bidder_state;
|
||||
|
||||
bidder_state = (struct program_bidder *)self->bidder->data;
|
||||
return (__archive_read_program(self, bidder_state->cmd));
|
||||
bidder_state = (struct program_bidder *)f->bidder->data;
|
||||
return (__archive_read_program(f, bidder_state->cmd));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
program_filter_read(struct archive_read_filter *self, const void **buff)
|
||||
program_filter_read(struct archive_read_filter *f, const void **buff)
|
||||
{
|
||||
struct program *program = self->data;
|
||||
struct program *program = f->data;
|
||||
ssize_t bytes;
|
||||
size_t total;
|
||||
char *p;
|
||||
@@ -458,7 +458,7 @@ program_filter_read(struct archive_read_filter *self, const void **buff)
|
||||
total = 0;
|
||||
p = program->out_buf;
|
||||
while (program->child_stdout != -1 && total < program->out_buf_len) {
|
||||
bytes = child_read(self, p, program->out_buf_len - total);
|
||||
bytes = child_read(f, p, program->out_buf_len - total);
|
||||
if (bytes < 0)
|
||||
/* No recovery is possible if we can no longer
|
||||
* read from the child. */
|
||||
@@ -475,12 +475,12 @@ program_filter_read(struct archive_read_filter *self, const void **buff)
|
||||
}
|
||||
|
||||
static int
|
||||
program_filter_close(struct archive_read_filter *self)
|
||||
program_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct program *program = self->data;
|
||||
struct program *program = f->data;
|
||||
int e;
|
||||
|
||||
e = child_stop(self, program);
|
||||
e = child_stop(f, program);
|
||||
|
||||
/* Release our private data. */
|
||||
free(program->out_buf);
|
||||
|
||||
@@ -76,38 +76,38 @@ archive_read_support_filter_rpm(struct archive *_a)
|
||||
}
|
||||
|
||||
static int
|
||||
rpm_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
rpm_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *b;
|
||||
const unsigned char *p;
|
||||
int bits_checked;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
b = __archive_read_filter_ahead(filter, 8, NULL);
|
||||
if (b == NULL)
|
||||
p = __archive_read_filter_ahead(f, 8, NULL);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
|
||||
bits_checked = 0;
|
||||
/*
|
||||
* Verify Header Magic Bytes : 0XED 0XAB 0XEE 0XDB
|
||||
*/
|
||||
if (memcmp(b, "\xED\xAB\xEE\xDB", 4) != 0)
|
||||
if (memcmp(p, "\xED\xAB\xEE\xDB", 4) != 0)
|
||||
return (0);
|
||||
bits_checked += 32;
|
||||
/*
|
||||
* Check major version.
|
||||
*/
|
||||
if (b[4] != 3 && b[4] != 4)
|
||||
if (p[4] != 3 && p[4] != 4)
|
||||
return (0);
|
||||
bits_checked += 8;
|
||||
/*
|
||||
* Check package type; binary or source.
|
||||
*/
|
||||
if (b[6] != 0)
|
||||
if (p[6] != 0)
|
||||
return (0);
|
||||
bits_checked += 8;
|
||||
if (b[7] != 0 && b[7] != 1)
|
||||
if (p[7] != 0 && p[7] != 1)
|
||||
return (0);
|
||||
bits_checked += 8;
|
||||
|
||||
@@ -121,40 +121,40 @@ rpm_reader_vtable = {
|
||||
};
|
||||
|
||||
static int
|
||||
rpm_bidder_init(struct archive_read_filter *self)
|
||||
rpm_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct rpm *rpm;
|
||||
|
||||
self->code = ARCHIVE_FILTER_RPM;
|
||||
self->name = "rpm";
|
||||
f->code = ARCHIVE_FILTER_RPM;
|
||||
f->name = "rpm";
|
||||
|
||||
rpm = calloc(1, sizeof(*rpm));
|
||||
if (rpm == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for rpm");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = rpm;
|
||||
f->data = rpm;
|
||||
rpm->data_reached = 0;
|
||||
self->vtable = &rpm_reader_vtable;
|
||||
f->vtable = &rpm_reader_vtable;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
skip_padding(struct archive_read_filter *self)
|
||||
skip_padding(struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *h;
|
||||
ssize_t avail, count, r;
|
||||
|
||||
do {
|
||||
h = __archive_read_filter_ahead(self->upstream, 1, &avail);
|
||||
h = __archive_read_filter_ahead(f->upstream, 1, &avail);
|
||||
if (h == NULL)
|
||||
return (ARCHIVE_FATAL);
|
||||
for (count = 0; count < avail && *h++ == '\0'; count++)
|
||||
;
|
||||
r = __archive_read_filter_consume(self->upstream, count);
|
||||
r = __archive_read_filter_consume(f->upstream, count);
|
||||
if (r < 0)
|
||||
return (r);
|
||||
} while (count == avail);
|
||||
@@ -163,20 +163,20 @@ skip_padding(struct archive_read_filter *self)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
skip_prologue(struct archive_read_filter *self)
|
||||
skip_prologue(struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *h;
|
||||
ssize_t r;
|
||||
int header, seen_header = 0;
|
||||
|
||||
/* Skip lead size. */
|
||||
r = __archive_read_filter_consume(self->upstream, RPM_LEAD_SIZE);
|
||||
r = __archive_read_filter_consume(f->upstream, RPM_LEAD_SIZE);
|
||||
if (r < 0)
|
||||
return (r);
|
||||
|
||||
do {
|
||||
/* Read header intro. */
|
||||
h = __archive_read_filter_ahead(self->upstream,
|
||||
h = __archive_read_filter_ahead(f->upstream,
|
||||
RPM_MIN_HEAD_SIZE, NULL);
|
||||
if (h == NULL)
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -193,13 +193,13 @@ skip_prologue(struct archive_read_filter *self)
|
||||
length = RPM_MIN_HEAD_SIZE + section * 16 + bytes;
|
||||
|
||||
/* Skip header. */
|
||||
r = __archive_read_filter_consume(self->upstream,
|
||||
r = __archive_read_filter_consume(f->upstream,
|
||||
length);
|
||||
if (r < 0)
|
||||
return (r);
|
||||
|
||||
/* Skip padding. */
|
||||
r = skip_padding(self);
|
||||
r = skip_padding(f);
|
||||
if (r != ARCHIVE_OK)
|
||||
return (r);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ skip_prologue(struct archive_read_filter *self)
|
||||
/* At least one header must have been encountered. */
|
||||
if (!seen_header) {
|
||||
archive_set_error(
|
||||
&self->archive->archive,
|
||||
&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT,
|
||||
"Unrecognized rpm header");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -218,29 +218,29 @@ skip_prologue(struct archive_read_filter *self)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
rpm_filter_read(struct archive_read_filter *self, const void **buff)
|
||||
rpm_filter_read(struct archive_read_filter *f, const void **buff)
|
||||
{
|
||||
struct rpm *rpm = self->data;
|
||||
struct rpm *rpm = f->data;
|
||||
ssize_t r;
|
||||
|
||||
if (!rpm->data_reached) {
|
||||
r = skip_prologue(self);
|
||||
r = skip_prologue(f);
|
||||
if (r != ARCHIVE_OK)
|
||||
return (r);
|
||||
rpm->data_reached = 1;
|
||||
}
|
||||
|
||||
*buff = __archive_read_filter_ahead(self->upstream, 1, &r);
|
||||
*buff = __archive_read_filter_ahead(f->upstream, 1, &r);
|
||||
if (r > 0)
|
||||
__archive_read_filter_consume(self->upstream, r);
|
||||
__archive_read_filter_consume(f->upstream, r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
rpm_filter_close(struct archive_read_filter *self)
|
||||
rpm_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct rpm *rpm = self->data;
|
||||
struct rpm *rpm = f->data;
|
||||
|
||||
free(rpm);
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ get_line(const unsigned char *b, ssize_t avail, ssize_t *nlsize)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
bid_get_line(struct archive_read_filter *filter,
|
||||
bid_get_line(struct archive_read_filter *f,
|
||||
const unsigned char **b, ssize_t *avail, ssize_t *ravail,
|
||||
ssize_t *nl, size_t* nbytes_read)
|
||||
{
|
||||
@@ -235,12 +235,12 @@ bid_get_line(struct archive_read_filter *filter,
|
||||
if (nbytes_req < (size_t)*ravail + 160)
|
||||
nbytes_req <<= 1;
|
||||
|
||||
*b = __archive_read_filter_ahead(filter, nbytes_req, avail);
|
||||
*b = __archive_read_filter_ahead(f, nbytes_req, avail);
|
||||
if (*b == NULL) {
|
||||
if (*ravail >= *avail)
|
||||
return (0);
|
||||
/* Reading bytes reaches the end of a stream. */
|
||||
*b = __archive_read_filter_ahead(filter, *avail, avail);
|
||||
*b = __archive_read_filter_ahead(f, *avail, avail);
|
||||
quit = 1;
|
||||
}
|
||||
*nbytes_read = *avail;
|
||||
@@ -258,42 +258,42 @@ bid_get_line(struct archive_read_filter *filter,
|
||||
#define UUDECODE(c) (((c) - 0x20) & 0x3f)
|
||||
|
||||
static int
|
||||
uudecode_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
uudecode_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *b;
|
||||
const unsigned char *p;
|
||||
ssize_t avail, ravail;
|
||||
ssize_t len, nl;
|
||||
int l;
|
||||
int firstline;
|
||||
size_t nbytes_read;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
b = __archive_read_filter_ahead(filter, 1, &avail);
|
||||
if (b == NULL)
|
||||
p = __archive_read_filter_ahead(f, 1, &avail);
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
|
||||
firstline = 20;
|
||||
ravail = avail;
|
||||
nbytes_read = avail;
|
||||
for (;;) {
|
||||
len = bid_get_line(filter, &b, &avail, &ravail, &nl, &nbytes_read);
|
||||
len = bid_get_line(f, &p, &avail, &ravail, &nl, &nbytes_read);
|
||||
if (len < 0 || nl == 0)
|
||||
return (0); /* No match found. */
|
||||
if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0)
|
||||
if (len - nl >= 11 && memcmp(p, "begin ", 6) == 0)
|
||||
l = 6;
|
||||
else if (len -nl >= 18 && memcmp(b, "begin-base64 ", 13) == 0)
|
||||
else if (len -nl >= 18 && memcmp(p, "begin-base64 ", 13) == 0)
|
||||
l = 13;
|
||||
else
|
||||
l = 0;
|
||||
|
||||
if (l > 0 && (b[l] < '0' || b[l] > '7' ||
|
||||
b[l+1] < '0' || b[l+1] > '7' ||
|
||||
b[l+2] < '0' || b[l+2] > '7' || b[l+3] != ' '))
|
||||
if (l > 0 && (p[l] < '0' || p[l] > '7' ||
|
||||
p[l+1] < '0' || p[l+1] > '7' ||
|
||||
p[l+2] < '0' || p[l+2] > '7' || p[l+3] != ' '))
|
||||
l = 0;
|
||||
|
||||
b += len;
|
||||
p += len;
|
||||
avail -= len;
|
||||
if (l)
|
||||
break;
|
||||
@@ -305,51 +305,51 @@ uudecode_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
}
|
||||
if (!avail)
|
||||
return (0);
|
||||
len = bid_get_line(filter, &b, &avail, &ravail, &nl, &nbytes_read);
|
||||
len = bid_get_line(f, &p, &avail, &ravail, &nl, &nbytes_read);
|
||||
if (len < 0 || nl == 0)
|
||||
return (0);/* There are non-ascii characters. */
|
||||
avail -= len;
|
||||
|
||||
if (l == 6) {
|
||||
/* "begin " */
|
||||
if (!uuchar[*b])
|
||||
if (!uuchar[*p])
|
||||
return (0);
|
||||
/* Get a length of decoded bytes. */
|
||||
l = UUDECODE(*b++); len--;
|
||||
l = UUDECODE(*p++); len--;
|
||||
if (l > 45)
|
||||
/* Normally, maximum length is 45(character 'M'). */
|
||||
return (0);
|
||||
if (l > len - nl)
|
||||
return (0); /* Line too short. */
|
||||
while (l) {
|
||||
if (!uuchar[*b++])
|
||||
if (!uuchar[*p++])
|
||||
return (0);
|
||||
--len;
|
||||
--l;
|
||||
}
|
||||
if (len-nl == 1 &&
|
||||
(uuchar[*b] || /* Check sum. */
|
||||
(*b >= 'a' && *b <= 'z'))) {/* Padding data(MINIX). */
|
||||
++b;
|
||||
(uuchar[*p] || /* Check sum. */
|
||||
(*p >= 'a' && *p <= 'z'))) {/* Padding data(MINIX). */
|
||||
++p;
|
||||
--len;
|
||||
}
|
||||
b += nl;
|
||||
if (avail && uuchar[*b])
|
||||
p += nl;
|
||||
if (avail && uuchar[*p])
|
||||
return (firstline+30);
|
||||
} else if (l == 13) {
|
||||
/* "begin-base64 " */
|
||||
while (len-nl > 0) {
|
||||
if (!base64[*b++])
|
||||
if (!base64[*p++])
|
||||
return (0);
|
||||
--len;
|
||||
}
|
||||
b += nl;
|
||||
p += nl;
|
||||
|
||||
if (avail >= 5 && memcmp(b, "====\n", 5) == 0)
|
||||
if (avail >= 5 && memcmp(p, "====\n", 5) == 0)
|
||||
return (firstline+40);
|
||||
if (avail >= 6 && memcmp(b, "====\r\n", 6) == 0)
|
||||
if (avail >= 6 && memcmp(p, "====\r\n", 6) == 0)
|
||||
return (firstline+40);
|
||||
if (avail > 0 && base64[*b])
|
||||
if (avail > 0 && base64[*p])
|
||||
return (firstline+30);
|
||||
}
|
||||
|
||||
@@ -364,20 +364,20 @@ uudecode_reader_vtable = {
|
||||
};
|
||||
|
||||
static int
|
||||
uudecode_bidder_init(struct archive_read_filter *self)
|
||||
uudecode_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct uu *uu;
|
||||
void *out_buff;
|
||||
void *in_buff;
|
||||
|
||||
self->code = ARCHIVE_FILTER_UU;
|
||||
self->name = "uu";
|
||||
f->code = ARCHIVE_FILTER_UU;
|
||||
f->name = "uu";
|
||||
|
||||
uu = calloc(1, sizeof(*uu));
|
||||
out_buff = malloc(OUT_BUFF_SIZE);
|
||||
in_buff = malloc(IN_BUFF_SIZE);
|
||||
if (uu == NULL || out_buff == NULL || in_buff == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for uudecode");
|
||||
free(uu);
|
||||
free(out_buff);
|
||||
@@ -385,7 +385,7 @@ uudecode_bidder_init(struct archive_read_filter *self)
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = uu;
|
||||
f->data = uu;
|
||||
uu->in_buff = in_buff;
|
||||
uu->in_cnt = 0;
|
||||
uu->in_allocated = IN_BUFF_SIZE;
|
||||
@@ -393,13 +393,13 @@ uudecode_bidder_init(struct archive_read_filter *self)
|
||||
uu->state = ST_FIND_HEAD;
|
||||
uu->mode_set = 0;
|
||||
uu->name = NULL;
|
||||
self->vtable = &uudecode_reader_vtable;
|
||||
f->vtable = &uudecode_reader_vtable;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
ensure_in_buff_size(struct archive_read_filter *self,
|
||||
ensure_in_buff_size(struct archive_read_filter *f,
|
||||
struct uu *uu, size_t size)
|
||||
{
|
||||
|
||||
@@ -421,7 +421,7 @@ ensure_in_buff_size(struct archive_read_filter *self,
|
||||
/* Allocate the new buffer. */
|
||||
ptr = malloc(newsize);
|
||||
if (ptr == NULL) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ENOMEM,
|
||||
"Can't allocate data for uudecode");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -438,10 +438,9 @@ ensure_in_buff_size(struct archive_read_filter *self,
|
||||
}
|
||||
|
||||
static int
|
||||
uudecode_read_header(struct archive_read_filter *self, struct archive_entry *entry)
|
||||
uudecode_read_header(struct archive_read_filter *f, struct archive_entry *entry)
|
||||
{
|
||||
|
||||
struct uu *uu = self->data;
|
||||
struct uu *uu = f->data;
|
||||
|
||||
if (uu->mode_set != 0)
|
||||
archive_entry_set_mode(entry, S_IFREG | uu->mode);
|
||||
@@ -453,9 +452,9 @@ uudecode_read_header(struct archive_read_filter *self, struct archive_entry *ent
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
uudecode_filter_read(struct archive_read_filter *self, const void **buff)
|
||||
uudecode_filter_read(struct archive_read_filter *f, const void **buff)
|
||||
{
|
||||
struct uu *uu = self->data;
|
||||
struct uu *uu = f->data;
|
||||
const unsigned char *b, *d;
|
||||
unsigned char *out;
|
||||
ssize_t avail_in, ravail;
|
||||
@@ -464,7 +463,7 @@ uudecode_filter_read(struct archive_read_filter *self, const void **buff)
|
||||
ssize_t len, llen, nl, namelen;
|
||||
|
||||
read_more:
|
||||
d = __archive_read_filter_ahead(self->upstream, 1, &avail_in);
|
||||
d = __archive_read_filter_ahead(f->upstream, 1, &avail_in);
|
||||
if (d == NULL && avail_in < 0)
|
||||
return (ARCHIVE_FATAL);
|
||||
/* Quiet a code analyzer; make sure avail_in must be zero
|
||||
@@ -483,7 +482,7 @@ read_more:
|
||||
}
|
||||
if (uu->in_cnt) {
|
||||
if (uu->in_cnt > UUENCODE_BID_MAX_READ) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT,
|
||||
"Invalid format data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -492,7 +491,7 @@ read_more:
|
||||
* If there is remaining data which is saved by
|
||||
* a previous call, use it first.
|
||||
*/
|
||||
if (ensure_in_buff_size(self, uu,
|
||||
if (ensure_in_buff_size(f, uu,
|
||||
avail_in + uu->in_cnt) != ARCHIVE_OK)
|
||||
return (ARCHIVE_FATAL);
|
||||
if (avail_in > 0)
|
||||
@@ -515,13 +514,13 @@ read_more:
|
||||
used = avail_in;
|
||||
goto finish;
|
||||
}
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Insufficient compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (len > UUENCODE_BID_MAX_READ) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT,
|
||||
"Invalid format data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -530,7 +529,7 @@ read_more:
|
||||
if ((nl == 0) && (uu->state != ST_UUEND)) {
|
||||
if (total == 0 && ravail <= 0) {
|
||||
/* There is nothing more to read, fail */
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT,
|
||||
"Missing format data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -539,7 +538,7 @@ read_more:
|
||||
* Save remaining data which does not contain
|
||||
* NL('\n','\r').
|
||||
*/
|
||||
if (ensure_in_buff_size(self, uu, len)
|
||||
if (ensure_in_buff_size(f, uu, len)
|
||||
!= ARCHIVE_OK)
|
||||
return (ARCHIVE_FATAL);
|
||||
if (uu->in_buff != b)
|
||||
@@ -549,7 +548,7 @@ read_more:
|
||||
/* Do not return 0; it means end-of-file.
|
||||
* We should try to read more bytes. */
|
||||
__archive_read_filter_consume(
|
||||
self->upstream, ravail);
|
||||
f->upstream, ravail);
|
||||
goto read_more;
|
||||
}
|
||||
used += len;
|
||||
@@ -560,7 +559,7 @@ read_more:
|
||||
case ST_FIND_HEAD:
|
||||
/* Do not read more than UUENCODE_BID_MAX_READ bytes */
|
||||
if (total + len >= UUENCODE_BID_MAX_READ) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_FILE_FORMAT,
|
||||
"Invalid format data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -591,7 +590,7 @@ read_more:
|
||||
uu->name = malloc(namelen + 1);
|
||||
if (uu->name == NULL) {
|
||||
archive_set_error(
|
||||
&self->archive->archive,
|
||||
&f->archive->archive,
|
||||
ENOMEM,
|
||||
"Can't allocate data for uudecode");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -608,7 +607,7 @@ read_more:
|
||||
goto finish;
|
||||
body = len - nl;
|
||||
if (!uuchar[*b] || body <= 0) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Insufficient compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -617,7 +616,7 @@ read_more:
|
||||
l = UUDECODE(*b++);
|
||||
body--;
|
||||
if (l > body) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Insufficient compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -652,7 +651,7 @@ read_more:
|
||||
}
|
||||
}
|
||||
if (l) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Insufficient compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -662,7 +661,7 @@ read_more:
|
||||
if (len - nl == 3 && memcmp(b, "end ", 3) == 0)
|
||||
uu->state = ST_FIND_HEAD;
|
||||
else {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Insufficient compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -707,7 +706,7 @@ read_more:
|
||||
}
|
||||
}
|
||||
if (l && *b != '=') {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Insufficient compressed data");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -718,7 +717,7 @@ read_more:
|
||||
finish:
|
||||
if (ravail < avail_in)
|
||||
used -= avail_in - ravail;
|
||||
__archive_read_filter_consume(self->upstream, used);
|
||||
__archive_read_filter_consume(f->upstream, used);
|
||||
|
||||
*buff = uu->out_buff;
|
||||
uu->total += total;
|
||||
@@ -726,9 +725,9 @@ finish:
|
||||
}
|
||||
|
||||
static int
|
||||
uudecode_filter_close(struct archive_read_filter *self)
|
||||
uudecode_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct uu *uu = self->data;
|
||||
struct uu *uu = f->data;
|
||||
|
||||
free(uu->in_buff);
|
||||
free(uu->out_buff);
|
||||
|
||||
@@ -197,14 +197,14 @@ archive_read_support_filter_lzip(struct archive *_a)
|
||||
* Test whether we can handle this data.
|
||||
*/
|
||||
static int
|
||||
xz_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
xz_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
buffer = __archive_read_filter_ahead(filter, 6, NULL);
|
||||
buffer = __archive_read_filter_ahead(f, 6, NULL);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -230,17 +230,17 @@ xz_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
* they have other evidence (file name, command-line option) to go on.
|
||||
*/
|
||||
static int
|
||||
lzma_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
lzma_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
uint32_t dicsize;
|
||||
uint64_t uncompressed_size;
|
||||
int bits_checked;
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
(void)b; /* UNUSED */
|
||||
|
||||
buffer = __archive_read_filter_ahead(filter, 14, NULL);
|
||||
buffer = __archive_read_filter_ahead(f, 14, NULL);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -336,13 +336,13 @@ lzma_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
}
|
||||
|
||||
static int
|
||||
lzip_has_member(struct archive_read_filter *filter)
|
||||
lzip_has_member(struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
int bits_checked;
|
||||
int log2dic;
|
||||
|
||||
buffer = __archive_read_filter_ahead(filter, 6, NULL);
|
||||
buffer = __archive_read_filter_ahead(f, 6, NULL);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
|
||||
@@ -369,12 +369,12 @@ lzip_has_member(struct archive_read_filter *filter)
|
||||
}
|
||||
|
||||
static int
|
||||
lzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
lzip_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
|
||||
(void)self; /* UNUSED */
|
||||
return (lzip_has_member(filter));
|
||||
(void)b; /* UNUSED */
|
||||
return (lzip_has_member(f));
|
||||
}
|
||||
|
||||
#if HAVE_LZMA_H && HAVE_LIBLZMA
|
||||
@@ -383,34 +383,34 @@ lzip_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
* liblzma 4.999.7 and later support both lzma and xz streams.
|
||||
*/
|
||||
static int
|
||||
xz_bidder_init(struct archive_read_filter *self)
|
||||
xz_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
self->code = ARCHIVE_FILTER_XZ;
|
||||
self->name = "xz";
|
||||
return (xz_lzma_bidder_init(self));
|
||||
f->code = ARCHIVE_FILTER_XZ;
|
||||
f->name = "xz";
|
||||
return (xz_lzma_bidder_init(f));
|
||||
}
|
||||
|
||||
static int
|
||||
lzma_bidder_init(struct archive_read_filter *self)
|
||||
lzma_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
self->code = ARCHIVE_FILTER_LZMA;
|
||||
self->name = "lzma";
|
||||
return (xz_lzma_bidder_init(self));
|
||||
f->code = ARCHIVE_FILTER_LZMA;
|
||||
f->name = "lzma";
|
||||
return (xz_lzma_bidder_init(f));
|
||||
}
|
||||
|
||||
static int
|
||||
lzip_bidder_init(struct archive_read_filter *self)
|
||||
lzip_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
self->code = ARCHIVE_FILTER_LZIP;
|
||||
self->name = "lzip";
|
||||
return (xz_lzma_bidder_init(self));
|
||||
f->code = ARCHIVE_FILTER_LZIP;
|
||||
f->name = "lzip";
|
||||
return (xz_lzma_bidder_init(f));
|
||||
}
|
||||
|
||||
/*
|
||||
* Set an error code and choose an error message
|
||||
*/
|
||||
static void
|
||||
set_error(struct archive_read_filter *self, int ret)
|
||||
set_error(struct archive_read_filter *f, int ret)
|
||||
{
|
||||
|
||||
switch (ret) {
|
||||
@@ -418,36 +418,36 @@ set_error(struct archive_read_filter *self, int ret)
|
||||
case LZMA_OK: /* Decompressor made some progress. */
|
||||
break;
|
||||
case LZMA_MEM_ERROR:
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Lzma library error: Cannot allocate memory");
|
||||
break;
|
||||
case LZMA_MEMLIMIT_ERROR:
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Lzma library error: Out of memory");
|
||||
break;
|
||||
case LZMA_FORMAT_ERROR:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Lzma library error: format not recognized");
|
||||
break;
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Lzma library error: Invalid options");
|
||||
break;
|
||||
case LZMA_DATA_ERROR:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Lzma library error: Corrupted input data");
|
||||
break;
|
||||
case LZMA_BUF_ERROR:
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Lzma library error: No progress is possible");
|
||||
break;
|
||||
default:
|
||||
/* Return an error. */
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Lzma decompression failed: Unknown error");
|
||||
break;
|
||||
@@ -464,7 +464,7 @@ xz_lzma_reader_vtable = {
|
||||
* Setup the callbacks.
|
||||
*/
|
||||
static int
|
||||
xz_lzma_bidder_init(struct archive_read_filter *self)
|
||||
xz_lzma_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
static const size_t out_block_size = 64 * 1024;
|
||||
void *out_block;
|
||||
@@ -474,17 +474,17 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
|
||||
xz = calloc(1, sizeof(*xz));
|
||||
out_block = malloc(out_block_size);
|
||||
if (xz == NULL || out_block == NULL) {
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for xz decompression");
|
||||
free(out_block);
|
||||
free(xz);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = xz;
|
||||
f->data = xz;
|
||||
xz->out_block_size = out_block_size;
|
||||
xz->out_block = out_block;
|
||||
self->vtable = &xz_lzma_reader_vtable;
|
||||
f->vtable = &xz_lzma_reader_vtable;
|
||||
|
||||
xz->stream.avail_in = 0;
|
||||
|
||||
@@ -492,7 +492,7 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
|
||||
xz->stream.avail_out = xz->out_block_size;
|
||||
|
||||
xz->crc32 = 0;
|
||||
if (self->code == ARCHIVE_FILTER_LZIP) {
|
||||
if (f->code == ARCHIVE_FILTER_LZIP) {
|
||||
/*
|
||||
* We have to read a lzip header and use it to initialize
|
||||
* compression library, thus we cannot initialize the
|
||||
@@ -504,7 +504,7 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
|
||||
xz->in_stream = 1;
|
||||
|
||||
/* Initialize compression library. */
|
||||
if (self->code == ARCHIVE_FILTER_XZ)
|
||||
if (f->code == ARCHIVE_FILTER_XZ)
|
||||
ret = lzma_stream_decoder(&(xz->stream),
|
||||
LZMA_MEMLIMIT,/* memlimit */
|
||||
LZMA_CONCATENATED);
|
||||
@@ -516,26 +516,26 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
|
||||
return (ARCHIVE_OK);
|
||||
|
||||
/* Library setup failed: Choose an error message and clean up. */
|
||||
set_error(self, ret);
|
||||
set_error(f, ret);
|
||||
|
||||
free(xz->out_block);
|
||||
free(xz);
|
||||
self->data = NULL;
|
||||
self->vtable = NULL;
|
||||
f->data = NULL;
|
||||
f->vtable = NULL;
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
lzip_init(struct archive_read_filter *self)
|
||||
lzip_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct xz *xz = self->data;
|
||||
struct xz *xz = f->data;
|
||||
const unsigned char *h;
|
||||
lzma_filter filters[2];
|
||||
unsigned char props[5];
|
||||
uint32_t dicsize;
|
||||
int log2dic, ret;
|
||||
|
||||
h = __archive_read_filter_ahead(self->upstream, 6, NULL);
|
||||
h = __archive_read_filter_ahead(f->upstream, 6, NULL);
|
||||
if (h == NULL)
|
||||
return (ARCHIVE_FATAL);
|
||||
|
||||
@@ -557,7 +557,7 @@ lzip_init(struct archive_read_filter *self)
|
||||
archive_le32enc(props+1, dicsize);
|
||||
|
||||
/* Consume lzip header. */
|
||||
__archive_read_filter_consume(self->upstream, 6);
|
||||
__archive_read_filter_consume(f->upstream, 6);
|
||||
xz->member_in = 6;
|
||||
|
||||
filters[0].id = LZMA_FILTER_LZMA1;
|
||||
@@ -567,23 +567,23 @@ lzip_init(struct archive_read_filter *self)
|
||||
|
||||
ret = lzma_properties_decode(&filters[0], NULL, props, sizeof(props));
|
||||
if (ret != LZMA_OK) {
|
||||
set_error(self, ret);
|
||||
set_error(f, ret);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
ret = lzma_raw_decoder(&(xz->stream), filters);
|
||||
free(filters[0].options);
|
||||
if (ret != LZMA_OK) {
|
||||
set_error(self, ret);
|
||||
set_error(f, ret);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
lzip_tail(struct archive_read_filter *self)
|
||||
lzip_tail(struct archive_read_filter *f)
|
||||
{
|
||||
struct xz *xz = self->data;
|
||||
const unsigned char *f;
|
||||
struct xz *xz = f->data;
|
||||
const unsigned char *p;
|
||||
ssize_t avail_in;
|
||||
int tail;
|
||||
|
||||
@@ -591,44 +591,44 @@ lzip_tail(struct archive_read_filter *self)
|
||||
tail = 12;
|
||||
else
|
||||
tail = 20;
|
||||
f = __archive_read_filter_ahead(self->upstream, tail, &avail_in);
|
||||
if (f == NULL && avail_in < 0)
|
||||
p = __archive_read_filter_ahead(f->upstream, tail, &avail_in);
|
||||
if (p == NULL && avail_in < 0)
|
||||
return (ARCHIVE_FATAL);
|
||||
if (f == NULL || avail_in < tail) {
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
if (p == NULL || avail_in < tail) {
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Lzip: Remaining data is less bytes");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
|
||||
/* Check the crc32 value of the uncompressed data of the current
|
||||
* member */
|
||||
if (xz->crc32 != archive_le32dec(f)) {
|
||||
if (xz->crc32 != archive_le32dec(p)) {
|
||||
#ifndef DONT_FAIL_ON_CRC_ERROR
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Lzip: CRC32 error");
|
||||
return (ARCHIVE_FAILED);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Check the uncompressed size of the current member */
|
||||
if ((uint64_t)xz->member_out != archive_le64dec(f + 4)) {
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
if ((uint64_t)xz->member_out != archive_le64dec(p + 4)) {
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Lzip: Uncompressed size error");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
|
||||
/* Check the total size of the current member */
|
||||
if (xz->lzip_ver == 1 &&
|
||||
(uint64_t)xz->member_in + tail != archive_le64dec(f + 12)) {
|
||||
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
(uint64_t)xz->member_in + tail != archive_le64dec(p + 12)) {
|
||||
archive_set_error(&f->archive->archive, ARCHIVE_ERRNO_MISC,
|
||||
"Lzip: Member size error");
|
||||
return (ARCHIVE_FAILED);
|
||||
}
|
||||
__archive_read_filter_consume(self->upstream, tail);
|
||||
__archive_read_filter_consume(f->upstream, tail);
|
||||
|
||||
/* If current lzip data consists of multi member, try decompressing
|
||||
* a next member. */
|
||||
if (lzip_has_member(self->upstream) != 0) {
|
||||
if (lzip_has_member(f->upstream) != 0) {
|
||||
xz->in_stream = 0;
|
||||
xz->crc32 = 0;
|
||||
xz->member_out = 0;
|
||||
@@ -642,9 +642,9 @@ lzip_tail(struct archive_read_filter *self)
|
||||
* Return the next block of decompressed data.
|
||||
*/
|
||||
static ssize_t
|
||||
xz_filter_read(struct archive_read_filter *self, const void **p)
|
||||
xz_filter_read(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct xz *xz = self->data;
|
||||
struct xz *xz = f->data;
|
||||
size_t decompressed;
|
||||
ssize_t avail_in;
|
||||
int64_t member_in;
|
||||
@@ -662,15 +662,15 @@ xz_filter_read(struct archive_read_filter *self, const void **p)
|
||||
/*
|
||||
* Initialize liblzma for lzip
|
||||
*/
|
||||
ret = lzip_init(self);
|
||||
ret = lzip_init(f);
|
||||
if (ret != ARCHIVE_OK)
|
||||
return (ret);
|
||||
xz->in_stream = 1;
|
||||
}
|
||||
xz->stream.next_in =
|
||||
__archive_read_filter_ahead(self->upstream, 1, &avail_in);
|
||||
__archive_read_filter_ahead(f->upstream, 1, &avail_in);
|
||||
if (xz->stream.next_in == NULL && avail_in < 0) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"truncated input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -685,13 +685,13 @@ xz_filter_read(struct archive_read_filter *self, const void **p)
|
||||
xz->eof = 1;
|
||||
/* FALL THROUGH */
|
||||
case LZMA_OK: /* Decompressor made some progress. */
|
||||
__archive_read_filter_consume(self->upstream,
|
||||
__archive_read_filter_consume(f->upstream,
|
||||
avail_in - xz->stream.avail_in);
|
||||
xz->member_in +=
|
||||
avail_in - xz->stream.avail_in;
|
||||
break;
|
||||
default:
|
||||
set_error(self, ret);
|
||||
set_error(f, ret);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
}
|
||||
@@ -700,9 +700,9 @@ xz_filter_read(struct archive_read_filter *self, const void **p)
|
||||
xz->member_out += decompressed;
|
||||
if (decompressed == 0) {
|
||||
if (member_in != xz->member_in &&
|
||||
self->code == ARCHIVE_FILTER_LZIP &&
|
||||
f->code == ARCHIVE_FILTER_LZIP &&
|
||||
xz->eof) {
|
||||
ret = lzip_tail(self);
|
||||
ret = lzip_tail(f);
|
||||
if (ret != ARCHIVE_OK)
|
||||
return (ret);
|
||||
if (!xz->eof)
|
||||
@@ -711,11 +711,11 @@ xz_filter_read(struct archive_read_filter *self, const void **p)
|
||||
*p = NULL;
|
||||
} else {
|
||||
*p = xz->out_block;
|
||||
if (self->code == ARCHIVE_FILTER_LZIP) {
|
||||
if (f->code == ARCHIVE_FILTER_LZIP) {
|
||||
xz->crc32 = lzma_crc32(xz->out_block,
|
||||
decompressed, xz->crc32);
|
||||
if (xz->eof) {
|
||||
ret = lzip_tail(self);
|
||||
ret = lzip_tail(f);
|
||||
if (ret != ARCHIVE_OK)
|
||||
return (ret);
|
||||
}
|
||||
@@ -728,9 +728,9 @@ xz_filter_read(struct archive_read_filter *self, const void **p)
|
||||
* Clean up the decompressor.
|
||||
*/
|
||||
static int
|
||||
xz_filter_close(struct archive_read_filter *self)
|
||||
xz_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct xz *xz = self->data;
|
||||
struct xz *xz = f->data;
|
||||
|
||||
lzma_end(&(xz->stream));
|
||||
free(xz->out_block);
|
||||
@@ -748,44 +748,44 @@ xz_filter_close(struct archive_read_filter *self)
|
||||
*
|
||||
*/
|
||||
static int
|
||||
lzma_bidder_init(struct archive_read_filter *self)
|
||||
lzma_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "lzma -d -qq");
|
||||
r = __archive_read_program(f, "lzma -d -qq");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_LZMA;
|
||||
self->name = "lzma";
|
||||
f->code = ARCHIVE_FILTER_LZMA;
|
||||
f->name = "lzma";
|
||||
return (r);
|
||||
}
|
||||
|
||||
static int
|
||||
xz_bidder_init(struct archive_read_filter *self)
|
||||
xz_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "xz -d -qq");
|
||||
r = __archive_read_program(f, "xz -d -qq");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_XZ;
|
||||
self->name = "xz";
|
||||
f->code = ARCHIVE_FILTER_XZ;
|
||||
f->name = "xz";
|
||||
return (r);
|
||||
}
|
||||
|
||||
static int
|
||||
lzip_bidder_init(struct archive_read_filter *self)
|
||||
lzip_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "lzip -d -q");
|
||||
r = __archive_read_program(f, "lzip -d -q");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_LZIP;
|
||||
self->name = "lzip";
|
||||
f->code = ARCHIVE_FILTER_LZIP;
|
||||
f->name = "lzip";
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ archive_read_support_filter_zstd(struct archive *_a)
|
||||
* Test whether we can handle this data.
|
||||
*/
|
||||
static int
|
||||
zstd_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
struct archive_read_filter *filter)
|
||||
zstd_bidder_bid(struct archive_read_filter_bidder *b,
|
||||
struct archive_read_filter *f)
|
||||
{
|
||||
const unsigned char *buffer;
|
||||
ssize_t avail;
|
||||
@@ -132,9 +132,9 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
const uint32_t zstd_magic_skippable_start = 0x184D2A50;
|
||||
const uint32_t zstd_magic_skippable_mask = 0xFFFFFFF0;
|
||||
|
||||
(void) self; /* UNUSED */
|
||||
(void) b; /* UNUSED */
|
||||
|
||||
buffer = __archive_read_filter_ahead(filter, min_zstd_frame_size,
|
||||
buffer = __archive_read_filter_ahead(f, min_zstd_frame_size,
|
||||
&avail);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -151,7 +151,7 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
|
||||
/* Ensure that we can read another 4 bytes. */
|
||||
if (offset_in_buffer + 4 > (size_t)avail) {
|
||||
buffer = __archive_read_filter_ahead(filter,
|
||||
buffer = __archive_read_filter_ahead(f,
|
||||
offset_in_buffer + 4, &avail);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -178,7 +178,7 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
if (min > max_lookahead)
|
||||
return (0);
|
||||
|
||||
buffer = __archive_read_filter_ahead(filter,
|
||||
buffer = __archive_read_filter_ahead(f,
|
||||
min, &avail);
|
||||
if (buffer == NULL)
|
||||
return (0);
|
||||
@@ -206,16 +206,16 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self,
|
||||
* in case that's available.
|
||||
*/
|
||||
static int
|
||||
zstd_bidder_init(struct archive_read_filter *self)
|
||||
zstd_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = __archive_read_program(self, "zstd -d -qq");
|
||||
r = __archive_read_program(f, "zstd -d -qq");
|
||||
/* Note: We set the format here even if __archive_read_program()
|
||||
* above fails. We do, after all, know what the format is
|
||||
* even if we weren't able to read it. */
|
||||
self->code = ARCHIVE_FILTER_ZSTD;
|
||||
self->name = "zstd";
|
||||
f->code = ARCHIVE_FILTER_ZSTD;
|
||||
f->name = "zstd";
|
||||
return (r);
|
||||
}
|
||||
|
||||
@@ -231,15 +231,15 @@ zstd_reader_vtable = {
|
||||
* Initialize the filter object
|
||||
*/
|
||||
static int
|
||||
zstd_bidder_init(struct archive_read_filter *self)
|
||||
zstd_bidder_init(struct archive_read_filter *f)
|
||||
{
|
||||
struct zstd *zstd;
|
||||
size_t out_block_size = ZSTD_DStreamOutSize();
|
||||
void *out_block;
|
||||
ZSTD_DStream *dstream;
|
||||
|
||||
self->code = ARCHIVE_FILTER_ZSTD;
|
||||
self->name = "zstd";
|
||||
f->code = ARCHIVE_FILTER_ZSTD;
|
||||
f->name = "zstd";
|
||||
|
||||
zstd = calloc(1, sizeof(*zstd));
|
||||
out_block = malloc(out_block_size);
|
||||
@@ -249,17 +249,17 @@ zstd_bidder_init(struct archive_read_filter *self)
|
||||
free(out_block);
|
||||
free(zstd);
|
||||
ZSTD_freeDStream(dstream); /* supports free on NULL */
|
||||
archive_set_error(&self->archive->archive, ENOMEM,
|
||||
archive_set_error(&f->archive->archive, ENOMEM,
|
||||
"Can't allocate data for zstd decompression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
self->data = zstd;
|
||||
f->data = zstd;
|
||||
|
||||
zstd->out_block_size = out_block_size;
|
||||
zstd->out_block = out_block;
|
||||
zstd->dstream = dstream;
|
||||
self->vtable = &zstd_reader_vtable;
|
||||
f->vtable = &zstd_reader_vtable;
|
||||
|
||||
zstd->eof = 0;
|
||||
zstd->in_frame = 0;
|
||||
@@ -268,9 +268,9 @@ zstd_bidder_init(struct archive_read_filter *self)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
zstd_filter_read(struct archive_read_filter *self, const void **p)
|
||||
zstd_filter_read(struct archive_read_filter *f, const void **p)
|
||||
{
|
||||
struct zstd *zstd = self->data;
|
||||
struct zstd *zstd = f->data;
|
||||
size_t decompressed;
|
||||
ssize_t avail_in;
|
||||
ZSTD_outBuffer out;
|
||||
@@ -284,14 +284,14 @@ zstd_filter_read(struct archive_read_filter *self, const void **p)
|
||||
if (!zstd->in_frame) {
|
||||
ret = ZSTD_initDStream(zstd->dstream);
|
||||
if (ZSTD_isError(ret)) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Error initializing zstd decompressor: %s",
|
||||
ZSTD_getErrorName(ret));
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
}
|
||||
in.src = __archive_read_filter_ahead(self->upstream, 1,
|
||||
in.src = __archive_read_filter_ahead(f->upstream, 1,
|
||||
&avail_in);
|
||||
if (avail_in < 0) {
|
||||
return avail_in;
|
||||
@@ -302,7 +302,7 @@ zstd_filter_read(struct archive_read_filter *self, const void **p)
|
||||
zstd->eof = 1;
|
||||
break;
|
||||
} else {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Truncated zstd input");
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -315,7 +315,7 @@ zstd_filter_read(struct archive_read_filter *self, const void **p)
|
||||
ret = ZSTD_decompressStream(zstd->dstream, &out, &in);
|
||||
|
||||
if (ZSTD_isError(ret)) {
|
||||
archive_set_error(&self->archive->archive,
|
||||
archive_set_error(&f->archive->archive,
|
||||
ARCHIVE_ERRNO_MISC,
|
||||
"Zstd decompression failed: %s",
|
||||
ZSTD_getErrorName(ret));
|
||||
@@ -323,7 +323,7 @@ zstd_filter_read(struct archive_read_filter *self, const void **p)
|
||||
}
|
||||
|
||||
/* Decompressor made some progress */
|
||||
__archive_read_filter_consume(self->upstream, in.pos);
|
||||
__archive_read_filter_consume(f->upstream, in.pos);
|
||||
|
||||
/* ret guaranteed to be > 0 if frame isn't done yet */
|
||||
zstd->in_frame = (ret != 0);
|
||||
@@ -342,9 +342,9 @@ zstd_filter_read(struct archive_read_filter *self, const void **p)
|
||||
* Clean up the decompressor.
|
||||
*/
|
||||
static int
|
||||
zstd_filter_close(struct archive_read_filter *self)
|
||||
zstd_filter_close(struct archive_read_filter *f)
|
||||
{
|
||||
struct zstd *zstd = self->data;
|
||||
struct zstd *zstd = f->data;
|
||||
|
||||
ZSTD_freeDStream(zstd->dstream);
|
||||
free(zstd->out_block);
|
||||
|
||||
Reference in new issue
Block a user