[gs-commits] mupdf 1.16.1.56 Fix signedness issues in .tar/.zip parser
[email protected] (Sebastian Rasmussen) Tue, 1 Oct 2019 14:55:50 +0000 (UTC)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit f7b5ebb1731a0c747bd28eb6c419d59fbe69504f Author: Sebastian Rasmussen <[email protected]> Date: Fri Sep 27 16:52:38 2019 +0200 Fix signedness issues in .tar/.zip parsers. diff --git a/source/fitz/untar.c b/source/fitz/untar.c index c156ac9..9278815 100644 --- a/source/fitz/untar.c +++ b/source/fitz/untar.c @@ -2,10 +2,7 @@ #include "fitz-imp.h" #include <string.h> - -#if !defined (INT32_MAX) -#define INT32_MAX 2147483647L -#endif +#include <limits.h> typedef struct tar_entry_s tar_entry; typedef struct fz_tar_archive_s fz_tar_archive; @@ -13,7 +10,8 @@ typedef struct fz_tar_archive_s fz_tar_archive; struct tar_entry_s { char *name; - int64_t offset, size; + int64_t offset; + int size; }; struct fz_tar_archive_s @@ -82,8 +80,8 @@ static void ensure_tar_entries(fz_context *ctx, fz_tar_archive *tar) fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in tar entry size"); octsize[nelem(octsize) - 1] = '\0'; size = otoi(octsize); - if (size > INT32_MAX) - fz_throw(ctx, FZ_ERROR_GENERIC, "tar archive entry larger than 2 GB"); + if (size > INT_MAX) + fz_throw(ctx, FZ_ERROR_GENERIC, "tar archive entry too large"); fz_seek(ctx, file, 20, 1); typeflag = fz_read_byte(ctx, file); @@ -145,7 +143,7 @@ static fz_buffer *read_tar_entry(fz_context *ctx, fz_archive *arch, const char * { fz_seek(ctx, file, ent->offset + 512, 0); ubuf->len = fz_read(ctx, file, ubuf->data, ent->size); - if (ubuf->len != ent->size) + if (ubuf->len != (size_t)ent->size) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read entire archive entry"); } fz_catch(ctx) diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c index b3b1c35..adfc84f 100644 --- a/source/fitz/unzip.c +++ b/source/fitz/unzip.c @@ -2,6 +2,7 @@ #include "fitz-imp.h" #include <string.h> +#include <limits.h> #include <zlib.h> @@ -33,7 +34,7 @@ struct fz_zip_archive_s { fz_archive super; - uint64_t count; + int count; zip_entry *entries; }; @@ -118,7 +119,9 @@ static void read_zip_dir_imp(fz_context *ctx, fz_zip_archive *zip, int64_t start fz_try(ctx) { - for (i = 0; i < count; i++) + if (count > INT_MAX) + count = INT_MAX; + for (i = 0; i < (int)count; i++) { sig = fz_read_uint32_le(ctx, file); if (sig != ZIP_CENTRAL_DIRECTORY_SIG) @@ -303,7 +306,7 @@ static fz_buffer *read_zip_entry(fz_context *ctx, fz_archive *arch, const char * int method; z_stream z; int code; - int len; + uint64_t len; zip_entry *ent; fz_var(cbuf); http://git.ghostscript.com/?p=mupdf.git;a=commit;h=f7b5ebb1731a0c747bd28eb6c419d59fbe69504f -- MuPDF library Artifex Software, Inc.