In QPDF::pipeStreamData use unique_ptr as heap

This commit is contained in:
m-holger 2023-11-18 14:40:32 +00:00
parent 0dee397075
commit ddad5ad53e
3 changed files with 10 additions and 10 deletions

View File

@ -1133,7 +1133,7 @@ class QPDF
Pipeline*& pipeline, Pipeline*& pipeline,
QPDFObjGen const& og, QPDFObjGen const& og,
QPDFObjectHandle& stream_dict, QPDFObjectHandle& stream_dict,
std::vector<std::shared_ptr<Pipeline>>& heap); std::unique_ptr<Pipeline>& heap);
// Methods to support object copying // Methods to support object copying
void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);

View File

@ -2413,7 +2413,7 @@ QPDF::pipeStreamData(
bool suppress_warnings, bool suppress_warnings,
bool will_retry) bool will_retry)
{ {
std::vector<std::shared_ptr<Pipeline>> to_delete; std::unique_ptr<Pipeline> to_delete;
if (encp->encrypted) { if (encp->encrypted) {
decryptStream(encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete); decryptStream(encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete);
} }

View File

@ -1038,6 +1038,9 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og)
} }
} }
// Prepend a decryption pipeline to 'pipeline'. The decryption pipeline (returned as
// 'decrypt_pipeline' must be owned by the caller to ensure that it stays alive while the pipeline
// is in use.
void void
QPDF::decryptStream( QPDF::decryptStream(
std::shared_ptr<EncryptionParameters> encp, std::shared_ptr<EncryptionParameters> encp,
@ -1046,7 +1049,7 @@ QPDF::decryptStream(
Pipeline*& pipeline, Pipeline*& pipeline,
QPDFObjGen const& og, QPDFObjGen const& og,
QPDFObjectHandle& stream_dict, QPDFObjectHandle& stream_dict,
std::vector<std::shared_ptr<Pipeline>>& heap) std::unique_ptr<Pipeline>& decrypt_pipeline)
{ {
std::string type; std::string type;
if (stream_dict.getKey("/Type").isName()) { if (stream_dict.getKey("/Type").isName()) {
@ -1082,8 +1085,7 @@ QPDF::decryptStream(
crypt_params.getKey("/Name").isName()) { crypt_params.getKey("/Name").isName()) {
QTC::TC("qpdf", "QPDF_encrypt crypt array"); QTC::TC("qpdf", "QPDF_encrypt crypt array");
method = interpretCF(encp, crypt_params.getKey("/Name")); method = interpretCF(encp, crypt_params.getKey("/Name"));
method_source = "stream's Crypt " method_source = "stream's Crypt decode parameters (array)";
"decode parameters (array)";
} }
} }
} }
@ -1132,10 +1134,9 @@ QPDF::decryptStream(
} }
} }
std::string key = getKeyForObject(encp, og, use_aes); std::string key = getKeyForObject(encp, og, use_aes);
std::shared_ptr<Pipeline> new_pipeline;
if (use_aes) { if (use_aes) {
QTC::TC("qpdf", "QPDF_encryption aes decode stream"); QTC::TC("qpdf", "QPDF_encryption aes decode stream");
new_pipeline = std::make_shared<Pl_AES_PDF>( decrypt_pipeline = std::make_unique<Pl_AES_PDF>(
"AES stream decryption", "AES stream decryption",
pipeline, pipeline,
false, false,
@ -1143,14 +1144,13 @@ QPDF::decryptStream(
key.length()); key.length());
} else { } else {
QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
new_pipeline = std::make_shared<Pl_RC4>( decrypt_pipeline = std::make_unique<Pl_RC4>(
"RC4 stream decryption", "RC4 stream decryption",
pipeline, pipeline,
QUtil::unsigned_char_pointer(key), QUtil::unsigned_char_pointer(key),
toI(key.length())); toI(key.length()));
} }
pipeline = new_pipeline.get(); pipeline = decrypt_pipeline.get();
heap.push_back(new_pipeline);
} }
void void