summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2022-03-22 15:01:28 +0000
committerChris Liddell <chris.liddell@artifex.com>2022-03-22 15:15:30 +0000
commit77325b545df906364819f71f1785c5b3b0d81536 (patch)
treec135fc63a781b9ce09c56ddf25d3a9e94d9abceb
parenta4b71ab352e9e9b3f849b3727944b6e8ec64e7b0 (diff)
downloadghostpdl-77325b545df906364819f71f1785c5b3b0d81536.tar.gz
pdfi: add warning for invalid BaseEncoding names
-rw-r--r--pdf/pdf_font.c62
-rw-r--r--pdf/pdf_warnings.h1
2 files changed, 44 insertions, 19 deletions
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index a34ef231b..fa716056d 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -1375,6 +1375,29 @@ int pdfi_free_font(pdf_obj *font)
return 0;
}
+static inline int pdfi_encoding_name_to_index(pdf_name *name)
+{
+ int ind = gs_error_undefined;
+ if (name->type == PDF_NAME) {
+ if (pdfi_name_is(name, "StandardEncoding")) {
+ ind = ENCODING_INDEX_STANDARD;
+ } else {
+ if (pdfi_name_is(name, "WinAnsiEncoding")){
+ ind = ENCODING_INDEX_WINANSI;
+ } else {
+ if (pdfi_name_is(name, "MacRomanEncoding")){
+ ind = ENCODING_INDEX_MACROMAN;
+ } else {
+ if (pdfi_name_is(name, "MacExpertEncoding")){
+ ind = ENCODING_INDEX_MACEXPERT;
+ }
+ }
+ }
+ }
+ }
+ return ind;
+}
+
/*
* Routine to fill in an array with each of the glyph names from a given
* 'standard' Encoding.
@@ -1390,25 +1413,13 @@ static int pdfi_build_Encoding(pdf_context *ctx, pdf_name *name, pdf_array *Enco
if (pdfi_array_size(Encoding) < 256)
return gs_note_error(gs_error_rangecheck);
- if (pdfi_name_is(name, "StandardEncoding")) {
- gs_encoding = ENCODING_INDEX_STANDARD;
- } else {
- if (pdfi_name_is(name, "WinAnsiEncoding")){
- gs_encoding = ENCODING_INDEX_WINANSI;
- } else {
- if (pdfi_name_is(name, "MacRomanEncoding")){
- gs_encoding = ENCODING_INDEX_MACROMAN;
- } else {
- if (pdfi_name_is(name, "MacExpertEncoding")){
- gs_encoding = ENCODING_INDEX_MACEXPERT;
- } else {
- return_error(gs_error_undefined);
- }
- }
- }
- }
- i = 0;
- for (i=0;i<256;i++) {
+ code = pdfi_encoding_name_to_index(name);
+ if (code < 0)
+ return code;
+ gs_encoding = (unsigned char)code;
+ code = 0;
+
+ for (i = 0;i<256;i++) {
temp = gs_c_known_encode(i, gs_encoding);
gs_c_glyph_name(temp, &str);
code = pdfi_name_alloc(ctx, (byte *)str.data, str.size, (pdf_obj **)&n);
@@ -1471,6 +1482,18 @@ int pdfi_create_Encoding(pdf_context *ctx, pdf_obj *pdf_Encoding, pdf_obj *font_
}
else {
code = pdfi_dict_get(ctx, (pdf_dict *)pdf_Encoding, "BaseEncoding", (pdf_obj **)&n);
+ if (code >= 0) {
+ if (pdfi_encoding_name_to_index(n) < 0) {
+ pdfi_set_warning(ctx, 0, NULL, W_PDF_INVALID_FONT_BASEENC, "pdfi_create_Encoding", NULL);
+ pdfi_countdown(n);
+ n = NULL;
+ code = gs_error_undefined;
+ }
+ else if (pdfi_name_is(n, "StandardEncoding") == true) {
+ pdfi_set_warning(ctx, 0, NULL, W_PDF_INVALID_FONT_BASEENC, "pdfi_create_Encoding", NULL);
+ }
+ }
+
if (code < 0) {
code = pdfi_name_alloc(ctx, (byte *)"StandardEncoding", 16, (pdf_obj **)&n);
if (code < 0) {
@@ -1480,6 +1503,7 @@ int pdfi_create_Encoding(pdf_context *ctx, pdf_obj *pdf_Encoding, pdf_obj *font_
}
pdfi_countup(n);
}
+
code = pdfi_build_Encoding(ctx, n, (pdf_array *)*Encoding);
if (code < 0) {
pdfi_countdown(*Encoding);
diff --git a/pdf/pdf_warnings.h b/pdf/pdf_warnings.h
index effd5d19d..21b2403f5 100644
--- a/pdf/pdf_warnings.h
+++ b/pdf/pdf_warnings.h
@@ -57,5 +57,6 @@ PARAM(W_PDF_BAD_MEDIABOX, "Couldn't retrieve MediaBox for page, using
PARAM(W_PDF_CA_OUTOFRANGE, "CA or ca value not in range 0.0 to 1.0, clamped to range."),
PARAM(W_PDF_INVALID_DEFAULTSPACE, "Invalid DefaultGray, DefaultRGB or DefaultCMYK space specified, ignored."),
PARAM(W_PDF_INVALID_DECRYPT_LEN, "Invalid /Length supplied in Encryption dictionary."),
+PARAM(W_PDF_INVALID_FONT_BASEENC, "Ignoring invalid BaseEncoding name in font"),
#undef PARAM