diff options
author | Nancy Durgin <nancy.durgin@artifex.com> | 2021-05-05 12:55:15 -0700 |
---|---|---|
committer | Nancy Durgin <nancy.durgin@artifex.com> | 2021-05-05 13:59:37 -0700 |
commit | 7d7c7fb08cd61f2787839d111494460815c17b9f (patch) | |
tree | c7bfd74520a744a8a9d739f111fff2293144daac | |
parent | bf8dd4fc9b6ce7f2a50c15f4fdad57c862fbc94c (diff) | |
download | ghostpdl-7d7c7fb08cd61f2787839d111494460815c17b9f.tar.gz |
Fix to decrypt hexstrings
pdfi_read_hexstring() didn't check for whether it needed to decrypt
the string. I just grabbed the similar code from pdfi_read_string(), so
hopefully this is correct.
I was fixing a bug where the Info wasn't displaying correctly with
-DPDFINFO, for example on file tests_private/pdf/PDF_1.7_FTS/fts_03_0301.pdf
Also disable string decryption while interpreting c_string. This is
needed by annotations that construct hexstrings and send them through
the interpreter.
Also cleaned up implementation of pdfi_read_Info() to modernize the
dictionary calls. It was probably really old code and was doing
unnecessary stuff about resolving an INDIRECT object that is now
handled in the dictionary code.
-rw-r--r-- | pdf/pdf_doc.c | 33 | ||||
-rw-r--r-- | pdf/pdf_int.c | 19 |
2 files changed, 23 insertions, 29 deletions
diff --git a/pdf/pdf_doc.c b/pdf/pdf_doc.c index 4b4d87d07..5bdb188d8 100644 --- a/pdf/pdf_doc.c +++ b/pdf/pdf_doc.c @@ -90,46 +90,23 @@ int pdfi_read_Root(pdf_context *ctx) int pdfi_read_Info(pdf_context *ctx) { - pdf_obj *o, *o1; + pdf_dict *Info; int code; if (ctx->args.pdfdebug) dmprintf(ctx->memory, "%% Reading Info dictionary\n"); - code = pdfi_dict_get(ctx, ctx->Trailer, "Info", &o1); + code = pdfi_dict_get_type(ctx, ctx->Trailer, "Info", PDF_DICT, (pdf_obj **)&Info); if (code < 0) return code; - if (o1->type == PDF_INDIRECT) { - code = pdfi_dereference(ctx, ((pdf_indirect_ref *)o1)->ref_object_num, ((pdf_indirect_ref *)o1)->ref_generation_num, &o); - pdfi_countdown(o1); - if (code < 0) - return code; - - if (o->type != PDF_DICT) { - pdfi_countdown(o); - return_error(gs_error_typecheck); - } - - code = pdfi_dict_put(ctx, ctx->Trailer, "Info", o); - if (code < 0) { - pdfi_countdown(o); - return code; - } - o1 = o; - } else { - if (o1->type != PDF_DICT) { - pdfi_countdown(o1); - return_error(gs_error_typecheck); - } - } - if (ctx->args.pdfdebug) dmprintf(ctx->memory, "\n"); - /* We don't pdfi_countdown(o1) now, because we've transferred our + + /* We don't pdfi_countdown(Info) now, because we've transferred our * reference to the pointer in the pdf_context structure. */ - ctx->Info = (pdf_dict *)o1; + ctx->Info = Info; return 0; } diff --git a/pdf/pdf_int.c b/pdf/pdf_int.c index bdad20bf4..33d871eae 100644 --- a/pdf/pdf_int.c +++ b/pdf/pdf_int.c @@ -468,6 +468,12 @@ static int pdfi_read_hexstring(pdf_context *ctx, pdf_c_stream *s, uint32_t indir string->indirect_num = indirect_num; string->indirect_gen = indirect_gen; + if (ctx->encryption.is_encrypted && ctx->encryption.decrypt_strings) { + code = pdfi_decrypt_string(ctx, string); + if (code < 0) + return code; + } + code = pdfi_push(ctx, (pdf_obj *)string); if (code < 0) pdfi_free_object((pdf_obj *)string); @@ -1892,6 +1898,9 @@ pdfi_interpret_inner_content_c_string(pdf_context *ctx, char *content_string, bool stoponerror, const char *desc) { uint32_t length = (uint32_t)strlen(content_string); + bool decrypt_strings; + int code; + /* Underlying buffer limit is uint32, so handle the extremely unlikely case that * our string is too big. @@ -1899,8 +1908,16 @@ pdfi_interpret_inner_content_c_string(pdf_context *ctx, char *content_string, if (length != strlen(content_string)) return_error(gs_error_limitcheck); - return pdfi_interpret_inner_content_buffer(ctx, (byte *)content_string, length, + /* Since this is a constructed string content, not part of the file, it can never + * be encrypted. So disable decryption during this call. + */ + decrypt_strings = ctx->encryption.decrypt_strings; + ctx->encryption.decrypt_strings = false; + code = pdfi_interpret_inner_content_buffer(ctx, (byte *)content_string, length, stream_dict, page_dict, stoponerror, desc); + ctx->encryption.decrypt_strings = decrypt_strings; + + return code; } /* Interpret inner content from a string |