From 842d2c38e1785a318e596ad3fb852aaffa49d8a2 Mon Sep 17 00:00:00 2001 From: simon987 Date: Sat, 18 Jul 2020 18:48:53 -0400 Subject: [PATCH] Fix for simon987/sist2#85 --- libscan/arc/arc.c | 10 +++++++++- libscan/font/font.c | 6 +++++- libscan/util.h | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libscan/arc/arc.c b/libscan/arc/arc.c index 2a134ee..e23c67c 100644 --- a/libscan/arc/arc.c +++ b/libscan/arc/arc.c @@ -5,6 +5,8 @@ #include #include +#define MAX_SUBFILE_SIZE (long)(10000000000) + int should_parse_filtered_file(const char *filepath, int ext) { char tmp[PATH_MAX * 2]; @@ -34,7 +36,13 @@ int should_parse_filtered_file(const char *filepath, int ext) { } int arc_read(struct vfile *f, void *buf, size_t size) { - return archive_read_data(f->arc, buf, size); + size_t read = archive_read_data(f->arc, buf, size); + + if (read != size) { + return -1; + } + + return read; } int arc_open(vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse) { diff --git a/libscan/font/font.c b/libscan/font/font.c index 942aa57..85e5462 100644 --- a/libscan/font/font.c +++ b/libscan/font/font.c @@ -143,9 +143,13 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) { FT_Init_FreeType(&ft_lib); } - size_t buf_len; + size_t buf_len = 0; void * buf = read_all(f, &buf_len); + if (buf == NULL) { + return; + } + FT_Face face; FT_Error err = FT_New_Memory_Face(ft_lib, (unsigned char *) buf, buf_len, 0, &face); if (err != 0) { diff --git a/libscan/util.h b/libscan/util.h index 8d694df..87e46c1 100644 --- a/libscan/util.h +++ b/libscan/util.h @@ -308,7 +308,10 @@ static void *read_all(vfile_t *f, size_t *size) { void *buf = malloc(f->info.st_size); *size = f->read(f, buf, f->info.st_size); - //TODO: log + if (*size != f->info.st_size) { + free(buf); + return NULL; + } return buf; }