summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2023-01-11 12:26:40 +0000
committerChris Liddell <chris.liddell@artifex.com>2023-02-27 14:40:12 +0000
commit5fd346cfbf6ec6ad3972fd33b888525edb241d02 (patch)
tree61658481089d192bedb851eb9c896bec82d0fed9 /pdf
parentcc86ef9a49487d2a71d0f49b201853a43038d34c (diff)
downloadghostpdl-5fd346cfbf6ec6ad3972fd33b888525edb241d02.tar.gz
Revise how the pdfi fontmap code checks a font file exists
Originally, the code assumed that any extra font files were on disk files, and did not account for the possibility that they might be in the romfs (or potentially access via the Postscript %os% or similer i/o device). This revises it to cope with such cases. Stems from Bug 706267.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdf_file.c42
-rw-r--r--pdf/pdf_file.h4
-rw-r--r--pdf/pdf_fmap.c11
3 files changed, 40 insertions, 17 deletions
diff --git a/pdf/pdf_file.c b/pdf/pdf_file.c
index bbd408afa..c1423863f 100644
--- a/pdf/pdf_file.c
+++ b/pdf/pdf_file.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018-2022 Artifex Software, Inc.
+/* Copyright (C) 2018-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -1779,10 +1779,10 @@ retry:
return code;
}
-int pdfi_open_resource_file(pdf_context *ctx, const char *fname, const int fnamelen, stream **s)
+static int pdfi_open_resource_file_inner(pdf_context *ctx, const char *fname, const int fnamelen, stream **s)
{
int code = 0;
- if (fname == NULL || fnamelen == 0)
+ if (fname == NULL || fnamelen == 0 || fnamelen >= gp_file_name_sizeof)
*s = NULL;
else if (gp_file_name_is_absolute(fname, fnamelen) || fname[0] == '%') {
/* If it's an absolute path or an explicit PS style device, just try to open it */
@@ -1846,13 +1846,28 @@ retry:
return 0;
}
-int pdfi_open_font_file(pdf_context *ctx, const char *fname, const int fnamelen, stream **s)
+int pdfi_open_resource_file(pdf_context *ctx, const char *fname, const int fnamelen, stream **s)
+{
+ return pdfi_open_resource_file_inner(ctx, fname, fnamelen, s);
+}
+
+bool pdfi_resource_file_exists(pdf_context *ctx, const char *fname, const int fnamelen)
+{
+ stream *s = NULL;
+ int code = pdfi_open_resource_file_inner(ctx, fname, fnamelen, &s);
+ if (s)
+ sclose(s);
+
+ return (code >= 0);
+}
+
+static int pdfi_open_font_file_inner(pdf_context *ctx, const char *fname, const int fnamelen, stream **s)
{
int code = 0;
const char *fontdirstr = "Font/";
const int fontdirstrlen = strlen(fontdirstr);
- if (fname == NULL || fnamelen == 0)
+ if (fname == NULL || fnamelen == 0 || fnamelen >= gp_file_name_sizeof)
*s = NULL;
else if (gp_file_name_is_absolute(fname, fnamelen) || fname[0] == '%') {
/* If it's an absolute path or an explicit PS style device, just try to open it */
@@ -1910,7 +1925,22 @@ int pdfi_open_font_file(pdf_context *ctx, const char *fname, const int fnamelen,
}
}
if (*s == NULL)
- return pdfi_open_resource_file(ctx, fname, fnamelen, s);
+ return pdfi_open_resource_file_inner(ctx, fname, fnamelen, s);
return 0;
}
+
+int pdfi_open_font_file(pdf_context *ctx, const char *fname, const int fnamelen, stream **s)
+{
+ return pdfi_open_font_file_inner(ctx, fname, fnamelen, s);
+}
+
+bool pdfi_font_file_exists(pdf_context *ctx, const char *fname, const int fnamelen)
+{
+ stream *s = NULL;
+ int code = pdfi_open_font_file_inner(ctx, fname, fnamelen, &s);
+ if (s)
+ sclose(s);
+
+ return (code >= 0);
+}
diff --git a/pdf/pdf_file.h b/pdf/pdf_file.h
index d1fafbb62..620a1b763 100644
--- a/pdf/pdf_file.h
+++ b/pdf/pdf_file.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018-2022 Artifex Software, Inc.
+/* Copyright (C) 2018-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -109,6 +109,8 @@ int pdfi_apply_SHA256_filter(pdf_context *ctx, pdf_c_stream *source, pdf_c_strea
#endif
int pdfi_open_resource_file(pdf_context *ctx, const char *fname, const int fnamelen, stream **s);
+bool pdfi_resource_file_exists(pdf_context *ctx, const char *fname, const int fnamelen);
int pdfi_open_font_file(pdf_context *ctx, const char *fname, const int fnamelen, stream **s);
+bool pdfi_font_file_exists(pdf_context *ctx, const char *fname, const int fnamelen);
#endif /* PDF_FILES */
diff --git a/pdf/pdf_fmap.c b/pdf/pdf_fmap.c
index eded1165b..70ef8f11a 100644
--- a/pdf/pdf_fmap.c
+++ b/pdf/pdf_fmap.c
@@ -41,16 +41,7 @@ pdfi_custom_fmap_entry pdfi_custom_fmap_entries[] =
static inline bool pdfi_fmap_file_exists(pdf_context *ctx, pdf_string *fname)
{
- char nm[gp_file_name_sizeof];
- struct stat buf;
- int code = gs_error_invalidfileaccess;
-
- if (fname->length < gp_file_name_sizeof) {
- memcpy(nm, fname->data, fname->length);
- nm[fname->length] = '\0';
- code = gp_stat(ctx->memory, (const char *)nm, &buf);
- }
- return code >= 0;
+ return pdfi_font_file_exists(ctx, (const char *)fname->data, fname->length);
}
static int