[gs-commits] mupdf 1.16.1.54 x11: Avoid signedness issues when reading
[email protected] (Sebastian Rasmussen) Tue, 1 Oct 2019 14:55:50 +0000 (UTC)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 8b235020fbe99e722b2fd6bea1e770292814765d Author: Sebastian Rasmussen <[email protected]> Date: Fri Sep 27 17:18:34 2019 +0200 x11: Avoid signedness issues when reading from files/streams. diff --git a/platform/x11/curl_stream.c b/platform/x11/curl_stream.c index 4c1f699..b7a612e 100644 --- a/platform/x11/curl_stream.c +++ b/platform/x11/curl_stream.c @@ -361,7 +361,7 @@ static int cs_next(fz_context *ctx, fz_stream *stream, size_t len) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fetch data: %s", curl_easy_strerror(err)); } - if (read_point > state->content_length) + if ((size_t) read_point > state->content_length) { unlock(state); if (state->data_arrived == 0) diff --git a/platform/x11/prog_stream.c b/platform/x11/prog_stream.c index 3ed4dac..744a017 100644 --- a/platform/x11/prog_stream.c +++ b/platform/x11/prog_stream.c @@ -82,11 +82,10 @@ unlock(prog_state *state) } #endif -static int next_prog(fz_context *ctx, fz_stream *stm, size_t in_len) +static int next_prog(fz_context *ctx, fz_stream *stm, size_t len) { prog_state *ps = (prog_state *)stm->state; - int64_t len = in_len; - int64_t n; + size_t n; if (len > sizeof(ps->buffer)) len = sizeof(ps->buffer); @@ -95,15 +94,12 @@ static int next_prog(fz_context *ctx, fz_stream *stm, size_t in_len) lock(ps); if (ps->available < ps->length) { - if (stm->pos + len > ps->available) + if (stm->pos > ps->available || ps->available - stm->pos <= 0) { - len = ps->available - stm->pos; - if (len <= 0) - { - unlock(ps); - fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data yet"); - } + unlock(ps); + fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data yet"); } + len = ps->available - stm->pos; } unlock(ps); diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index 6f251ba..a902bd5 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -318,7 +318,7 @@ void wincopyfile(char *source, char *target) { FILE *in, *out; char buf[32 << 10]; - int n; + size_t n; in = fopen(source, "rb"); if (!in) http://git.ghostscript.com/?p=mupdf.git;a=commit;h=8b235020fbe99e722b2fd6bea1e770292814765d -- MuPDF library Artifex Software, Inc.