Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: fpdfsdk/src/fpdfview.cpp

Issue 1396283006: Fix layering violation in CPDF_Document::FromFPDFDocument(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« fpdfsdk/include/fsdk_define.h ('K') | « fpdfsdk/src/fpdfsave.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../core/include/fxcodec/fx_codec.h" 7 #include "../../core/include/fxcodec/fx_codec.h"
8 #include "../../core/include/fxcrt/fx_safe_types.h" 8 #include "../../core/include/fxcrt/fx_safe_types.h"
9 #include "../../public/fpdf_ext.h" 9 #include "../../public/fpdf_ext.h"
10 #include "../../public/fpdf_progressive.h" 10 #include "../../public/fpdf_progressive.h"
11 #include "../../public/fpdfview.h" 11 #include "../../public/fpdfview.h"
12 #include "../../third_party/base/nonstd_unique_ptr.h" 12 #include "../../third_party/base/nonstd_unique_ptr.h"
13 #include "../../third_party/base/numerics/safe_conversions_impl.h" 13 #include "../../third_party/base/numerics/safe_conversions_impl.h"
14 #include "../include/fsdk_define.h" 14 #include "../include/fsdk_define.h"
15 #include "../include/fsdk_mgr.h" 15 #include "../include/fsdk_mgr.h"
16 #include "../include/fsdk_rendercontext.h" 16 #include "../include/fsdk_rendercontext.h"
17 #include "../include/javascript/IJavaScript.h" 17 #include "../include/javascript/IJavaScript.h"
18 18
19 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
20 return static_cast<CPDF_Document*>(doc);
21 }
22
19 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { 23 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) {
20 if (pFileAccess) 24 if (pFileAccess)
21 m_FileAccess = *pFileAccess; 25 m_FileAccess = *pFileAccess;
22 } 26 }
23 27
24 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, 28 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer,
25 FX_FILESIZE offset, 29 FX_FILESIZE offset,
26 size_t size) { 30 size_t size) {
27 if (offset < 0) { 31 if (offset < 0) {
28 return FALSE; 32 return FALSE;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 CheckUnSupportError(pDoc, err_code); 219 CheckUnSupportError(pDoc, err_code);
216 return pParser->GetDocument(); 220 return pParser->GetDocument();
217 } 221 }
218 222
219 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, 223 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
220 int* fileVersion) { 224 int* fileVersion) {
221 if (!fileVersion) 225 if (!fileVersion)
222 return FALSE; 226 return FALSE;
223 227
224 *fileVersion = 0; 228 *fileVersion = 0;
225 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(doc); 229 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
226 if (!pDoc) 230 if (!pDoc)
227 return FALSE; 231 return FALSE;
228 232
229 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 233 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
230 if (!pParser) 234 if (!pParser)
231 return FALSE; 235 return FALSE;
232 236
233 *fileVersion = pParser->GetFileVersion(); 237 *fileVersion = pParser->GetFileVersion();
234 return TRUE; 238 return TRUE;
235 } 239 }
236 240
237 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match 241 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match
238 // header). 242 // header).
239 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { 243 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
240 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 244 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
241 if (!pDoc) 245 if (!pDoc)
242 return 0; 246 return 0;
243 247
244 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 248 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
245 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 249 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
246 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; 250 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
247 } 251 }
248 252
249 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { 253 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
250 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 254 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
251 if (!pDoc) 255 if (!pDoc)
252 return -1; 256 return -1;
253 257
254 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 258 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
255 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 259 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
256 return pDict ? pDict->GetInteger("R") : -1; 260 return pDict ? pDict->GetInteger("R") : -1;
257 } 261 }
258 262
259 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { 263 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
260 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 264 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
261 return pDoc ? pDoc->GetPageCount() : 0; 265 return pDoc ? pDoc->GetPageCount() : 0;
262 } 266 }
263 267
264 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, 268 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
265 int page_index) { 269 int page_index) {
266 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 270 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
267 if (!pDoc) 271 if (!pDoc)
268 return nullptr; 272 return nullptr;
269 273
270 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) 274 if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
271 return nullptr; 275 return nullptr;
272 276
273 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 277 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
274 if (pDict == NULL) 278 if (pDict == NULL)
275 return NULL; 279 return NULL;
276 CPDF_Page* pPage = new CPDF_Page; 280 CPDF_Page* pPage = new CPDF_Page;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 CPDFSDK_PageView* pPageView = 509 CPDFSDK_PageView* pPageView =
506 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); 510 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page);
507 if (pPageView && pPageView->IsLocked()) { 511 if (pPageView && pPageView->IsLocked()) {
508 pPageView->TakeOverPage(); 512 pPageView->TakeOverPage();
509 return; 513 return;
510 } 514 }
511 delete (CPDF_Page*)page; 515 delete (CPDF_Page*)page;
512 } 516 }
513 517
514 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { 518 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
515 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 519 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
516 if (!pDoc) 520 if (!pDoc)
517 return; 521 return;
518 522
519 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 523 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
520 if (!pParser) { 524 if (!pParser) {
521 delete pDoc; 525 delete pDoc;
522 return; 526 return;
523 } 527 }
524 delete pParser; 528 delete pParser;
525 } 529 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions); 742 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions);
739 pContext->m_pRenderer->Start(pause); 743 pContext->m_pRenderer->Start(pause);
740 if (bNeedToRestore) 744 if (bNeedToRestore)
741 pContext->m_pDevice->RestoreState(); 745 pContext->m_pDevice->RestoreState();
742 } 746 }
743 747
744 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, 748 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
745 int page_index, 749 int page_index,
746 double* width, 750 double* width,
747 double* height) { 751 double* height) {
748 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 752 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
749 if (!pDoc) 753 if (!pDoc)
750 return FALSE; 754 return FALSE;
751 755
752 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 756 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
753 if (!pDict) 757 if (!pDict)
754 return FALSE; 758 return FALSE;
755 759
756 CPDF_Page page; 760 CPDF_Page page;
757 page.Load(pDoc, pDict); 761 page.Load(pDoc, pDict);
758 *width = page.GetPageWidth(); 762 *width = page.GetPageWidth();
759 *height = page.GetPageHeight(); 763 *height = page.GetPageHeight();
760 764
761 return TRUE; 765 return TRUE;
762 } 766 }
763 767
764 DLLEXPORT FPDF_BOOL STDCALL 768 DLLEXPORT FPDF_BOOL STDCALL
765 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { 769 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
766 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 770 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
767 if (!pDoc) 771 if (!pDoc)
768 return TRUE; 772 return TRUE;
769 CPDF_ViewerPreferences viewRef(pDoc); 773 CPDF_ViewerPreferences viewRef(pDoc);
770 return viewRef.PrintScaling(); 774 return viewRef.PrintScaling();
771 } 775 }
772 776
773 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { 777 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
774 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 778 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
775 if (!pDoc) 779 if (!pDoc)
776 return 1; 780 return 1;
777 CPDF_ViewerPreferences viewRef(pDoc); 781 CPDF_ViewerPreferences viewRef(pDoc);
778 return viewRef.NumCopies(); 782 return viewRef.NumCopies();
779 } 783 }
780 784
781 DLLEXPORT FPDF_PAGERANGE STDCALL 785 DLLEXPORT FPDF_PAGERANGE STDCALL
782 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { 786 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
783 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 787 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
784 if (!pDoc) 788 if (!pDoc)
785 return NULL; 789 return NULL;
786 CPDF_ViewerPreferences viewRef(pDoc); 790 CPDF_ViewerPreferences viewRef(pDoc);
787 return viewRef.PrintPageRange(); 791 return viewRef.PrintPageRange();
788 } 792 }
789 793
790 DLLEXPORT FPDF_DUPLEXTYPE STDCALL 794 DLLEXPORT FPDF_DUPLEXTYPE STDCALL
791 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { 795 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
792 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 796 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
793 if (!pDoc) 797 if (!pDoc)
794 return DuplexUndefined; 798 return DuplexUndefined;
795 CPDF_ViewerPreferences viewRef(pDoc); 799 CPDF_ViewerPreferences viewRef(pDoc);
796 CFX_ByteString duplex = viewRef.Duplex(); 800 CFX_ByteString duplex = viewRef.Duplex();
797 if (FX_BSTRC("Simplex") == duplex) 801 if (FX_BSTRC("Simplex") == duplex)
798 return Simplex; 802 return Simplex;
799 if (FX_BSTRC("DuplexFlipShortEdge") == duplex) 803 if (FX_BSTRC("DuplexFlipShortEdge") == duplex)
800 return DuplexFlipShortEdge; 804 return DuplexFlipShortEdge;
801 if (FX_BSTRC("DuplexFlipLongEdge") == duplex) 805 if (FX_BSTRC("DuplexFlipLongEdge") == duplex)
802 return DuplexFlipLongEdge; 806 return DuplexFlipLongEdge;
803 return DuplexUndefined; 807 return DuplexUndefined;
804 } 808 }
805 809
806 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { 810 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
807 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 811 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
808 if (!pDoc) 812 if (!pDoc)
809 return 0; 813 return 0;
810 814
811 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 815 CPDF_Dictionary* pRoot = pDoc->GetRoot();
812 if (!pRoot) 816 if (!pRoot)
813 return 0; 817 return 0;
814 818
815 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); 819 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
816 int count = nameTree.GetCount(); 820 int count = nameTree.GetCount();
817 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); 821 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
818 if (pDest) 822 if (pDest)
819 count += pDest->GetCount(); 823 count += pDest->GetCount();
820 return count; 824 return count;
821 } 825 }
822 826
823 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, 827 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
824 FPDF_BYTESTRING name) { 828 FPDF_BYTESTRING name) {
825 if (!name || name[0] == 0) 829 if (!name || name[0] == 0)
826 return nullptr; 830 return nullptr;
827 831
828 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); 832 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
829 if (!pDoc) 833 if (!pDoc)
830 return nullptr; 834 return nullptr;
831 835
832 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 836 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
833 return name_tree.LookupNamedDest(pDoc, name); 837 return name_tree.LookupNamedDest(pDoc, name);
834 } 838 }
835 839
836 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, 840 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
837 int index, 841 int index,
838 void* buffer, 842 void* buffer,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 if (!buffer) { 890 if (!buffer) {
887 *buflen = len; 891 *buflen = len;
888 } else if (*buflen >= len) { 892 } else if (*buflen >= len) {
889 memcpy(buffer, utf16Name.c_str(), len); 893 memcpy(buffer, utf16Name.c_str(), len);
890 *buflen = len; 894 *buflen = len;
891 } else { 895 } else {
892 *buflen = -1; 896 *buflen = -1;
893 } 897 }
894 return (FPDF_DEST)pDestObj; 898 return (FPDF_DEST)pDestObj;
895 } 899 }
OLDNEW
« fpdfsdk/include/fsdk_define.h ('K') | « fpdfsdk/src/fpdfsave.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698