diff --git a/libscan/arc/arc.c b/libscan/arc/arc.c index e23c67c..eeb0d07 100644 --- a/libscan/arc/arc.c +++ b/libscan/arc/arc.c @@ -39,6 +39,10 @@ int arc_read(struct vfile *f, void *buf, size_t size) { size_t read = archive_read_data(f->arc, buf, size); if (read != size) { + const char* error_str = archive_error_string(f->arc); + if (error_str != NULL) { + f->logf(f->filepath, LEVEL_ERROR, "Error reading archive file: %s", error_str); + } return -1; } @@ -119,6 +123,8 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc) { sub_job->vfile.arc = a; sub_job->vfile.filepath = sub_job->filepath; sub_job->vfile.is_fs_file = FALSE; + sub_job->vfile.log = ctx->log; + sub_job->vfile.logf = ctx->logf; memcpy(sub_job->parent, doc->uuid, sizeof(uuid_t)); while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { diff --git a/libscan/ebook/ebook.c b/libscan/ebook/ebook.c index dd8a831..9f9edee 100644 --- a/libscan/ebook/ebook.c +++ b/libscan/ebook/ebook.c @@ -397,6 +397,11 @@ void parse_ebook_mem(scan_ebook_ctx_t *ctx, void* buf, size_t buf_len, const cha void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, document_t *doc) { size_t buf_len; void * buf = read_all(f, &buf_len); + if (buf == NULL) { + CTX_LOG_ERROR(f->filepath, "read_all() failed") + return; + } + parse_ebook_mem(ctx, buf, buf_len, mime_str, doc); free(buf); } diff --git a/libscan/font/font.c b/libscan/font/font.c index 85e5462..ce2203f 100644 --- a/libscan/font/font.c +++ b/libscan/font/font.c @@ -145,8 +145,8 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) { size_t buf_len = 0; void * buf = read_all(f, &buf_len); - if (buf == NULL) { + CTX_LOG_ERROR(f->filepath, "read_all() failed") return; } diff --git a/libscan/mobi/scan_mobi.c b/libscan/mobi/scan_mobi.c index 87a4bc5..40d3de2 100644 --- a/libscan/mobi/scan_mobi.c +++ b/libscan/mobi/scan_mobi.c @@ -14,6 +14,11 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) { size_t buf_len; char* buf = read_all(f, &buf_len); + if (buf == NULL) { + mobi_free(m); + CTX_LOG_ERROR(f->filepath, "read_all() failed") + return; + } FILE *file = fmemopen(buf, buf_len, "rb"); if (file == NULL) { diff --git a/libscan/ooxml/ooxml.c b/libscan/ooxml/ooxml.c index 4321b41..f35673c 100644 --- a/libscan/ooxml/ooxml.c +++ b/libscan/ooxml/ooxml.c @@ -166,6 +166,10 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) { size_t buf_len; void *buf = read_all(f, &buf_len); + if (buf == NULL) { + CTX_LOG_ERROR(f->filepath, "read_all() failed") + return; + } struct archive *a = archive_read_new(); archive_read_support_format_zip(a); diff --git a/libscan/raw/raw.c b/libscan/raw/raw.c index 83d2dca..dd775a5 100644 --- a/libscan/raw/raw.c +++ b/libscan/raw/raw.c @@ -91,6 +91,10 @@ void parse_raw(scan_raw_ctx_t *ctx, vfile_t *f, document_t *doc) { size_t buf_len = 0; void *buf = read_all(f, &buf_len); + if (buf == NULL) { + CTX_LOG_ERROR(f->filepath, "read_all() failed") + return; + } int ret = libraw_open_buffer(libraw_lib, buf, buf_len); if (ret != 0) { diff --git a/libscan/scan.h b/libscan/scan.h index c05a334..fcf31f6 100644 --- a/libscan/scan.h +++ b/libscan/scan.h @@ -23,6 +23,9 @@ #define IS_META_LONG(key) (key & META_LONG_MASK) == META_LONG_MASK #define IS_META_STR(meta) (meta->key & META_STR_MASK) == META_STR_MASK +typedef void (*store_callback_t)(char *key, size_t key_len, char *buf, size_t buf_len); +typedef void (*logf_callback_t)(const char *filepath, int level, char *format, ...); +typedef void (*log_callback_t)(const char *filepath, int level, char *str); typedef int scan_code_t; #define SCAN_OK (scan_code_t) 0 @@ -130,6 +133,8 @@ typedef struct vfile { seek_func_t seek; close_func_t close; reset_func_t reset; + log_callback_t log; + logf_callback_t logf; } vfile_t; typedef struct parse_job_t { @@ -153,9 +158,6 @@ typedef struct parse_job_t { #include "util.h" -typedef void (*store_callback_t)(char *key, size_t key_len, char *buf, size_t buf_len); -typedef void (*logf_callback_t)(const char *filepath, int level, char *format, ...); -typedef void (*log_callback_t)(const char *filepath, int level, char *str); typedef void (*parse_callback_t)(parse_job_t *job); #endif