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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp

Issue 1143663004: Add safe FX_Alloc2D() macro (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Drop one file, indent. Created 5 years, 7 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
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 <limits.h> 7 #include <limits.h>
8 8
9 #include "../../../include/fpdfapi/fpdf_page.h" 9 #include "../../../include/fpdfapi/fpdf_page.h"
10 #include "../../../include/fpdfapi/fpdf_module.h" 10 #include "../../../include/fpdfapi/fpdf_module.h"
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 return FALSE; 663 return FALSE;
664 } 664 }
665 CPDF_Array* pArray0 = pDict->GetArray(FX_BSTRC("C0")); 665 CPDF_Array* pArray0 = pDict->GetArray(FX_BSTRC("C0"));
666 if (m_nOutputs == 0) { 666 if (m_nOutputs == 0) {
667 m_nOutputs = 1; 667 m_nOutputs = 1;
668 if (pArray0) { 668 if (pArray0) {
669 m_nOutputs = pArray0->GetCount(); 669 m_nOutputs = pArray0->GetCount();
670 } 670 }
671 } 671 }
672 CPDF_Array* pArray1 = pDict->GetArray(FX_BSTRC("C1")); 672 CPDF_Array* pArray1 = pDict->GetArray(FX_BSTRC("C1"));
673 m_pBeginValues = FX_Alloc(FX_FLOAT, m_nOutputs * 2); 673 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
674 m_pEndValues = FX_Alloc(FX_FLOAT, m_nOutputs * 2); 674 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
675 for (int i = 0; i < m_nOutputs; i ++) { 675 for (int i = 0; i < m_nOutputs; i ++) {
676 m_pBeginValues[i] = pArray0 ? pArray0->GetFloat(i) : 0.0f; 676 m_pBeginValues[i] = pArray0 ? pArray0->GetFloat(i) : 0.0f;
677 m_pEndValues[i] = pArray1 ? pArray1->GetFloat(i) : 1.0f; 677 m_pEndValues[i] = pArray1 ? pArray1->GetFloat(i) : 1.0f;
678 } 678 }
679 m_Exponent = pDict->GetFloat(FX_BSTRC("N")); 679 m_Exponent = pDict->GetFloat(FX_BSTRC("N"));
680 m_nOrigOutputs = m_nOutputs; 680 m_nOrigOutputs = m_nOutputs;
681 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) { 681 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) {
682 return FALSE; 682 return FALSE;
683 } 683 }
684 m_nOutputs *= m_nInputs; 684 m_nOutputs *= m_nInputs;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 m_pBounds = FX_Alloc(FX_FLOAT, m_nSubs + 1); 761 m_pBounds = FX_Alloc(FX_FLOAT, m_nSubs + 1);
762 m_pBounds[0] = m_pDomains[0]; 762 m_pBounds[0] = m_pDomains[0];
763 pArray = pDict->GetArray(FX_BSTRC("Bounds")); 763 pArray = pDict->GetArray(FX_BSTRC("Bounds"));
764 if (pArray == NULL) { 764 if (pArray == NULL) {
765 return FALSE; 765 return FALSE;
766 } 766 }
767 for (i = 0; i < m_nSubs - 1; i ++) { 767 for (i = 0; i < m_nSubs - 1; i ++) {
768 m_pBounds[i + 1] = pArray->GetFloat(i); 768 m_pBounds[i + 1] = pArray->GetFloat(i);
769 } 769 }
770 m_pBounds[m_nSubs] = m_pDomains[1]; 770 m_pBounds[m_nSubs] = m_pDomains[1];
771 m_pEncode = FX_Alloc(FX_FLOAT, m_nSubs * 2); 771 m_pEncode = FX_Alloc2D(FX_FLOAT, m_nSubs, 2);
772 pArray = pDict->GetArray(FX_BSTRC("Encode")); 772 pArray = pDict->GetArray(FX_BSTRC("Encode"));
773 if (pArray == NULL) { 773 if (pArray == NULL) {
774 return FALSE; 774 return FALSE;
775 } 775 }
776 for (i = 0; i < m_nSubs * 2; i ++) { 776 for (i = 0; i < m_nSubs * 2; i ++) {
777 m_pEncode[i] = pArray->GetFloat(i); 777 m_pEncode[i] = pArray->GetFloat(i);
778 } 778 }
779 return TRUE; 779 return TRUE;
780 } 780 }
781 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const 781 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 pDict = (CPDF_Dictionary*)pObj; 850 pDict = (CPDF_Dictionary*)pObj;
851 } 851 }
852 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain")); 852 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain"));
853 if (pDomains == NULL) { 853 if (pDomains == NULL) {
854 return FALSE; 854 return FALSE;
855 } 855 }
856 m_nInputs = pDomains->GetCount() / 2; 856 m_nInputs = pDomains->GetCount() / 2;
857 if (m_nInputs == 0) { 857 if (m_nInputs == 0) {
858 return FALSE; 858 return FALSE;
859 } 859 }
860 m_pDomains = FX_Alloc(FX_FLOAT, m_nInputs * 2); 860 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2);
861 for (int i = 0; i < m_nInputs * 2; i ++) { 861 for (int i = 0; i < m_nInputs * 2; i ++) {
862 m_pDomains[i] = pDomains->GetFloat(i); 862 m_pDomains[i] = pDomains->GetFloat(i);
863 } 863 }
864 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range")); 864 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range"));
865 m_nOutputs = 0; 865 m_nOutputs = 0;
866 if (pRanges) { 866 if (pRanges) {
867 m_nOutputs = pRanges->GetCount() / 2; 867 m_nOutputs = pRanges->GetCount() / 2;
868 m_pRanges = FX_Alloc(FX_FLOAT, m_nOutputs * 2); 868 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
869 for (int i = 0; i < m_nOutputs * 2; i ++) { 869 for (int i = 0; i < m_nOutputs * 2; i ++) {
870 m_pRanges[i] = pRanges->GetFloat(i); 870 m_pRanges[i] = pRanges->GetFloat(i);
871 } 871 }
872 } 872 }
873 FX_DWORD old_outputs = m_nOutputs; 873 FX_DWORD old_outputs = m_nOutputs;
874 FX_BOOL ret = v_Init(pObj); 874 FX_BOOL ret = v_Init(pObj);
875 if (m_pRanges && m_nOutputs > (int)old_outputs) { 875 if (m_pRanges && m_nOutputs > (int)old_outputs) {
876 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2); 876 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2);
877 if (m_pRanges) { 877 if (m_pRanges) {
878 FXSYS_memset32(m_pRanges + (old_outputs * 2), 0, sizeof(FX_FLOAT) * (m_nOutputs - old_outputs) * 2); 878 FXSYS_memset32(m_pRanges + (old_outputs * 2), 0, sizeof(FX_FLOAT) * (m_nOutputs - old_outputs) * 2);
(...skipping 19 matching lines...) Expand all
898 for (int i = 0; i < m_nOutputs; i ++) { 898 for (int i = 0; i < m_nOutputs; i ++) {
899 if (results[i] < m_pRanges[i * 2]) { 899 if (results[i] < m_pRanges[i * 2]) {
900 results[i] = m_pRanges[i * 2]; 900 results[i] = m_pRanges[i * 2];
901 } else if (results[i] > m_pRanges[i * 2 + 1]) { 901 } else if (results[i] > m_pRanges[i * 2 + 1]) {
902 results[i] = m_pRanges[i * 2 + 1]; 902 results[i] = m_pRanges[i * 2 + 1];
903 } 903 }
904 } 904 }
905 } 905 }
906 return TRUE; 906 return TRUE;
907 } 907 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698