From a412aad1c19ef3bcf286a465f615bb5e3a9ad526 Mon Sep 17 00:00:00 2001 From: Ken Sharp Date: Fri, 17 Feb 2023 09:14:26 +0000 Subject: GhostPDF - Dest names need not be C strings Test file supplied in confidence by customer 820 The file has an Outlines entry where the /Dest has a name which is in UTF16-BE. The code was dealing with strings as C strings, which fails here because UTF16-BE text can contain NULLs. In this commit; alter the comparison to use memcmp instead of strncmp and pass the length of the PDF string as a parameter so that we do not need to use strlen. --- pdf/pdf_mark.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pdf') diff --git a/pdf/pdf_mark.c b/pdf/pdf_mark.c index 41f3f54f2..d39594681 100644 --- a/pdf/pdf_mark.c +++ b/pdf/pdf_mark.c @@ -753,9 +753,9 @@ error: return code; } -static int pdfi_get_name_from_node(pdf_context *ctx, pdf_dict *node, char *str, pdf_obj **Name, bool is_root) +static int pdfi_get_name_from_node(pdf_context *ctx, pdf_dict *node, char *str, int len, pdf_obj **Name, bool is_root) { - int i = 0, len = strlen(str), code = 0; + int i = 0, code = 0; pdf_string *StrKey = NULL; pdf_array *NamesArray = NULL; pdf_dict *Kid = NULL; @@ -798,7 +798,7 @@ static int pdfi_get_name_from_node(pdf_context *ctx, pdf_dict *node, char *str, if (code < 0) goto error; - if (StrKey->length == len && strncmp((const char *)StrKey->data, str, len) == 0) { + if (StrKey->length == len && memcmp((const char *)StrKey->data, str, len) == 0) { code = pdfi_array_get(ctx, NamesArray, (i * 2) + 1, (pdf_obj **)Name); goto error; } @@ -819,7 +819,7 @@ static int pdfi_get_name_from_node(pdf_context *ctx, pdf_dict *node, char *str, if (code < 0) goto error; - code = pdfi_get_name_from_node(ctx, Kid, str, Name, false); + code = pdfi_get_name_from_node(ctx, Kid, str, len, Name, false); pdfi_countdown(Kid); Kid = NULL; if (code == 0) @@ -873,7 +873,7 @@ static int pdfi_get_named_dest(pdf_context *ctx, pdf_obj *Named, pdf_obj **Dest) str[len] = 0; } - code = pdfi_get_name_from_node(ctx, Dests, str, Dest, true); + code = pdfi_get_name_from_node(ctx, Dests, str, len, Dest, true); error: if (pdfi_type_of(Named) == PDF_NAME) -- cgit v1.2.1