summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-05-19 14:56:52 -0700
committerTom Sepez <tsepez@chromium.org>2015-05-19 14:56:52 -0700
commitbf4aa2cc93a67826247e887b2ba26a1b965eb616 (patch)
treea1d6336676d6d70467a7fb94aa0e625b1dbc8c25 /core/src/fpdfapi
parenteb6527763171cdb4b0fbfea5a20d691f4d67b660 (diff)
downloadpdfium-bf4aa2cc93a67826247e887b2ba26a1b965eb616.tar.xz
Revert "Remove FX_Alloc() null checks now that it can't return NULL."
This reverts commit eb6527763171cdb4b0fbfea5a20d691f4d67b660. Reason for revert: broke javascript tests. TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1145843005
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp18
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp6
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp3
8 files changed, 40 insertions, 11 deletions
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index 3abbcee046..0886d3ff53 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -415,6 +415,9 @@ FX_BOOL CPDF_Encryptor::Initialize(CPDF_CryptoHandler* pHandler, int objnum, FX_
}
m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size);
m_pData = FX_Alloc(FX_BYTE, m_dwSize);
+ if(!m_pData) {
+ return FALSE;
+ }
pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize);
m_bNewBuf = TRUE;
return TRUE;
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
index a5a91ebc53..1328fcdf96 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
@@ -71,11 +71,17 @@ void CPDF_Image::SetJpegImage(IFX_FileRead *pFile)
dwEstimateSize = 8192;
}
FX_LPBYTE pData = FX_Alloc(FX_BYTE, dwEstimateSize);
+ if (!pData) {
+ return;
+ }
pFile->ReadBlock(pData, 0, dwEstimateSize);
CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize);
FX_Free(pData);
if (!pDict && size > dwEstimateSize) {
pData = FX_Alloc(FX_BYTE, size);
+ if (!pData) {
+ return;
+ }
pFile->ReadBlock(pData, 0, size);
pDict = InitJPEG(pData, size);
FX_Free(pData);
@@ -217,8 +223,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F
} else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
_JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, mask_size, TRUE);
} else {
- mask_buf = FX_Alloc2D(FX_BYTE, maskHeight, maskWidth);
- mask_size = maskHeight * maskWidth; // Safe since checked alloc returned.
+ mask_size = maskHeight * maskWidth;
+ mask_buf = FX_Alloc(FX_BYTE, mask_size);
for (FX_INT32 a = 0; a < maskHeight; a ++) {
FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), maskWidth);
}
@@ -300,8 +306,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F
}
} else if (opType == 1) {
if (!bStream) {
- dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight);
- dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned.
+ dest_size = dest_pitch * BitmapHeight;
+ dest_buf = FX_Alloc(FX_BYTE, dest_size);
}
FX_LPBYTE pDest = dest_buf;
for (FX_INT32 i = 0; i < BitmapHeight; i ++) {
@@ -315,8 +321,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F
}
} else if (opType == 2) {
if (!bStream) {
- dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight);
- dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned.
+ dest_size = dest_pitch * BitmapHeight;
+ dest_buf = FX_Alloc(FX_BYTE, dest_size);
} else {
dest_buf = FX_Alloc(FX_BYTE, dest_pitch);
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
index 5a9f1a8cb8..4ec753d751 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
@@ -204,10 +204,11 @@ void CPDF_TextObject::CopyData(const CPDF_PageObject* pSrc)
if (m_nChars > 1) {
m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars);
m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
- for (int i = 0; i < m_nChars; i ++) {
+ int i;
+ for (i = 0; i < m_nChars; i ++) {
m_pCharCodes[i] = pSrcObj->m_pCharCodes[i];
}
- for (int i = 0; i < m_nChars - 1; i ++) {
+ for (i = 0; i < m_nChars - 1; i ++) {
m_pCharPos[i] = pSrcObj->m_pCharPos[i];
}
} else {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index d8b24593ef..952fe1d9a9 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -262,8 +262,8 @@ FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, FX_LPBYTE& dest_b
delete pDecoder;
return -1;
}
- dest_buf = FX_Alloc2D(FX_BYTE, pitch, height);
- dest_size = pitch * height; // Safe since checked alloc returned.
+ dest_size = pitch * height;
+ dest_buf = FX_Alloc( FX_BYTE, dest_size);
for (int row = 0; row < height; row ++) {
FX_LPBYTE pLine = pDecoder->GetScanline(row);
if (pLine == NULL) {
@@ -1050,6 +1050,10 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause)
m_Size += size + 1;
}
m_pData = FX_Alloc(FX_BYTE, m_Size);
+ if (!m_pData) {
+ m_Status = Done;
+ return;
+ }
FX_DWORD pos = 0;
for (i = 0; i < m_nStreams; i ++) {
FXSYS_memcpy32(m_pData + pos, m_pStreamArray[i]->GetData(), m_pStreamArray[i]->GetSize());
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 691981cb10..8f5871df7f 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -40,6 +40,9 @@ FX_DWORD _A85Decode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_b
return (FX_DWORD) - 1;
}
dest_buf = FX_Alloc(FX_BYTE, zcount * 4 + (pos - zcount));
+ if (dest_buf == NULL) {
+ return (FX_DWORD) - 1;
+ }
int state = 0;
FX_UINT32 res = 0;
pos = dest_size = 0;
@@ -150,6 +153,9 @@ FX_DWORD RunLengthDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& d
return -1;
}
dest_buf = FX_Alloc( FX_BYTE, dest_size);
+ if (!dest_buf) {
+ return -1;
+ }
i = 0;
int dest_count = 0;
while (i < src_size) {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 341be13d44..3eac5ae74e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -1086,7 +1086,7 @@ void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, FX_BOOL bRawAccess,
}
if (!pStream->IsMemoryBased()) {
pSrcData = m_pSrcData = FX_Alloc(FX_BYTE, dwSrcSize);
- if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) {
+ if (!pSrcData || !pStream->ReadRawData(0, pSrcData, dwSrcSize)) {
return;
}
} else {
@@ -1165,6 +1165,9 @@ FX_LPBYTE CPDF_StreamAcc::DetachData()
return p;
}
FX_LPBYTE p = FX_Alloc(FX_BYTE, m_dwSize);
+ if (p == NULL) {
+ return NULL;
+ }
FXSYS_memcpy32(p, m_pData, m_dwSize);
return p;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 0d4ed27c06..2772d9825e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2477,6 +2477,9 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT
}
CPDF_Stream* pStream;
FX_LPBYTE pData = FX_Alloc(FX_BYTE, len);
+ if (!pData) {
+ return NULL;
+ }
ReadBlock(pData, len);
if (pCryptoHandler) {
CFX_BinaryBuf dest_buf;
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index b45d9c3e5d..7093edae47 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -500,6 +500,9 @@ DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, FX
return NULL;
}
DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents);
+ if (pCompData == NULL) {
+ return NULL;
+ }
int max_data = (1 << m_bpc) - 1;
CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode"));
if (pDecode) {