// Copyright 2016 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/fpdfdoc/cpdf_metadata.h" #include #include #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fxcrt/cfx_read_only_span_stream.h" #include "core/fxcrt/check.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/xml/cfx_xmldocument.h" #include "core/fxcrt/xml/cfx_xmlelement.h" #include "core/fxcrt/xml/cfx_xmlparser.h" namespace { constexpr int kMaxMetaDataDepth = 128; bool CheckForSharedFormInternal(int depth, CFX_XMLElement* element, std::vector* unsupported) { if (depth >= kMaxMetaDataDepth) { return false; } WideString attr = element->GetAttribute(WideString::FromASCII("xmlns:adhocwf")); if (attr.EqualsASCII("http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/")) { for (const auto* child = element->GetFirstChild(); child; child = child->GetNextSibling()) { if (child->GetType() != CFX_XMLNode::Type::kElement) continue; const auto* child_elem = static_cast(child); if (!child_elem->GetName().EqualsASCII("adhocwf:workflowType")) continue; switch (child_elem->GetTextData().GetInteger()) { case 0: unsupported->push_back(UnsupportedFeature::kDocumentSharedFormEmail); break; case 1: unsupported->push_back( UnsupportedFeature::kDocumentSharedFormAcrobat); break; case 2: unsupported->push_back( UnsupportedFeature::kDocumentSharedFormFilesystem); break; } // We only care about the first one we find. break; } } for (auto* child = element->GetFirstChild(); child; child = child->GetNextSibling()) { CFX_XMLElement* xml_element = ToXMLElement(child); if (xml_element && !CheckForSharedFormInternal(depth + 1, xml_element, unsupported)) { return false; } } return true; } } // namespace CPDF_Metadata::CPDF_Metadata(RetainPtr pStream) : stream_(std::move(pStream)) { DCHECK(stream_); } CPDF_Metadata::~CPDF_Metadata() = default; std::vector CPDF_Metadata::CheckForSharedForm() const { auto pAcc = pdfium::MakeRetain(stream_); pAcc->LoadAllDataFiltered(); auto stream = pdfium::MakeRetain(pAcc->GetSpan()); CFX_XMLParser parser(stream); std::unique_ptr doc = parser.Parse(); if (!doc) return {}; std::vector unsupported; CheckForSharedFormInternal(/*depth=*/0, doc->GetRoot(), &unsupported); return unsupported; }