From e61e2f3d34efee51b69838646dd4e7462989ca08 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 20 Apr 2018 05:24:25 +0000 Subject: Revert "Do validation earlier in CPDF_SampledFunc::v_Init()." This reverts commit 54e6da1ee793f436341dfcdc4e0c26b0658d1928. Reason for revert: Checks not ordered correctly. Original change's description: > Do validation earlier in CPDF_SampledFunc::v_Init(). > > Change-Id: Ib44b39aea419230f73583caf69313a2f92557397 > Reviewed-on: https://pdfium-review.googlesource.com/30932 > Commit-Queue: Lei Zhang > Reviewed-by: Henrique Nakashima TBR=thestig@chromium.org,hnakashima@chromium.org Change-Id: I133ca5add12c173dd05ef995b5834c3058d814cd No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://pdfium-review.googlesource.com/31050 Reviewed-by: Lei Zhang Commit-Queue: Lei Zhang --- core/fpdfapi/page/cpdf_sampledfunc.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/fpdfapi/page/cpdf_sampledfunc.cpp b/core/fpdfapi/page/cpdf_sampledfunc.cpp index 21a1db4a97..cdedc862bb 100644 --- a/core/fpdfapi/page/cpdf_sampledfunc.cpp +++ b/core/fpdfapi/page/cpdf_sampledfunc.cpp @@ -50,21 +50,10 @@ bool CPDF_SampledFunc::v_Init(CPDF_Object* pObj, if (!IsValidBitsPerSample(m_nBitsPerSample)) return false; - FX_SAFE_UINT32 nTotalSampleBits = 1; - nTotalSampleBits *= m_nBitsPerSample; - nTotalSampleBits *= m_nOutputs; - FX_SAFE_UINT32 nTotalSampleBytes = nTotalSampleBits; - nTotalSampleBytes += 7; - nTotalSampleBytes /= 8; - if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0) - return false; - m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); m_pSampleStream = pdfium::MakeRetain(pStream); m_pSampleStream->LoadAllDataFiltered(); - if (nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) - return false; - + FX_SAFE_UINT32 nTotalSampleBits = 1; m_EncodeInfo.resize(m_nInputs); for (uint32_t i = 0; i < m_nInputs; i++) { m_EncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; @@ -80,6 +69,15 @@ bool CPDF_SampledFunc::v_Init(CPDF_Object* pObj, m_EncodeInfo[i].sizes == 1 ? 1 : (float)m_EncodeInfo[i].sizes - 1; } } + nTotalSampleBits *= m_nBitsPerSample; + nTotalSampleBits *= m_nOutputs; + FX_SAFE_UINT32 nTotalSampleBytes = nTotalSampleBits; + nTotalSampleBytes += 7; + nTotalSampleBytes /= 8; + if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 || + nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) { + return false; + } m_DecodeInfo.resize(m_nOutputs); for (uint32_t i = 0; i < m_nOutputs; i++) { if (pDecode) { -- cgit v1.2.3