From 09175e457852c585a68a86d43280f7e0790a4a3b Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 19 Oct 2009 00:17:11 +0000 Subject: more testing, bug fix for linearized aes encrypted files git-svn-id: svn+q:///qpdf/trunk@824 71b93d88-0707-0410-a8cf-f5a4172ac649 --- libqpdf/QPDFWriter.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'libqpdf/QPDFWriter.cc') diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index d094aa66..3c1640f7 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -344,6 +344,52 @@ QPDFWriter::copyEncryptionParameters() } } +void +QPDFWriter::disableIncompatbleEncryption(float v) +{ + if (! this->encrypted) + { + return; + } + + bool disable = false; + if (v < 1.3) + { + disable = true; + } + else + { + int V = atoi(encryption_dictionary["/V"].c_str()); + int R = atoi(encryption_dictionary["/R"].c_str()); + if (v < 1.4) + { + if ((V > 1) || (R > 2)) + { + disable = true; + } + } + else if (v < 1.5) + { + if ((V > 2) || (R > 3)) + { + disable = true; + } + } + else if (v < 1.6) + { + if (this->encrypt_use_aes) + { + disable = true; + } + } + } + if (disable) + { + QTC::TC("qpdf", "QPDFWriter forced version disabled encryption"); + this->encrypted = false; + } +} + void QPDFWriter::setEncryptionParametersInternal( int V, int R, int key_len, long P, @@ -965,7 +1011,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, Buffer* buf = bufpl.getBuffer(); val = QPDF_String( std::string((char*)buf->getBuffer(), - (size_t)buf->getSize())).unparse(); + (size_t)buf->getSize())).unparse(true); delete buf; } else @@ -1423,6 +1469,17 @@ QPDFWriter::write() copyEncryptionParameters(); } + if (! this->forced_pdf_version.empty()) + { + float v = atof(this->forced_pdf_version.c_str()); + disableIncompatbleEncryption(v); + if (v < 1.5) + { + QTC::TC("qpdf", "QPDFWriter forcing object stream disable"); + this->object_stream_mode = o_disable; + } + } + if (this->qdf_mode || this->normalize_content || (this->stream_data_mode == s_uncompress)) { -- cgit v1.2.3-54-g00ecf