2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Treat /EmbeddedFiles as a proper name tree

If we ever had an encrypted file with different filters for
attachments and either the /EmbeddedFiles name tree was deep or some
of the file specs didn't have /Type, we would have overlooked those as
attachment streams. The code now properly handles /EmbeddedFiles as a
name tree.
This commit is contained in:
Jay Berkenbilt 2021-01-11 10:50:39 -05:00
parent 6fe7b704c7
commit fc88837d4b
2 changed files with 13 additions and 11 deletions

View File

@ -1,3 +1,9 @@
2021-01-11 Jay Berkenbilt <ejb@ql.org>
* Fix very old error in code that was finding attachment streams.
Probably this error never mattered, but the code was still not
exactly right.
2021-01-06 Jay Berkenbilt <ejb@ql.org> 2021-01-06 Jay Berkenbilt <ejb@ql.org>
* Give warnings instead of segfaulting if a QPDF operation is * Give warnings instead of segfaulting if a QPDF operation is

View File

@ -18,6 +18,7 @@
#include <qpdf/FileInputSource.hh> #include <qpdf/FileInputSource.hh>
#include <qpdf/BufferInputSource.hh> #include <qpdf/BufferInputSource.hh>
#include <qpdf/OffsetInputSource.hh> #include <qpdf/OffsetInputSource.hh>
#include <qpdf/QPDFNameTreeObjectHelper.hh>
#include <qpdf/QPDFExc.hh> #include <qpdf/QPDFExc.hh>
#include <qpdf/QPDF_Null.hh> #include <qpdf/QPDF_Null.hh>
@ -3004,22 +3005,17 @@ QPDF::findAttachmentStreams()
{ {
return; return;
} }
QPDFObjectHandle embeddedFiles = names.getKey("/EmbeddedFiles"); QPDFObjectHandle embedded_files = names.getKey("/EmbeddedFiles");
if (! embeddedFiles.isDictionary()) if (! embedded_files.isDictionary())
{ {
return; return;
} }
names = embeddedFiles.getKey("/Names"); QPDFNameTreeObjectHelper ef_tree(embedded_files);
if (! names.isArray()) auto ef_tree_map = ef_tree.getAsMap();
for (auto& i: ef_tree_map)
{ {
return; QPDFObjectHandle item = i.second;
}
for (int i = 0; i < names.getArrayNItems(); ++i)
{
QPDFObjectHandle item = names.getArrayItem(i);
if (item.isDictionary() && if (item.isDictionary() &&
item.getKey("/Type").isName() &&
(item.getKey("/Type").getName() == "/Filespec") &&
item.getKey("/EF").isDictionary() && item.getKey("/EF").isDictionary() &&
item.getKey("/EF").getKey("/F").isStream()) item.getKey("/EF").getKey("/F").isStream())
{ {