Fix for segfault in some comic files

This commit is contained in:
simon987 2021-06-07 09:01:06 -04:00
parent bcf3e4695b
commit ee9c98b488
2 changed files with 19 additions and 2 deletions

View File

@ -12,6 +12,10 @@ void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
struct archive_entry *entry = NULL; struct archive_entry *entry = NULL;
arc_data_t arc_data; arc_data_t arc_data;
if (ctx->tn_size <= 0) {
return;
}
int ret = arc_open(&arc_ctx, f, &a, &arc_data, TRUE); int ret = arc_open(&arc_ctx, f, &a, &arc_data, TRUE);
if (ret != ARCHIVE_OK) { if (ret != ARCHIVE_OK) {
CTX_LOG_ERRORF(f->filepath, "(cbr.c) [%d] %s", ret, archive_error_string(a)) CTX_LOG_ERRORF(f->filepath, "(cbr.c) [%d] %s", ret, archive_error_string(a))
@ -26,10 +30,10 @@ void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
const char *file_path = utf8_name == NULL ? archive_entry_pathname(entry) : utf8_name; const char *file_path = utf8_name == NULL ? archive_entry_pathname(entry) : utf8_name;
char *p = strrchr(file_path, '.'); char *p = strrchr(file_path, '.');
if (p != NULL && strcmp(p, ".png") == 0 || strcmp(p, ".jpg") == 0 || strcmp(p, ".jpeg") == 0) { if (p != NULL && (strcmp(p, ".png") == 0 || strcmp(p, ".jpg") == 0 || strcmp(p, ".jpeg") == 0)) {
size_t entry_size = archive_entry_size(entry); size_t entry_size = archive_entry_size(entry);
void *buf = malloc(entry_size); void *buf = malloc(entry_size);
int read = archive_read_data(a, buf, entry_size); size_t read = archive_read_data(a, buf, entry_size);
if (read != entry_size) { if (read != entry_size) {
const char *err_str = archive_error_string(a); const char *err_str = archive_error_string(a);

View File

@ -291,6 +291,19 @@ TEST(Comic, ComicCbr) {
cleanup(&doc, &f); cleanup(&doc, &f);
} }
TEST(Comic, ComicIssue160) {
vfile_t f;
document_t doc;
load_doc_file("libscan-test-files/test_files/ebook/comic-segfault-issue-160.cbr", &f, &doc);
int tn_size_saved = comic_ctx.tn_size;
comic_ctx.tn_size = 0;
parse_comic(&comic_ctx, &f, &doc);
comic_ctx.tn_size = tn_size_saved;
cleanup(&doc, &f);
}
TEST(Comic, ComicCbrAsIs) { TEST(Comic, ComicCbrAsIs) {
vfile_t f; vfile_t f;
document_t doc; document_t doc;