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

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

Issue 1241493002: Merge to M44: Integer 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 <limits.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 "../../../src/fxcrt/fx_safe_types.h" 10 #include "../../../src/fxcrt/fx_safe_types.h"
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 pDst[3] = (FX_BYTE)wTmp; 760 pDst[3] = (FX_BYTE)wTmp;
761 } 761 }
762 pLineSrc += m_nStride; 762 pLineSrc += m_nStride;
763 pLineDst += pImage->m_nStride; 763 pLineDst += pImage->m_nStride;
764 } 764 }
765 } 765 }
766 return pImage; 766 return pImage;
767 } 767 }
768 void CJBig2_Image::expand(FX_INT32 h, FX_BOOL v) 768 void CJBig2_Image::expand(FX_INT32 h, FX_BOOL v)
769 { 769 {
770 if (!m_pData) { 770 if (!m_pData || h <= m_nHeight) {
771 return; 771 return;
772 } 772 }
773 FX_SAFE_DWORD safeMemSize = pdfium::base::checked_cast<FX_DWORD>(h); 773 FX_DWORD dwH = pdfium::base::checked_cast<FX_DWORD>(h);
774 safeMemSize *= pdfium::base::checked_cast<FX_DWORD>(m_nStride); 774 FX_DWORD dwStride = pdfium::base::checked_cast<FX_DWORD>(m_nStride);
775 FX_DWORD dwHeight = pdfium::base::checked_cast<FX_DWORD>(m_nHeight);
776 FX_SAFE_DWORD safeMemSize = dwH;
777 safeMemSize *= dwStride;
775 if (!safeMemSize.IsValid()) { 778 if (!safeMemSize.IsValid()) {
776 return; 779 return;
777 } 780 }
781 //The guaranteed reallocated memory is to be < 4GB (unsigned int).
778 m_pData = (FX_BYTE*)m_pModule->JBig2_Realloc(m_pData, safeMemSize.ValueOrDie ()); 782 m_pData = (FX_BYTE*)m_pModule->JBig2_Realloc(m_pData, safeMemSize.ValueOrDie ());
779 if(h > m_nHeight) { 783 //The result of dwHeight * dwStride doesn't overflow after the
780 JBIG2_memset(m_pData + m_nHeight * m_nStride, v ? 0xff : 0, (h - m_nHeig ht)*m_nStride); 784 //checking of safeMemSize.
781 } 785 //The same as the result of (dwH - dwHeight) * dwStride) because
786 //dwH - dwHeight is always less than dwH(h) which is checked in
787 //the calculation of dwH * dwStride.
788 JBIG2_memset(m_pData + dwHeight * dwStride, v ? 0xff : 0, (dwH - dwHeight) * dwStride);
782 m_nHeight = h; 789 m_nHeight = h;
783 } 790 }
784 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image *pDst, FX_INT32 x, FX_INT32 y, JBig2ComposeOp op) 791 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image *pDst, FX_INT32 x, FX_INT32 y, JBig2ComposeOp op)
785 { 792 {
786 FX_INT32 xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0, 793 FX_INT32 xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0,
787 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0; 794 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0;
788 795
789 FX_DWORD s1 = 0, d1 = 0, d2 = 0, shift = 0, shift1 = 0, shift2 = 0, 796 FX_DWORD s1 = 0, d1 = 0, d2 = 0, shift = 0, shift1 = 0, shift2 = 0,
790 tmp = 0, tmp1 = 0, tmp2 = 0, maskL = 0, maskR = 0, maskM = 0; 797 tmp = 0, tmp1 = 0, tmp2 = 0, maskL = 0, maskR = 0, maskM = 0;
791 798
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 dp[2] = (FX_BYTE)(tmp >> 8); 1621 dp[2] = (FX_BYTE)(tmp >> 8);
1615 dp[3] = (FX_BYTE)tmp; 1622 dp[3] = (FX_BYTE)tmp;
1616 } 1623 }
1617 lineSrc += m_nStride; 1624 lineSrc += m_nStride;
1618 lineDst += pDst->m_nStride; 1625 lineDst += pDst->m_nStride;
1619 } 1626 }
1620 } 1627 }
1621 } 1628 }
1622 return 1; 1629 return 1;
1623 } 1630 }
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