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

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

Issue 2190283003: Fix a FPE in CStretchEngine::StartStretchHorz(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: signed Created 4 years, 4 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/fxge/dib/dib_int.h ('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 <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 double weight = area_start >= area_end ? 0.0f : area_end - area_start; 226 double weight = area_start >= area_end ? 0.0f : area_end - area_start;
227 if (weight == 0 && j == end_i) { 227 if (weight == 0 && j == end_i) {
228 pixel_weights.m_SrcEnd--; 228 pixel_weights.m_SrcEnd--;
229 break; 229 break;
230 } 230 }
231 pixel_weights.m_Weights[j - start_i] = 231 pixel_weights.m_Weights[j - start_i] =
232 FXSYS_round((FX_FLOAT)(weight * 65536)); 232 FXSYS_round((FX_FLOAT)(weight * 65536));
233 } 233 }
234 } 234 }
235 } 235 }
236
236 CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, 237 CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
237 FXDIB_Format dest_format, 238 FXDIB_Format dest_format,
238 int dest_width, 239 int dest_width,
239 int dest_height, 240 int dest_height,
240 const FX_RECT& clip_rect, 241 const FX_RECT& clip_rect,
241 const CFX_DIBSource* pSrcBitmap, 242 const CFX_DIBSource* pSrcBitmap,
242 int flags) { 243 int flags) {
243 m_State = 0; 244 m_State = 0;
244 m_DestFormat = dest_format; 245 m_DestFormat = dest_format;
245 m_DestBpp = dest_format & 0xff; 246 m_DestBpp = dest_format & 0xff;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 338 }
338 } 339 }
339 } else { 340 } else {
340 if (!m_bHasAlpha) { 341 if (!m_bHasAlpha) {
341 m_TransMethod = 7; 342 m_TransMethod = 7;
342 } else { 343 } else {
343 m_TransMethod = 8; 344 m_TransMethod = 8;
344 } 345 }
345 } 346 }
346 } 347 }
348
349 CStretchEngine::~CStretchEngine() {
350 FX_Free(m_pDestScanline);
351 FX_Free(m_pInterBuf);
352 FX_Free(m_pExtraAlphaBuf);
353 FX_Free(m_pDestMaskScanline);
354 }
355
347 FX_BOOL CStretchEngine::Continue(IFX_Pause* pPause) { 356 FX_BOOL CStretchEngine::Continue(IFX_Pause* pPause) {
348 while (m_State == 1) { 357 while (m_State == 1) {
349 if (ContinueStretchHorz(pPause)) { 358 if (ContinueStretchHorz(pPause)) {
350 return TRUE; 359 return TRUE;
351 } 360 }
352 m_State = 2; 361 m_State = 2;
353 StretchVert(); 362 StretchVert();
354 } 363 }
355 return FALSE; 364 return FALSE;
356 } 365 }
357 CStretchEngine::~CStretchEngine() { 366
358 FX_Free(m_pDestScanline);
359 FX_Free(m_pInterBuf);
360 FX_Free(m_pExtraAlphaBuf);
361 FX_Free(m_pDestMaskScanline);
362 }
363 FX_BOOL CStretchEngine::StartStretchHorz() { 367 FX_BOOL CStretchEngine::StartStretchHorz() {
364 if (m_DestWidth == 0 || !m_pDestScanline || 368 if (m_DestWidth == 0 || m_InterPitch == 0 || !m_pDestScanline)
365 m_SrcClip.Height() > (int)((1U << 29) / m_InterPitch) || 369 return FALSE;
366 m_SrcClip.Height() == 0) { 370
371 if (m_SrcClip.Height() == 0 ||
372 m_SrcClip.Height() > (1 << 29) / m_InterPitch) {
367 return FALSE; 373 return FALSE;
368 } 374 }
375
369 m_pInterBuf = FX_TryAlloc(unsigned char, m_SrcClip.Height() * m_InterPitch); 376 m_pInterBuf = FX_TryAlloc(unsigned char, m_SrcClip.Height() * m_InterPitch);
370 if (!m_pInterBuf) { 377 if (!m_pInterBuf)
371 return FALSE; 378 return FALSE;
372 } 379
373 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) { 380 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) {
374 m_pExtraAlphaBuf = 381 m_pExtraAlphaBuf =
375 FX_Alloc2D(unsigned char, m_SrcClip.Height(), m_ExtraMaskPitch); 382 FX_Alloc2D(unsigned char, m_SrcClip.Height(), m_ExtraMaskPitch);
376 uint32_t size = (m_DestClip.Width() * 8 + 31) / 32 * 4; 383 uint32_t size = (m_DestClip.Width() * 8 + 31) / 32 * 4;
377 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size); 384 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size);
378 if (!m_pDestMaskScanline) { 385 if (!m_pDestMaskScanline)
379 return FALSE; 386 return FALSE;
380 }
381 } 387 }
382 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidth, 388 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidth,
383 m_SrcClip.left, m_SrcClip.right, m_Flags); 389 m_SrcClip.left, m_SrcClip.right, m_Flags);
384 if (!m_WeightTable.m_pWeightTables) { 390 if (!m_WeightTable.m_pWeightTables)
385 return FALSE; 391 return FALSE;
386 } 392
387 m_CurRow = m_SrcClip.top; 393 m_CurRow = m_SrcClip.top;
388 m_State = 1; 394 m_State = 1;
389 return TRUE; 395 return TRUE;
390 } 396 }
391 #define FX_STRECH_PAUSE_ROWS 10 397
392 FX_BOOL CStretchEngine::ContinueStretchHorz(IFX_Pause* pPause) { 398 FX_BOOL CStretchEngine::ContinueStretchHorz(IFX_Pause* pPause) {
393 if (!m_DestWidth) { 399 if (!m_DestWidth)
394 return 0; 400 return FALSE;
395 } 401
396 if (m_pSource->SkipToScanline(m_CurRow, pPause)) { 402 if (m_pSource->SkipToScanline(m_CurRow, pPause))
397 return TRUE; 403 return TRUE;
398 } 404
399 int Bpp = m_DestBpp / 8; 405 int Bpp = m_DestBpp / 8;
400 int rows_to_go = FX_STRECH_PAUSE_ROWS; 406 static const int kStrechPauseRows = 10;
407 int rows_to_go = kStrechPauseRows;
401 for (; m_CurRow < m_SrcClip.bottom; m_CurRow++) { 408 for (; m_CurRow < m_SrcClip.bottom; m_CurRow++) {
402 if (rows_to_go == 0) { 409 if (rows_to_go == 0) {
403 if (pPause && pPause->NeedToPauseNow()) { 410 if (pPause && pPause->NeedToPauseNow())
404 return TRUE; 411 return TRUE;
405 } 412
406 rows_to_go = FX_STRECH_PAUSE_ROWS; 413 rows_to_go = kStrechPauseRows;
407 } 414 }
415
408 const uint8_t* src_scan = m_pSource->GetScanline(m_CurRow); 416 const uint8_t* src_scan = m_pSource->GetScanline(m_CurRow);
409 uint8_t* dest_scan = 417 uint8_t* dest_scan =
410 m_pInterBuf + (m_CurRow - m_SrcClip.top) * m_InterPitch; 418 m_pInterBuf + (m_CurRow - m_SrcClip.top) * m_InterPitch;
411 const uint8_t* src_scan_mask = nullptr; 419 const uint8_t* src_scan_mask = nullptr;
412 uint8_t* dest_scan_mask = nullptr; 420 uint8_t* dest_scan_mask = nullptr;
413 if (m_pExtraAlphaBuf) { 421 if (m_pExtraAlphaBuf) {
414 src_scan_mask = m_pSource->m_pAlphaMask->GetScanline(m_CurRow); 422 src_scan_mask = m_pSource->m_pAlphaMask->GetScanline(m_CurRow);
415 dest_scan_mask = 423 dest_scan_mask =
416 m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch; 424 m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch;
417 } 425 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 619 }
612 dest_scan += Bpp - 3; 620 dest_scan += Bpp - 3;
613 } 621 }
614 break; 622 break;
615 } 623 }
616 } 624 }
617 rows_to_go--; 625 rows_to_go--;
618 } 626 }
619 return FALSE; 627 return FALSE;
620 } 628 }
629
621 void CStretchEngine::StretchVert() { 630 void CStretchEngine::StretchVert() {
622 if (m_DestHeight == 0) { 631 if (m_DestHeight == 0)
623 return; 632 return;
624 } 633
625 CWeightTable table; 634 CWeightTable table;
626 table.Calc(m_DestHeight, m_DestClip.top, m_DestClip.bottom, m_SrcHeight, 635 table.Calc(m_DestHeight, m_DestClip.top, m_DestClip.bottom, m_SrcHeight,
627 m_SrcClip.top, m_SrcClip.bottom, m_Flags); 636 m_SrcClip.top, m_SrcClip.bottom, m_Flags);
628 if (!table.m_pWeightTables) { 637 if (!table.m_pWeightTables)
629 return; 638 return;
630 } 639
631 int DestBpp = m_DestBpp / 8; 640 int DestBpp = m_DestBpp / 8;
632 for (int row = m_DestClip.top; row < m_DestClip.bottom; row++) { 641 for (int row = m_DestClip.top; row < m_DestClip.bottom; row++) {
633 unsigned char* dest_scan = m_pDestScanline; 642 unsigned char* dest_scan = m_pDestScanline;
634 unsigned char* dest_sacn_mask = m_pDestMaskScanline; 643 unsigned char* dest_sacn_mask = m_pDestMaskScanline;
635 PixelWeight* pPixelWeights = table.GetPixelWeight(row); 644 PixelWeight* pPixelWeights = table.GetPixelWeight(row);
636 switch (m_TransMethod) { 645 switch (m_TransMethod) {
637 case 1: 646 case 1:
638 case 2: 647 case 2:
639 case 3: { 648 case 3: {
640 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 649 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 result_width); 929 result_width);
921 if (m_pMaskScanline) { 930 if (m_pMaskScanline) {
922 m_pSource->m_pAlphaMask->DownSampleScanline( 931 m_pSource->m_pAlphaMask->DownSampleScanline(
923 src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX, 932 src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX,
924 m_ClipRect.left, result_width); 933 m_ClipRect.left, result_width);
925 } 934 }
926 m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get()); 935 m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get());
927 } 936 }
928 return FALSE; 937 return FALSE;
929 } 938 }
OLDNEW
« no previous file with comments | « core/fxge/dib/dib_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698