From e344c7440c90ecfdbbbe8caf19fdc2084c978b84 Mon Sep 17 00:00:00 2001 From: simon987 Date: Fri, 14 Aug 2020 22:09:07 -0400 Subject: [PATCH] Gracefully handle archive errors in comic.c --- libscan/comic/comic.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libscan/comic/comic.c b/libscan/comic/comic.c index a202e63..9e0ffee 100644 --- a/libscan/comic/comic.c +++ b/libscan/comic/comic.c @@ -28,7 +28,16 @@ void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) { if (p != NULL && strcmp(p, ".png") == 0 || strcmp(p, ".jpg") == 0 || strcmp(p, ".jpeg") == 0) { size_t entry_size = archive_entry_size(entry); void* buf = malloc(entry_size); - archive_read_data(a, buf, entry_size); + int read = archive_read_data(a, buf, entry_size); + + if (read != entry_size) { + const char* err_str = archive_error_string(a); + if (err_str) { + CTX_LOG_ERRORF("comic.c", "Error while reading entry: %s", err_str) + } + free(buf); + break; + } ret = store_image_thumbnail((scan_media_ctx_t*)ctx, buf, entry_size, doc, file_path); free(buf);