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

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2355733002: Fix nullptr dereference in FPDF_GenerateAP(). (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfdoc/cpvt_generateap.h" 7 #include "core/fpdfdoc/cpvt_generateap.h"
8 8
9 #include <algorithm>
10
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
14 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" 16 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
15 #include "core/fpdfdoc/cpvt_color.h" 17 #include "core/fpdfdoc/cpvt_color.h"
16 #include "core/fpdfdoc/cpvt_fontmap.h" 18 #include "core/fpdfdoc/cpvt_fontmap.h"
17 #include "core/fpdfdoc/include/cpdf_annot.h" 19 #include "core/fpdfdoc/include/cpdf_annot.h"
18 #include "core/fpdfdoc/include/cpdf_formfield.h" 20 #include "core/fpdfdoc/include/cpdf_formfield.h"
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 664
663 return sAppStream.MakeString(); 665 return sAppStream.MakeString();
664 } 666 }
665 667
666 } // namespace 668 } // namespace
667 669
668 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { 670 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
669 if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget") 671 if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget")
670 return false; 672 return false;
671 673
672 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); 674 CPDF_Object* pFieldTypeObj = FPDF_GetFieldAttr(pAnnotDict, "FT");
673 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 675 if (!pFieldTypeObj)
674 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 676 return false;
675 : 0; 677
676 if (field_type == "Tx") { 678 CFX_ByteString field_type = pFieldTypeObj->GetString();
679 if (field_type == "Tx")
677 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); 680 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
678 } 681
682 CPDF_Object* pFieldFlagsObj = FPDF_GetFieldAttr(pAnnotDict, "Ff");
683 uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
684
679 if (field_type == "Ch") { 685 if (field_type == "Ch") {
680 return (flags & (1 << 17)) 686 return (flags & (1 << 17))
681 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) 687 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
682 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); 688 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
683 } 689 }
690
684 if (field_type == "Btn") { 691 if (field_type == "Btn") {
685 if (!(flags & (1 << 16))) { 692 if (!(flags & (1 << 16))) {
686 if (!pAnnotDict->KeyExist("AS")) { 693 if (!pAnnotDict->KeyExist("AS")) {
687 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent")) { 694 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent")) {
688 if (pParentDict->KeyExist("AS")) { 695 if (pParentDict->KeyExist("AS")) {
689 pAnnotDict->SetStringFor("AS", pParentDict->GetStringFor("AS")); 696 pAnnotDict->SetStringFor("AS", pParentDict->GetStringFor("AS"));
690 } 697 }
691 } 698 }
692 } 699 }
693 } 700 }
694 } 701 }
702
695 return false; 703 return false;
696 } 704 }
697 705
698 // Static. 706 // Static.
699 bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, 707 bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
700 CPDF_Dictionary* pAnnotDict) { 708 CPDF_Dictionary* pAnnotDict) {
701 return GenerateWidgetAP(pDoc, pAnnotDict, 1); 709 return GenerateWidgetAP(pDoc, pAnnotDict, 1);
702 } 710 }
703 711
704 // Static. 712 // Static.
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 int32_t nFontIndex, 1350 int32_t nFontIndex,
1343 FX_FLOAT fFontSize) { 1351 FX_FLOAT fFontSize) {
1344 CFX_ByteTextBuf sRet; 1352 CFX_ByteTextBuf sRet;
1345 if (pFontMap) { 1353 if (pFontMap) {
1346 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1354 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1347 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1355 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1348 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1356 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1349 } 1357 }
1350 return sRet.MakeString(); 1358 return sRet.MakeString();
1351 } 1359 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698