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

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_Image.cpp

Issue 1237723002: Merge to M44: Fix Heap Overflow in CJBig2_Image::expand (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 | « 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 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 "JBig2_Image.h" 7 #include <limits.h>
8 #include "../../../include/fxcrt/fx_basic.h" 8 #include "../../../include/fxcrt/fx_basic.h"
9 #include "../../../include/fxcrt/fx_coordinates.h" 9 #include "../../../include/fxcrt/fx_coordinates.h"
10 #include <limits.h> 10 #include "../../../src/fxcrt/fx_safe_types.h"
11 #include "JBig2_Image.h"
12
11 CJBig2_Image::CJBig2_Image(FX_INT32 w, FX_INT32 h) 13 CJBig2_Image::CJBig2_Image(FX_INT32 w, FX_INT32 h)
12 { 14 {
13 m_nWidth = w; 15 m_nWidth = w;
14 m_nHeight = h; 16 m_nHeight = h;
15 if (m_nWidth <= 0 || m_nHeight <= 0 || m_nWidth > INT_MAX - 31) { 17 if (m_nWidth <= 0 || m_nHeight <= 0 || m_nWidth > INT_MAX - 31) {
16 m_pData = NULL; 18 m_pData = NULL;
17 m_bNeedFree = FALSE; 19 m_bNeedFree = FALSE;
18 return; 20 return;
19 } 21 }
20 m_nStride = ((w + 31) >> 5) << 2; 22 m_nStride = ((w + 31) >> 5) << 2;
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 pLineDst += pImage->m_nStride; 763 pLineDst += pImage->m_nStride;
762 } 764 }
763 } 765 }
764 return pImage; 766 return pImage;
765 } 767 }
766 void CJBig2_Image::expand(FX_INT32 h, FX_BOOL v) 768 void CJBig2_Image::expand(FX_INT32 h, FX_BOOL v)
767 { 769 {
768 if (!m_pData) { 770 if (!m_pData) {
769 return; 771 return;
770 } 772 }
771 m_pData = (FX_BYTE*)m_pModule->JBig2_Realloc(m_pData, h * m_nStride); 773 FX_SAFE_DWORD safeMemSize = pdfium::base::checked_cast<FX_DWORD>(h);
774 safeMemSize *= pdfium::base::checked_cast<FX_DWORD>(m_nStride);
775 if (!safeMemSize.IsValid()) {
776 return;
777 }
778 m_pData = (FX_BYTE*)m_pModule->JBig2_Realloc(m_pData, safeMemSize.ValueOrDie ());
772 if(h > m_nHeight) { 779 if(h > m_nHeight) {
773 JBIG2_memset(m_pData + m_nHeight * m_nStride, v ? 0xff : 0, (h - m_nHeig ht)*m_nStride); 780 JBIG2_memset(m_pData + m_nHeight * m_nStride, v ? 0xff : 0, (h - m_nHeig ht)*m_nStride);
774 } 781 }
775 m_nHeight = h; 782 m_nHeight = h;
776 } 783 }
777 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image *pDst, FX_INT32 x, FX_INT32 y, JBig2ComposeOp op) 784 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image *pDst, FX_INT32 x, FX_INT32 y, JBig2ComposeOp op)
778 { 785 {
779 FX_INT32 xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0, 786 FX_INT32 xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0,
780 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0; 787 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0;
781 788
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 dp[2] = (FX_BYTE)(tmp >> 8); 1614 dp[2] = (FX_BYTE)(tmp >> 8);
1608 dp[3] = (FX_BYTE)tmp; 1615 dp[3] = (FX_BYTE)tmp;
1609 } 1616 }
1610 lineSrc += m_nStride; 1617 lineSrc += m_nStride;
1611 lineDst += pDst->m_nStride; 1618 lineDst += pDst->m_nStride;
1612 } 1619 }
1613 } 1620 }
1614 } 1621 }
1615 return 1; 1622 return 1;
1616 } 1623 }
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