summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2015-07-30 17:27:23 +0100
committerChris Liddell <chris.liddell@artifex.com>2015-08-06 10:30:08 +0100
commit1fae53a708fca6c2ac0417bc23f5d095cc379250 (patch)
tree1ae77835a99385e70b009a574f80a47b104e7b89
parent6fb23cff7abcef91d03b43454d2d40d79c5e83da (diff)
downloadghostpdl-1fae53a708fca6c2ac0417bc23f5d095cc379250.tar.gz
Bug 696101: fix uses of the sfopen API.
The stream API in GS is defined as *always* opening files in binary mode, where applicable, so there is no need for the API clients to specify binary mode. This is previously been benign, and thus ignored, but reportedly ending up with a duplicate 'b' character in the mode causes a crash on Windows 10. No cluster differences.
-rw-r--r--base/fapiufst.c2
-rw-r--r--base/gsicc_manage.c6
-rw-r--r--base/lib.mak2
-rw-r--r--base/sfxcommon.c9
-rw-r--r--base/strmio.h3
-rw-r--r--devices/vector/gdevpdfu.c4
-rw-r--r--pcl/pl/pllfont.c6
-rw-r--r--psi/zfile.c3
8 files changed, 23 insertions, 12 deletions
diff --git a/base/fapiufst.c b/base/fapiufst.c
index 647b44f19..6c566f713 100644
--- a/base/fapiufst.c
+++ b/base/fapiufst.c
@@ -970,7 +970,7 @@ ufst_make_font_data(fapi_ufst_server * r, const char *font_file_path,
d->font_type = FC_FCO_TYPE;
}
else {
- stream *f = sfopen(font_file_path, "rb", r->mem);
+ stream *f = sfopen(font_file_path, "r", r->mem);
if (f == NULL) {
ufst_emprintf1(r->mem,
diff --git a/base/gsicc_manage.c b/base/gsicc_manage.c
index 065984e0e..f43177a6a 100644
--- a/base/gsicc_manage.c
+++ b/base/gsicc_manage.c
@@ -1055,7 +1055,7 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
strcat(buffer, pname);
/* Just to make sure we were null terminated */
buffer[namelen + dirlen] = '\0';
- str = sfopen(buffer, "rb", mem_gc);
+ str = sfopen(buffer, "r", mem_gc);
gs_free_object(mem_gc, buffer, "gsicc_open_search");
if (str != NULL) {
*strp = str;
@@ -1064,7 +1064,7 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "rb", mem_gc);
+ str = sfopen(pname, "r", mem_gc);
if (str != NULL) {
*strp = str;
return 0;
@@ -1080,7 +1080,7 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
strcat(buffer, pname);
/* Just to make sure we were null terminated */
buffer[namelen + strlen(DEFAULT_DIR_ICC)] = '\0';
- str = sfopen(buffer, "rb", mem_gc);
+ str = sfopen(buffer, "r", mem_gc);
gs_free_object(mem_gc, buffer, "gsicc_open_search");
if (str == NULL) {
gs_warn1("Could not find %s ",pname);
diff --git a/base/lib.mak b/base/lib.mak
index 54d354b33..8fabc177d 100644
--- a/base/lib.mak
+++ b/base/lib.mak
@@ -1442,7 +1442,7 @@ $(GLD)sfile.dev : $(LIB_MAK) $(ECHOGS_XE) $(sfile_) $(MAKEDIRS)
$(GLOBJ)sfxcommon.$(OBJ) : $(GLSRC)sfxcommon.c $(AK) $(stdio__h)\
$(memory__h) $(unistd__h) $(gsmemory_h) $(gp_h) $(stream_h)\
- $(gserrors_h) $(MAKEDIRS)
+ $(gserrors_h) $(assert__h) $(MAKEDIRS)
$(GLCC) $(GLO_)sfxcommon.$(OBJ) $(C_) $(GLSRC)sfxcommon.c
$(GLOBJ)sfxstdio.$(OBJ) : $(GLSRC)sfxstdio.c $(AK) $(stdio__h)\
diff --git a/base/sfxcommon.c b/base/sfxcommon.c
index cec104df8..5177a62b6 100644
--- a/base/sfxcommon.c
+++ b/base/sfxcommon.c
@@ -23,6 +23,7 @@
#include "gp.h"
#include "gserrors.h"
#include "stream.h"
+#include "assert_.h"
#define DEFAULT_BUFFER_SIZE 2048
const uint file_default_buffer_size = DEFAULT_BUFFER_SIZE;
@@ -66,6 +67,14 @@ file_open_stream(const char *fname, uint len, const char *file_access,
FILE *file;
char fmode[4]; /* r/w/a, [+], [b], null */
+#ifdef DEBUG
+ if (strlen(gp_fmode_binary_suffix) > 0) {
+ if (strchr(file_access, gp_fmode_binary_suffix[0]) != NULL)
+ dmprintf(mem, "\nWarning: spurious 'b' character in file access mode\n");
+ assert(strchr(file_access, gp_fmode_binary_suffix[0]) == NULL);
+ }
+#endif
+
if (!iodev)
iodev = iodev_default(mem);
code = file_prepare_stream(fname, len, file_access, buffer_size, ps, fmode, mem);
diff --git a/base/strmio.h b/base/strmio.h
index 9e0c77be9..78431c0fa 100644
--- a/base/strmio.h
+++ b/base/strmio.h
@@ -35,6 +35,9 @@ typedef struct gs_memory_s gs_memory_t;
* If iodev_default is the '%os' device, then the file will be on the host
* file system transparently to the caller. The "%os%" prefix can be used
* to explicilty access the host file system.
+ *
+ * NOTE: sfopen() always opens files in "binary" mode on systems where that
+ * is applicable - so callers should not do so themselves.
*/
stream * sfopen(const char *path, const char *mode, gs_memory_t *mem);
diff --git a/devices/vector/gdevpdfu.c b/devices/vector/gdevpdfu.c
index a577d08be..1767a26c5 100644
--- a/devices/vector/gdevpdfu.c
+++ b/devices/vector/gdevpdfu.c
@@ -168,7 +168,7 @@ copy_ps_file_stripping_all(stream *s, const char *fname, bool HaveTrueTypes)
int n, l = 0, m = sizeof(buf) - 1, outl = 0;
bool skipping = false;
- f = sfopen(fname, "rb", s->memory);
+ f = sfopen(fname, "r", s->memory);
if (f == NULL)
return_error(gs_error_undefinedfilename);
n = sfread(buf, 1, m, f);
@@ -244,7 +244,7 @@ copy_ps_file_strip_comments(stream *s, const char *fname, bool HaveTrueTypes)
int n, l = 0, m = sizeof(buf) - 1, outl = 0;
bool skipping = false;
- f = sfopen(fname, "rb", s->memory);
+ f = sfopen(fname, "r", s->memory);
if (f == NULL)
return_error(gs_error_undefinedfilename);
n = sfread(buf, 1, m, f);
diff --git a/pcl/pl/pllfont.c b/pcl/pl/pllfont.c
index 6076fabd9..f63f21e8b 100644
--- a/pcl/pl/pllfont.c
+++ b/pcl/pl/pllfont.c
@@ -683,7 +683,7 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t * mem,
/* null terminate the string */
tmp_path_copy[code] = '\0';
- in = sfopen(tmp_path_copy, "rb", mem);
+ in = sfopen(tmp_path_copy, "r", mem);
if (in == NULL) { /* shouldn't happen */
dmprintf1(mem, "cannot open file %s\n", tmp_path_copy);
continue;
@@ -719,7 +719,7 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t * mem,
tmp_path_copy);
}
/* reopen the file */
- in = sfopen(tmp_path_copy, "rb", mem);
+ in = sfopen(tmp_path_copy, "r", mem);
if (in == NULL)
return gs_throw1(0,
"An unrecoverable failure occurred while reading the resident font %s\n",
@@ -763,7 +763,7 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t * mem,
dmprintf2(mem,
"TrueType font %s in file %s not found in table\n",
buffer, tmp_path_copy);
- in = sfopen(tmp_path_copy, "rb", mem);
+ in = sfopen(tmp_path_copy, "r", mem);
code =
get_name_from_tt_file(in, mem, buffer, WINDOWSNAME);
sfclose(in);
diff --git a/psi/zfile.c b/psi/zfile.c
index 121e403e8..320ecd500 100644
--- a/psi/zfile.c
+++ b/psi/zfile.c
@@ -1034,7 +1034,7 @@ lib_file_open(gs_file_path_ptr lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx
bool starting_arg_file = (i_ctx_p == NULL) ? true : i_ctx_p->starting_arg_file;
bool search_with_no_combine = false;
bool search_with_combine = false;
- char fmode[4] = { 'r', 0, 0, 0 }; /* room for binary suffix */
+ char fmode[2] = { 'r', 0};
gx_io_device *iodev = iodev_default(mem);
gs_main_instance *minst = get_minst_from_memory(mem);
int code;
@@ -1043,7 +1043,6 @@ lib_file_open(gs_file_path_ptr lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx
if (iodev == 0)
iodev = (gx_io_device *)gx_io_device_table[0];
- strcat(fmode, gp_fmode_binary_suffix);
if (gp_file_name_is_absolute(fname, flen)) {
search_with_no_combine = true;
search_with_combine = false;