diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2016-09-12 17:50:45 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2016-09-12 17:55:31 +0100 |
commit | d1ef839f4c41645cdba9524d0062c5aa2c533818 (patch) | |
tree | 8d5b73b33e1d237eb0f9aef55ec2dba4512969aa | |
parent | efdd255f800b4f1bc22e81d686691aa1b48f785f (diff) | |
download | ghostpdl-d1ef839f4c41645cdba9524d0062c5aa2c533818.tar.gz |
Bug 697110: Ensure stream 'file_limit' is correct
Follow-on from commit 4b101952d81a5899972f81f7b18ef3becd5bd45e
There are several places that set, and check the value of file_limit for
streams. Ensure they all use the requisite value whether the gs_offset_t is
64 bit (normal) or 32 bit (abnormal).
To make it easier, and more consistent, pull the logic out into a macro.
-rw-r--r-- | base/gsioram.c | 6 | ||||
-rw-r--r-- | base/gsiorom.c | 4 | ||||
-rw-r--r-- | base/sfxfd.c | 8 | ||||
-rw-r--r-- | base/sfxstdio.c | 6 | ||||
-rw-r--r-- | base/stream.h | 2 | ||||
-rw-r--r-- | psi/zfrsd.c | 2 | ||||
-rw-r--r-- | psi/ziodevsc.c | 6 |
7 files changed, 18 insertions, 16 deletions
diff --git a/base/gsioram.c b/base/gsioram.c index 9bf57c038..44805ac14 100644 --- a/base/gsioram.c +++ b/base/gsioram.c @@ -207,7 +207,7 @@ sread_ram(register stream * s, ramhandle * file, byte * buf, uint len) s->file_modes = s->modes; s->file_offset = 0; /* XXX get a more sensible number from the fs? */ - s->file_limit = max_long; + s->file_limit = S_FILE_LIMIT_MAX; } /* Procedures for reading from a file */ @@ -268,7 +268,7 @@ s_ram_read_process(stream_state * st, stream_cursor_read * ignore_pr, int status = 1; int count; - if (s->file_limit < max_long) { + if (s->file_limit < S_FILE_LIMIT_MAX) { long limit_count = s->file_offset + s->file_limit - ramfile_tell(file); @@ -298,7 +298,7 @@ swrite_ram(register stream * s, ramhandle * file, byte * buf, uint len) s->file = (FILE*)file; s->file_modes = s->modes; s->file_offset = 0; /* in case we switch to reading later */ - s->file_limit = max_long; /* ibid. */ + s->file_limit = S_FILE_LIMIT_MAX; } /* Initialize for appending to a file. */ diff --git a/base/gsiorom.c b/base/gsiorom.c index 92864b25b..a897d72e5 100644 --- a/base/gsiorom.c +++ b/base/gsiorom.c @@ -114,7 +114,7 @@ sread_block(register stream *s, const byte *ptr, uint len, const uint32_t *node s->file = (FILE *)node; /* convenient place to put it for %rom% files */ s->file_modes = s->modes; s->file_offset = 0; - s->file_limit = max_long; + s->file_limit = S_FILE_LIMIT_MAX; } /* Return the number of available bytes */ @@ -193,7 +193,7 @@ s_block_read_process(stream_state * st, stream_cursor_read * ignore_pr, if (s->position + (s->cursor.r.limit - s->cbuf + 1) >= filelen || block_data == NULL) return EOFC; /* at EOF */ - if (s->file_limit < max_long) { + if (s->file_limit < S_FILE_LIMIT_MAX) { /* Adjust count for subfile limit */ uint32_t limit_count = s->file_offset + s->file_limit - s->position; diff --git a/base/sfxfd.c b/base/sfxfd.c index 185c0753b..e0bb3f878 100644 --- a/base/sfxfd.c +++ b/base/sfxfd.c @@ -128,7 +128,7 @@ sread_fileno(register stream * s, FILE * file, byte * buf, uint len) s->file = file; s->file_modes = s->modes; s->file_offset = 0; - s->file_limit = max_long; + s->file_limit = S_FILE_LIMIT_MAX; } /* Confine reading to a subfile. This is primarily for reusable streams. */ @@ -141,7 +141,7 @@ int sread_subfile(stream *s, gs_offset_t start, gs_offset_t length) { if (s->file == 0 || s->modes != s_mode_read + s_mode_seek || - s->file_offset != 0 || s->file_limit != max_long || + s->file_offset != 0 || s->file_limit != S_FILE_LIMIT_MAX || ((s->position < start || s->position > start + length) && sseek(s, start) < 0) ) @@ -226,7 +226,7 @@ s_fileno_read_process(stream_state * st, stream_cursor_read * ignore_pr, again: max_count = pw->limit - pw->ptr; status = 1; - if (s->file_limit < max_long) { + if (s->file_limit < S_FILE_LIMIT_MAX) { gs_offset_t limit_count = s->file_offset + s->file_limit - ltell(fd); if (max_count > limit_count) @@ -269,7 +269,7 @@ swrite_fileno(register stream * s, FILE * file, byte * buf, uint len) s->file = file; s->file_modes = s->modes; s->file_offset = 0; /* in case we switch to reading later */ - s->file_limit = max_long; /* ibid. */ + s->file_limit = S_FILE_LIMIT_MAX; } /* Initialize for appending to an OS file. */ void diff --git a/base/sfxstdio.c b/base/sfxstdio.c index d6e48f448..0d901107d 100644 --- a/base/sfxstdio.c +++ b/base/sfxstdio.c @@ -79,7 +79,7 @@ sread_subfile(stream *s, gs_offset_t start, gs_offset_t length) { if (s->file == 0 || s->modes != s_mode_read + s_mode_seek || s->file_offset != 0 || - s->file_limit != (sizeof(gs_offset_t) > 4 ? max_int64_t : max_long) || + s->file_limit != S_FILE_LIMIT_MAX || ((s->position < start || s->position > start + length) && sseek(s, start) < 0) ) return ERRC; @@ -161,7 +161,7 @@ s_file_read_process(stream_state * st, stream_cursor_read * ignore_pr, int status = 1; int count; - if (s->file_limit < max_long) { + if (s->file_limit < S_FILE_LIMIT_MAX) { gs_offset_t limit_count = s->file_offset + s->file_limit - gp_ftell_64(file); if (max_count > limit_count) @@ -193,7 +193,7 @@ swrite_file(register stream * s, FILE * file, byte * buf, uint len) s->file = file; s->file_modes = s->modes; s->file_offset = 0; /* in case we switch to reading later */ - s->file_limit = (sizeof(gs_offset_t) > 4 ? max_int64_t : max_long); /* ibid. */ + s->file_limit = S_FILE_LIMIT_MAX; } /* Initialize for appending to an OS file. */ void diff --git a/base/stream.h b/base/stream.h index 4097d20c2..d13a23605 100644 --- a/base/stream.h +++ b/base/stream.h @@ -190,6 +190,8 @@ extern_st(st_stream); stream_enum_ptrs, stream_reloc_ptrs, stream_finalize) #define STREAM_NUM_PTRS 6 +#define S_FILE_LIMIT_MAX (sizeof(gs_offset_t) > 4 ? max_int64_t : max_long) + /* Initialize the checking IDs of a stream. */ #define s_init_ids(s) ((s)->read_id = (s)->write_id = 1) #define s_init_read_id(s) ((s)->read_id = 1, (s)->write_id = 0) diff --git a/psi/zfrsd.c b/psi/zfrsd.c index 69aa0cc95..191107d8a 100644 --- a/psi/zfrsd.c +++ b/psi/zfrsd.c @@ -370,7 +370,7 @@ make_aos(i_ctx_t *i_ctx_p, os_ptr op, int blk_sz, int blk_sz_last, uint file_sz) s_std_init(s, buf, aos_buf_size, &s_aos_procs, s_mode_read + s_mode_seek); s->state = (stream_state *)ss; s->file_offset = 0; - s->file_limit = max_long; + s->file_limit = S_FILE_LIMIT_MAX; s->close_at_eod = false; s->read_id = 1; make_stream_file(op, s, "r"); diff --git a/psi/ziodevsc.c b/psi/ziodevsc.c index 835848f29..6dd744f13 100644 --- a/psi/ziodevsc.c +++ b/psi/ziodevsc.c @@ -143,7 +143,7 @@ stdin_open(gx_io_device * iodev, const char *access, stream ** ps, s->file = 0; s->file_modes = s->modes; s->file_offset = 0; - s->file_limit = max_long; + s->file_limit = S_FILE_LIMIT_MAX; s->save_close = s_std_null; make_file(&ref_stdin, a_readonly | avm_system, s->read_id, s); *ps = s; @@ -220,7 +220,7 @@ stdout_open(gx_io_device * iodev, const char *access, stream ** ps, s->file = 0; s->file_modes = s->modes; s->file_offset = 0; /* in case we switch to reading later */ - s->file_limit = max_long; /* ibid. */ + s->file_limit = S_FILE_LIMIT_MAX; s->save_close = s->procs.flush; make_file(&ref_stdout, a_write | avm_system, s->write_id, s); *ps = s; @@ -291,7 +291,7 @@ stderr_open(gx_io_device * iodev, const char *access, stream ** ps, s->file = 0; s->file_modes = s->modes; s->file_offset = 0; /* in case we switch to reading later */ - s->file_limit = max_long; /* ibid. */ + s->file_limit = S_FILE_LIMIT_MAX; s->save_close = s->procs.flush; make_file(&ref_stderr, a_write | avm_system, s->write_id, s); *ps = s; |