diff options
author | thestig <thestig@chromium.org> | 2015-06-10 17:53:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-11 00:53:36 +0000 |
commit | b9357a7d2361b9f03e5a0a4ee784016adcea5303 (patch) | |
tree | e30f14d7316ecbcc989ac10ffbf9e4605c358a31 /pdf | |
parent | 2efc98723d56913bc45714ef4ad4e5948a870797 (diff) | |
download | chromium_src-b9357a7d2361b9f03e5a0a4ee784016adcea5303.zip chromium_src-b9357a7d2361b9f03e5a0a4ee784016adcea5303.tar.gz chromium_src-b9357a7d2361b9f03e5a0a4ee784016adcea5303.tar.bz2 |
PDF: Interpret printing permission bits correctly.
The rules for interpreting printing permission bits are different
depending on the security handler revision. This takes the handler
revision into account.
BUG=497924
Review URL: https://codereview.chromium.org/1167393002
Cr-Commit-Position: refs/heads/master@{#333864}
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/pdfium/pdfium_engine.cc | 24 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.h | 3 |
2 files changed, 24 insertions, 3 deletions
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index 4b27946..52605e9 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -592,6 +592,7 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) last_page_to_search_(-1), last_character_index_to_search_(-1), permissions_(0), + permissions_handler_revision_(-1), fpdf_availability_(NULL), next_timer_id_(0), last_page_mouse_down_(-1), @@ -2324,16 +2325,32 @@ bool PDFiumEngine::IsSelecting() { } bool PDFiumEngine::HasPermission(DocumentPermission permission) const { + // PDF 1.7 spec, section 3.5.2 says: "If the revision number is 2 or greater, + // the operations to which user access can be controlled are as follows: ..." + // + // Thus for revision numbers less than 2, permissions are ignored and this + // always returns true. + if (permissions_handler_revision_ < 2) + return true; + + // Handle high quality printing permission separately for security handler + // revision 3+. See table 3.20 in the PDF 1.7 spec. + if (permission == PERMISSION_PRINT_HIGH_QUALITY && + permissions_handler_revision_ >= 3) { + return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 && + (permissions_ & kPDFPermissionPrintHighQualityMask) != 0; + } + switch (permission) { case PERMISSION_COPY: return (permissions_ & kPDFPermissionCopyMask) != 0; case PERMISSION_COPY_ACCESSIBLE: return (permissions_ & kPDFPermissionCopyAccessibleMask) != 0; case PERMISSION_PRINT_LOW_QUALITY: - return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; case PERMISSION_PRINT_HIGH_QUALITY: - return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 && - (permissions_ & kPDFPermissionPrintHighQualityMask) != 0; + // With security handler revision 2 rules, check the same bit for high + // and low quality. See table 3.20 in the PDF 1.7 spec. + return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; default: return true; } @@ -2622,6 +2639,7 @@ void PDFiumEngine::ContinueLoadingDocument( client_->DocumentHasUnsupportedFeature("Bookmarks"); permissions_ = FPDF_GetDocPermissions(doc_); + permissions_handler_revision_ = FPDF_GetSecurityHandlerRevision(doc_); if (!form_) { // Only returns 0 when data isn't available. If form data is downloaded, or diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index 480a6e8..ff45f45 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -647,6 +647,9 @@ class PDFiumEngine : public PDFEngine, // Permissions bitfield. unsigned long permissions_; + // Permissions security handler revision number. -1 for unknown. + int permissions_handler_revision_; + // Interface structure to provide access to document stream. FPDF_FILEACCESS file_access_; // Interface structure to check data availability in the document stream. |