aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-06 22:25:10 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-06 23:08:41 +0100
commite076c9bf084ba5f90f52d829255e4ef04e3a8031 (patch)
tree2e2fb760c89cf04dd7eda0d2c5044f46925c6fc1 /libqpdf
parentac2b3b96e163c6ef98b708c6392a7e51538dd1cf (diff)
downloadqpdf-e076c9bf084ba5f90f52d829255e4ef04e3a8031.tar.zst
Remove erroneous handling of /EFF for stream decryption
I thought /EFF was supposed to be used as a default for decrypting embedded file streams, but actually it's supposed to be advice to a conforming writer about handling new ones. This makes sense since the findAttachmentStreams code, which is not actually needed, was never right.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF.cc48
-rw-r--r--libqpdf/QPDF_encryption.cc25
2 files changed, 20 insertions, 53 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 89c6ed74..3209903f 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -18,7 +18,6 @@
#include <qpdf/FileInputSource.hh>
#include <qpdf/BufferInputSource.hh>
#include <qpdf/OffsetInputSource.hh>
-#include <qpdf/QPDFNameTreeObjectHelper.hh>
#include <qpdf/QPDFExc.hh>
#include <qpdf/QPDF_Null.hh>
@@ -98,7 +97,6 @@ QPDF::ForeignStreamData::ForeignStreamData(
int foreign_generation,
qpdf_offset_t offset,
size_t length,
- bool is_attachment_stream,
QPDFObjectHandle local_dict)
:
encp(encp),
@@ -107,7 +105,6 @@ QPDF::ForeignStreamData::ForeignStreamData(
foreign_generation(foreign_generation),
offset(offset),
length(length),
- is_attachment_stream(is_attachment_stream),
local_dict(local_dict)
{
}
@@ -508,7 +505,6 @@ QPDF::parse(char const* password)
}
initializeEncryption();
- findAttachmentStreams();
this->m->parsed = true;
}
@@ -2648,8 +2644,6 @@ QPDF::replaceForeignIndirectObjects(
foreign.getGeneration(),
stream->getOffset(),
stream->getLength(),
- (foreign_stream_qpdf->m->attachment_streams.count(
- foreign.getObjGen()) > 0),
dict);
this->m->copied_stream_data_provider->registerForeignStream(
local_og, foreign_stream_data);
@@ -2882,7 +2876,6 @@ QPDF::pipeStreamData(PointerHolder<EncryptionParameters> encp,
int objid, int generation,
qpdf_offset_t offset, size_t length,
QPDFObjectHandle stream_dict,
- bool is_attachment_stream,
Pipeline* pipeline,
bool suppress_warnings,
bool will_retry)
@@ -2892,7 +2885,7 @@ QPDF::pipeStreamData(PointerHolder<EncryptionParameters> encp,
{
decryptStream(encp, file, qpdf_for_warning,
pipeline, objid, generation,
- stream_dict, is_attachment_stream, to_delete);
+ stream_dict, to_delete);
}
bool success = false;
@@ -2968,14 +2961,11 @@ QPDF::pipeStreamData(int objid, int generation,
bool suppress_warnings,
bool will_retry)
{
- bool is_attachment_stream = (
- this->m->attachment_streams.count(
- QPDFObjGen(objid, generation)) > 0);
return pipeStreamData(
this->m->encp, this->m->file, *this,
objid, generation, offset, length,
- stream_dict, is_attachment_stream,
- pipeline, suppress_warnings, will_retry);
+ stream_dict, pipeline,
+ suppress_warnings, will_retry);
}
bool
@@ -2992,36 +2982,8 @@ QPDF::pipeForeignStreamData(
foreign->encp, foreign->file, *this,
foreign->foreign_objid, foreign->foreign_generation,
foreign->offset, foreign->length,
- foreign->local_dict, foreign->is_attachment_stream,
- pipeline, suppress_warnings, will_retry);
-}
-
-void
-QPDF::findAttachmentStreams()
-{
- QPDFObjectHandle root = getRoot();
- QPDFObjectHandle names = root.getKey("/Names");
- if (! names.isDictionary())
- {
- return;
- }
- QPDFObjectHandle embedded_files = names.getKey("/EmbeddedFiles");
- if (! embedded_files.isDictionary())
- {
- return;
- }
- QPDFNameTreeObjectHelper ef_tree(embedded_files, *this);
- for (auto const& i: ef_tree)
- {
- QPDFObjectHandle item = i.second;
- if (item.isDictionary() &&
- item.getKey("/EF").isDictionary() &&
- item.getKey("/EF").getKey("/F").isStream())
- {
- QPDFObjectHandle stream = item.getKey("/EF").getKey("/F");
- this->m->attachment_streams.insert(stream.getObjGen());
- }
- }
+ foreign->local_dict, pipeline,
+ suppress_warnings, will_retry);
}
void
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index 00bd697e..2ff48df9 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -1022,6 +1022,20 @@ QPDF::initializeEncryption()
this->m->encp->cf_string = interpretCF(this->m->encp, StrF);
if (EFF.isName())
{
+ // qpdf does not use this for anything other than
+ // informational purposes. This is intended to instruct
+ // conforming writers on which crypt filter should be used
+ // when new file attachments are added to a PDF file, but
+ // qpdf never generates encrypted files with non-default
+ // crypt filters. Prior to 10.2, I was under the mistaken
+ // impression that this was supposed to be used for
+ // decrypting attachments, but the code was wrong in a way
+ // that turns out not to have mattered because no writers
+ // were generating files the way I was imagining. Still,
+ // providing this information could be useful when looking
+ // at a file generated by something else, such as Acrobat
+ // when specifying that only attachments should be
+ // encrypted.
this->m->encp->cf_file = interpretCF(this->m->encp, EFF);
}
else
@@ -1224,7 +1238,6 @@ QPDF::decryptStream(PointerHolder<EncryptionParameters> encp,
QPDF& qpdf_for_warning, Pipeline*& pipeline,
int objid, int generation,
QPDFObjectHandle& stream_dict,
- bool is_attachment_stream,
std::vector<PointerHolder<Pipeline> >& heap)
{
std::string type;
@@ -1296,15 +1309,7 @@ QPDF::decryptStream(PointerHolder<EncryptionParameters> encp,
}
else
{
- if (is_attachment_stream)
- {
- QTC::TC("qpdf", "QPDF_encryption attachment stream");
- method = encp->cf_file;
- }
- else
- {
- method = encp->cf_stream;
- }
+ method = encp->cf_stream;
}
}
use_aes = false;