This commit is contained in:
simon987 2021-02-27 15:23:56 -05:00
parent 49d4f1ae48
commit 8212dd4b23
4 changed files with 31 additions and 9 deletions

View File

@ -47,19 +47,25 @@ int arc_read(struct vfile *f, void *buf, size_t size) {
return read;
}
int arc_open(vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse) {
int arc_open(scan_arc_ctx_t *ctx, vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse) {
arc_data->f = f;
if (f->is_fs_file) {
*a = archive_read_new();
archive_read_support_filter_all(*a);
archive_read_support_format_all(*a);
if (ctx->passphrase[0] != 0) {
archive_read_add_passphrase(*a, ctx->passphrase);
}
return archive_read_open_filename(*a, f->filepath, ARC_BUF_SIZE);
} else if (allow_recurse) {
*a = archive_read_new();
archive_read_support_filter_all(*a);
archive_read_support_format_all(*a);
if (ctx->passphrase[0] != 0) {
archive_read_add_passphrase(*a, ctx->passphrase);
}
return archive_read_open(
*a, arc_data,
@ -80,7 +86,7 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc) {
arc_data_t arc_data;
arc_data.f = f;
int ret = arc_open(f, &a, &arc_data, ctx->mode == ARC_MODE_RECURSE);
int ret = arc_open(ctx, f, &a, &arc_data, ctx->mode == ARC_MODE_RECURSE);
if (ret == ARC_SKIPPED) {
return SCAN_OK;
}

View File

@ -20,6 +20,7 @@ typedef struct {
log_callback_t log;
logf_callback_t logf;
store_callback_t store;
char passphrase[1024];
} scan_arc_ctx_t;
#define ARC_BUF_SIZE 8192
@ -56,7 +57,7 @@ static int vfile_close_callback(struct archive *a, void *user_data) {
return ARCHIVE_OK;
}
int arc_open(vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse);
int arc_open(scan_arc_ctx_t *ctx, vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse);
int should_parse_filtered_file(const char *filepath, int ext);

View File

@ -5,13 +5,14 @@
#include <stdlib.h>
#include <archive.h>
static scan_arc_ctx_t arc_ctx = (scan_arc_ctx_t) {.passphrase = {0,}};
void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
struct archive *a = NULL;
struct archive_entry *entry = NULL;
arc_data_t arc_data;
int ret = arc_open(f, &a, &arc_data, TRUE);
int ret = arc_open(&arc_ctx, f, &a, &arc_data, TRUE);
if (ret != ARCHIVE_OK) {
CTX_LOG_ERRORF(f->filepath, "(cbr.c) [%d] %s", ret, archive_error_string(a))
archive_read_free(a);

View File

@ -595,6 +595,20 @@ TEST(Arc, Utf8) {
cleanup(&doc, &f);
}
TEST(Arc, EncryptedZip) {
vfile_t f;
document_t doc;
load_doc_file("libscan-test-files/test_files/arc/encrypted.zip", &f, &doc);
size_t size_before = store_size;
parse_archive(&arc_recurse_media_ctx, &f, &doc);
ASSERT_NE(size_before, store_size);
cleanup(&doc, &f);
}
/* RAW */
TEST(RAW, Panasonic) {
vfile_t f;