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

Side by Side Diff: core/src/fxge/dib/fx_dib_engine.cpp

Issue 1226403008: Merge to M44: Abort on OOM by default in FX_Alloc(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@2403
Patch Set: Created 5 years, 5 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 | « core/src/fxge/dib/fx_dib_convert.cpp ('k') | core/src/fxge/dib/fx_dib_main.cpp » ('j') | 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 "../../../include/fxge/fx_dib.h" 7 #include "../../../include/fxge/fx_dib.h"
8 #include "../../../include/fxge/fx_ge.h" 8 #include "../../../include/fxge/fx_ge.h"
9 #include "dib_int.h" 9 #include "dib_int.h"
10 #include <limits.h> 10 #include <limits.h>
(...skipping 10 matching lines...) Expand all
21 base = (FX_FLOAT)(src_len); 21 base = (FX_FLOAT)(src_len);
22 } else { 22 } else {
23 base = 0; 23 base = 0;
24 } 24 }
25 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1; 25 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1;
26 m_ItemSize = sizeof(int) * 2 + (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((F X_FLOAT)scale)) + ext_size)); 26 m_ItemSize = sizeof(int) * 2 + (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((F X_FLOAT)scale)) + ext_size));
27 m_DestMin = dest_min; 27 m_DestMin = dest_min;
28 if ((dest_max - dest_min) > (int)((1U << 30) - 4) / m_ItemSize) { 28 if ((dest_max - dest_min) > (int)((1U << 30) - 4) / m_ItemSize) {
29 return; 29 return;
30 } 30 }
31 m_pWeightTables = FX_AllocNL(FX_BYTE, (dest_max - dest_min) * m_ItemSize + 4 ); 31 m_pWeightTables = FX_TryAlloc(FX_BYTE, (dest_max - dest_min) * m_ItemSize + 4);
32 if (m_pWeightTables == NULL) { 32 if (m_pWeightTables == NULL) {
33 return; 33 return;
34 } 34 }
35 if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) { 35 if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
36 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel ++) { 36 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel ++) {
37 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); 37 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
38 double src_pos = dest_pixel * scale + scale / 2 + base; 38 double src_pos = dest_pixel * scale + scale / 2 + base;
39 if (flags & FXDIB_INTERPOL) { 39 if (flags & FXDIB_INTERPOL) {
40 pixel_weights.m_SrcStart = (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2); 40 pixel_weights.m_SrcStart = (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
41 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1. 0f / 2); 41 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1. 0f / 2);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 FX_DWORD size = clip_rect.Width(); 195 FX_DWORD size = clip_rect.Width();
196 if (size && m_DestBpp > (int)(INT_MAX / size)) { 196 if (size && m_DestBpp > (int)(INT_MAX / size)) {
197 return; 197 return;
198 } 198 }
199 size *= m_DestBpp; 199 size *= m_DestBpp;
200 if (size > INT_MAX - 31) { 200 if (size > INT_MAX - 31) {
201 return; 201 return;
202 } 202 }
203 size += 31; 203 size += 31;
204 size = size / 32 * 4; 204 size = size / 32 * 4;
205 m_pDestScanline = FX_AllocNL(FX_BYTE, size); 205 m_pDestScanline = FX_TryAlloc(FX_BYTE, size);
206 if (m_pDestScanline == NULL) { 206 if (m_pDestScanline == NULL) {
207 return; 207 return;
208 } 208 }
209 if (dest_format == FXDIB_Rgb32) { 209 if (dest_format == FXDIB_Rgb32) {
210 FXSYS_memset8(m_pDestScanline, 255, size); 210 FXSYS_memset8(m_pDestScanline, 255, size);
211 } 211 }
212 m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4; 212 m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4;
213 m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4; 213 m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4;
214 m_pInterBuf = NULL; 214 m_pInterBuf = NULL;
215 m_pSource = pSrcBitmap; 215 m_pSource = pSrcBitmap;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 304 }
305 if (m_pDestMaskScanline) { 305 if (m_pDestMaskScanline) {
306 FX_Free(m_pDestMaskScanline); 306 FX_Free(m_pDestMaskScanline);
307 } 307 }
308 } 308 }
309 FX_BOOL CStretchEngine::StartStretchHorz() 309 FX_BOOL CStretchEngine::StartStretchHorz()
310 { 310 {
311 if (m_DestWidth == 0 || m_pDestScanline == NULL || m_SrcClip.Height() > (int )((1U << 29) / m_InterPitch) || m_SrcClip.Height() == 0) { 311 if (m_DestWidth == 0 || m_pDestScanline == NULL || m_SrcClip.Height() > (int )((1U << 29) / m_InterPitch) || m_SrcClip.Height() == 0) {
312 return FALSE; 312 return FALSE;
313 } 313 }
314 m_pInterBuf = FX_AllocNL(unsigned char, m_SrcClip.Height() * m_InterPitch); 314 m_pInterBuf = FX_TryAlloc(unsigned char, m_SrcClip.Height() * m_InterPitch);
315 if (m_pInterBuf == NULL) { 315 if (m_pInterBuf == NULL) {
316 return FALSE; 316 return FALSE;
317 } 317 }
318 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) { 318 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) {
319 m_pExtraAlphaBuf = FX_Alloc(unsigned char, m_SrcClip.Height() * m_ExtraM askPitch); 319 m_pExtraAlphaBuf = FX_Alloc(unsigned char, m_SrcClip.Height() * m_ExtraM askPitch);
320 if (!m_pExtraAlphaBuf) { 320 if (!m_pExtraAlphaBuf) {
321 return FALSE; 321 return FALSE;
322 } 322 }
323 FX_DWORD size = (m_DestClip.Width() * 8 + 31) / 32 * 4; 323 FX_DWORD size = (m_DestClip.Width() * 8 + 31) / 32 * 4;
324 m_pDestMaskScanline = FX_AllocNL(unsigned char, size); 324 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size);
325 if (!m_pDestMaskScanline) { 325 if (!m_pDestMaskScanline) {
326 return FALSE; 326 return FALSE;
327 } 327 }
328 } 328 }
329 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidt h, m_SrcClip.left, m_SrcClip.right, m_Flags); 329 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidt h, m_SrcClip.left, m_SrcClip.right, m_Flags);
330 if (m_WeightTable.m_pWeightTables == NULL) { 330 if (m_WeightTable.m_pWeightTables == NULL) {
331 return FALSE; 331 return FALSE;
332 } 332 }
333 m_CurRow = m_SrcClip.top; 333 m_CurRow = m_SrcClip.top;
334 m_State = 1; 334 m_State = 1;
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 return TRUE; 840 return TRUE;
841 } 841 }
842 m_pSource->DownSampleScanline(src_y, m_pScanline, m_DestBPP, m_DestWidth , m_bFlipX, m_ClipRect.left, result_width); 842 m_pSource->DownSampleScanline(src_y, m_pScanline, m_DestBPP, m_DestWidth , m_bFlipX, m_ClipRect.left, result_width);
843 if (m_pMaskScanline) { 843 if (m_pMaskScanline) {
844 m_pSource->m_pAlphaMask->DownSampleScanline(src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, result_width); 844 m_pSource->m_pAlphaMask->DownSampleScanline(src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, result_width);
845 } 845 }
846 m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline); 846 m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline);
847 } 847 }
848 return FALSE; 848 return FALSE;
849 } 849 }
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_convert.cpp ('k') | core/src/fxge/dib/fx_dib_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698