From dda017988150901dccd6b9dcb2823d7d8522433b Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 14 Aug 2015 19:37:59 +0100 Subject: Add fz_read_string function to read a null terminated string Use that within gproof. The existing use of fz_read_line was broken and was resulting in bad values for separations. --- source/fitz/stream-read.c | 17 +++++++++++++++++ source/gprf/gprf-doc.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index f85b7612..927addb0 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -291,3 +291,20 @@ int64_t fz_read_int64(fz_context *ctx, fz_stream *stm) { return (int64_t)fz_read int16_t fz_read_int16_le(fz_context *ctx, fz_stream *stm) { return (int16_t)fz_read_uint16_le(ctx, stm); } int32_t fz_read_int32_le(fz_context *ctx, fz_stream *stm) { return (int32_t)fz_read_uint32_le(ctx, stm); } int64_t fz_read_int64_le(fz_context *ctx, fz_stream *stm) { return (int64_t)fz_read_uint64_le(ctx, stm); } + +void fz_read_string(fz_context *ctx, fz_stream *stm, char *buffer, int len) +{ + int c; + do + { + if (len <= 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "Buffer overrun reading null terminated string"); + + c = fz_read_byte(ctx, stm); + if (c == EOF) + fz_throw(ctx, FZ_ERROR_GENERIC, "EOF reading null terminated string"); + *buffer++ = c; + len--; + } + while (c != 0); +} diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c index 02562ca7..d0551816 100644 --- a/source/gprf/gprf-doc.c +++ b/source/gprf/gprf-doc.c @@ -556,7 +556,7 @@ read_tiles(fz_context *ctx, gprf_page *page) char blatter[4096]; int32_t rgba = fz_read_int32_le(ctx, file); int32_t cmyk = fz_read_int32_le(ctx, file); - fz_read_line(ctx, file, blatter, sizeof(blatter)); + fz_read_string(ctx, file, blatter, sizeof(blatter)); fz_add_separation(ctx, page->separations, rgba, cmyk, blatter); } -- cgit v1.2.3