diff options
-rw-r--r-- | core/fdrm/crypto/fx_crypt.cpp | 48 | ||||
-rw-r--r-- | core/fdrm/crypto/fx_crypt_sha.cpp | 94 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_func.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp | 23 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_parser.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 24 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec.cpp | 2 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpeg.cpp | 2 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpx_opj.cpp | 2 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Image.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/include/fx_safe_types.h | 2 |
14 files changed, 108 insertions, 107 deletions
diff --git a/core/fdrm/crypto/fx_crypt.cpp b/core/fdrm/crypto/fx_crypt.cpp index f3665060f8..9e10f369ca 100644 --- a/core/fdrm/crypto/fx_crypt.cpp +++ b/core/fdrm/crypto/fx_crypt.cpp @@ -62,14 +62,14 @@ struct md5_context { uint32_t state[4]; uint8_t buffer[64]; }; -#define GET_FX_DWORD(n, b, i) \ +#define GET_UINT32(n, b, i) \ { \ (n) = (uint32_t)((uint8_t*)b)[(i)] | \ (((uint32_t)((uint8_t*)b)[(i) + 1]) << 8) | \ (((uint32_t)((uint8_t*)b)[(i) + 2]) << 16) | \ (((uint32_t)((uint8_t*)b)[(i) + 3]) << 24); \ } -#define PUT_FX_DWORD(n, b, i) \ +#define PUT_UINT32(n, b, i) \ { \ (((uint8_t*)b)[(i)]) = (uint8_t)(((n)) & 0xFF); \ (((uint8_t*)b)[(i) + 1]) = (uint8_t)(((n) >> 8) & 0xFF); \ @@ -78,22 +78,22 @@ struct md5_context { } void md5_process(struct md5_context* ctx, const uint8_t data[64]) { uint32_t A, B, C, D, X[16]; - GET_FX_DWORD(X[0], data, 0); - GET_FX_DWORD(X[1], data, 4); - GET_FX_DWORD(X[2], data, 8); - GET_FX_DWORD(X[3], data, 12); - GET_FX_DWORD(X[4], data, 16); - GET_FX_DWORD(X[5], data, 20); - GET_FX_DWORD(X[6], data, 24); - GET_FX_DWORD(X[7], data, 28); - GET_FX_DWORD(X[8], data, 32); - GET_FX_DWORD(X[9], data, 36); - GET_FX_DWORD(X[10], data, 40); - GET_FX_DWORD(X[11], data, 44); - GET_FX_DWORD(X[12], data, 48); - GET_FX_DWORD(X[13], data, 52); - GET_FX_DWORD(X[14], data, 56); - GET_FX_DWORD(X[15], data, 60); + GET_UINT32(X[0], data, 0); + GET_UINT32(X[1], data, 4); + GET_UINT32(X[2], data, 8); + GET_UINT32(X[3], data, 12); + GET_UINT32(X[4], data, 16); + GET_UINT32(X[5], data, 20); + GET_UINT32(X[6], data, 24); + GET_UINT32(X[7], data, 28); + GET_UINT32(X[8], data, 32); + GET_UINT32(X[9], data, 36); + GET_UINT32(X[10], data, 40); + GET_UINT32(X[11], data, 44); + GET_UINT32(X[12], data, 48); + GET_UINT32(X[13], data, 52); + GET_UINT32(X[14], data, 56); + GET_UINT32(X[15], data, 60); #define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) #define P(a, b, c, d, k, s, t) \ { \ @@ -226,16 +226,16 @@ void CRYPT_MD5Finish(void* pctx, uint8_t digest[16]) { struct md5_context* ctx = (struct md5_context*)pctx; uint32_t last, padn; uint8_t msglen[8]; - PUT_FX_DWORD(ctx->total[0], msglen, 0); - PUT_FX_DWORD(ctx->total[1], msglen, 4); + PUT_UINT32(ctx->total[0], msglen, 0); + PUT_UINT32(ctx->total[1], msglen, 4); last = (ctx->total[0] >> 3) & 0x3F; padn = (last < 56) ? (56 - last) : (120 - last); CRYPT_MD5Update(ctx, md5_padding, padn); CRYPT_MD5Update(ctx, msglen, 8); - PUT_FX_DWORD(ctx->state[0], digest, 0); - PUT_FX_DWORD(ctx->state[1], digest, 4); - PUT_FX_DWORD(ctx->state[2], digest, 8); - PUT_FX_DWORD(ctx->state[3], digest, 12); + PUT_UINT32(ctx->state[0], digest, 0); + PUT_UINT32(ctx->state[1], digest, 4); + PUT_UINT32(ctx->state[2], digest, 8); + PUT_UINT32(ctx->state[3], digest, 12); } void CRYPT_MD5Generate(const uint8_t* input, uint32_t length, diff --git a/core/fdrm/crypto/fx_crypt_sha.cpp b/core/fdrm/crypto/fx_crypt_sha.cpp index 28b3ce3739..ed5da2f504 100644 --- a/core/fdrm/crypto/fx_crypt_sha.cpp +++ b/core/fdrm/crypto/fx_crypt_sha.cpp @@ -159,12 +159,12 @@ typedef struct { uint32_t state[8]; uint8_t buffer[64]; } sha256_context; -#define GET_FX_DWORD(n, b, i) \ +#define GET_UINT32(n, b, i) \ { \ (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | \ ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ } -#define PUT_FX_DWORD(n, b, i) \ +#define PUT_UINT32(n, b, i) \ { \ (b)[(i)] = (uint8_t)((n) >> 24); \ (b)[(i) + 1] = (uint8_t)((n) >> 16); \ @@ -187,22 +187,22 @@ void CRYPT_SHA256Start(void* context) { static void sha256_process(sha256_context* ctx, const uint8_t data[64]) { uint32_t temp1, temp2, W[64]; uint32_t A, B, C, D, E, F, G, H; - GET_FX_DWORD(W[0], data, 0); - GET_FX_DWORD(W[1], data, 4); - GET_FX_DWORD(W[2], data, 8); - GET_FX_DWORD(W[3], data, 12); - GET_FX_DWORD(W[4], data, 16); - GET_FX_DWORD(W[5], data, 20); - GET_FX_DWORD(W[6], data, 24); - GET_FX_DWORD(W[7], data, 28); - GET_FX_DWORD(W[8], data, 32); - GET_FX_DWORD(W[9], data, 36); - GET_FX_DWORD(W[10], data, 40); - GET_FX_DWORD(W[11], data, 44); - GET_FX_DWORD(W[12], data, 48); - GET_FX_DWORD(W[13], data, 52); - GET_FX_DWORD(W[14], data, 56); - GET_FX_DWORD(W[15], data, 60); + GET_UINT32(W[0], data, 0); + GET_UINT32(W[1], data, 4); + GET_UINT32(W[2], data, 8); + GET_UINT32(W[3], data, 12); + GET_UINT32(W[4], data, 16); + GET_UINT32(W[5], data, 20); + GET_UINT32(W[6], data, 24); + GET_UINT32(W[7], data, 28); + GET_UINT32(W[8], data, 32); + GET_UINT32(W[9], data, 36); + GET_UINT32(W[10], data, 40); + GET_UINT32(W[11], data, 44); + GET_UINT32(W[12], data, 48); + GET_UINT32(W[13], data, 52); + GET_UINT32(W[14], data, 56); + GET_UINT32(W[15], data, 60); #define SHR(x, n) ((x & 0xFFFFFFFF) >> n) #define ROTR(x, n) (SHR(x, n) | (x << (32 - n))) #define S0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) @@ -340,20 +340,20 @@ void CRYPT_SHA256Finish(void* context, uint8_t digest[32]) { uint8_t msglen[8]; high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); low = (ctx->total[0] << 3); - PUT_FX_DWORD(high, msglen, 0); - PUT_FX_DWORD(low, msglen, 4); + PUT_UINT32(high, msglen, 0); + PUT_UINT32(low, msglen, 4); last = ctx->total[0] & 0x3F; padn = (last < 56) ? (56 - last) : (120 - last); CRYPT_SHA256Update(ctx, sha256_padding, padn); CRYPT_SHA256Update(ctx, msglen, 8); - PUT_FX_DWORD(ctx->state[0], digest, 0); - PUT_FX_DWORD(ctx->state[1], digest, 4); - PUT_FX_DWORD(ctx->state[2], digest, 8); - PUT_FX_DWORD(ctx->state[3], digest, 12); - PUT_FX_DWORD(ctx->state[4], digest, 16); - PUT_FX_DWORD(ctx->state[5], digest, 20); - PUT_FX_DWORD(ctx->state[6], digest, 24); - PUT_FX_DWORD(ctx->state[7], digest, 28); + PUT_UINT32(ctx->state[0], digest, 0); + PUT_UINT32(ctx->state[1], digest, 4); + PUT_UINT32(ctx->state[2], digest, 8); + PUT_UINT32(ctx->state[3], digest, 12); + PUT_UINT32(ctx->state[4], digest, 16); + PUT_UINT32(ctx->state[5], digest, 20); + PUT_UINT32(ctx->state[6], digest, 24); + PUT_UINT32(ctx->state[7], digest, 28); } void CRYPT_SHA256Generate(const uint8_t* data, uint32_t size, @@ -468,7 +468,7 @@ static const FX_CHAR* constants[] = { ((uint64_t)(b)[(i) + 4] << 24) | ((uint64_t)(b)[(i) + 5] << 16) | \ ((uint64_t)(b)[(i) + 6] << 8) | ((uint64_t)(b)[(i) + 7]); \ } -#define PUT_FX_64DWORD(n, b, i) \ +#define PUT_UINT64(n, b, i) \ { \ (b)[(i)] = (uint8_t)((n) >> 56); \ (b)[(i) + 1] = (uint8_t)((n) >> 48); \ @@ -582,18 +582,18 @@ void CRYPT_SHA384Finish(void* context, uint8_t digest[48]) { uint64_t high, low; high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); low = (ctx->total[0] << 3); - PUT_FX_64DWORD(high, msglen, 0); - PUT_FX_64DWORD(low, msglen, 8); + PUT_UINT64(high, msglen, 0); + PUT_UINT64(low, msglen, 8); last = (uint32_t)ctx->total[0] & 0x7F; padn = (last < 112) ? (112 - last) : (240 - last); CRYPT_SHA384Update(ctx, sha384_padding, padn); CRYPT_SHA384Update(ctx, msglen, 16); - PUT_FX_64DWORD(ctx->state[0], digest, 0); - PUT_FX_64DWORD(ctx->state[1], digest, 8); - PUT_FX_64DWORD(ctx->state[2], digest, 16); - PUT_FX_64DWORD(ctx->state[3], digest, 24); - PUT_FX_64DWORD(ctx->state[4], digest, 32); - PUT_FX_64DWORD(ctx->state[5], digest, 40); + PUT_UINT64(ctx->state[0], digest, 0); + PUT_UINT64(ctx->state[1], digest, 8); + PUT_UINT64(ctx->state[2], digest, 16); + PUT_UINT64(ctx->state[3], digest, 24); + PUT_UINT64(ctx->state[4], digest, 32); + PUT_UINT64(ctx->state[5], digest, 40); } void CRYPT_SHA384Generate(const uint8_t* data, uint32_t size, @@ -629,20 +629,20 @@ void CRYPT_SHA512Finish(void* context, uint8_t digest[64]) { uint64_t high, low; high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); low = (ctx->total[0] << 3); - PUT_FX_64DWORD(high, msglen, 0); - PUT_FX_64DWORD(low, msglen, 8); + PUT_UINT64(high, msglen, 0); + PUT_UINT64(low, msglen, 8); last = (uint32_t)ctx->total[0] & 0x7F; padn = (last < 112) ? (112 - last) : (240 - last); CRYPT_SHA512Update(ctx, sha384_padding, padn); CRYPT_SHA512Update(ctx, msglen, 16); - PUT_FX_64DWORD(ctx->state[0], digest, 0); - PUT_FX_64DWORD(ctx->state[1], digest, 8); - PUT_FX_64DWORD(ctx->state[2], digest, 16); - PUT_FX_64DWORD(ctx->state[3], digest, 24); - PUT_FX_64DWORD(ctx->state[4], digest, 32); - PUT_FX_64DWORD(ctx->state[5], digest, 40); - PUT_FX_64DWORD(ctx->state[6], digest, 48); - PUT_FX_64DWORD(ctx->state[7], digest, 56); + PUT_UINT64(ctx->state[0], digest, 0); + PUT_UINT64(ctx->state[1], digest, 8); + PUT_UINT64(ctx->state[2], digest, 16); + PUT_UINT64(ctx->state[3], digest, 24); + PUT_UINT64(ctx->state[4], digest, 32); + PUT_UINT64(ctx->state[5], digest, 40); + PUT_UINT64(ctx->state[6], digest, 48); + PUT_UINT64(ctx->state[7], digest, 56); } void CRYPT_SHA512Generate(const uint8_t* data, uint32_t size, diff --git a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp index ebd6811da8..b00ab73af1 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp @@ -541,7 +541,7 @@ FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { m_pSampleStream = new CPDF_StreamAcc; m_pSampleStream->LoadAllData(pStream, FALSE); m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs); - FX_SAFE_DWORD nTotalSampleBits = 1; + FX_SAFE_UINT32 nTotalSampleBits = 1; for (uint32_t i = 0; i < m_nInputs; i++) { m_pEncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; if (!pSize && i == 0) @@ -560,7 +560,7 @@ FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { } nTotalSampleBits *= m_nBitsPerSample; nTotalSampleBits *= m_nOutputs; - FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits; + FX_SAFE_UINT32 nTotalSampleBytes = nTotalSampleBits; nTotalSampleBytes += 7; nTotalSampleBytes /= 8; if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 || diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index a3c88c00df..183573aaa3 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -797,7 +797,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) { if (m_InternalStage == STAGE_GETCONTENT) { if (m_CurrentOffset == m_nStreams) { if (!m_StreamArray.empty()) { - FX_SAFE_DWORD safeSize = 0; + FX_SAFE_UINT32 safeSize = 0; for (const auto& stream : m_StreamArray) { safeSize += stream->GetSize(); safeSize += 1; diff --git a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp index 15f98b26b9..68f8b88557 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp @@ -1507,7 +1507,7 @@ IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( return DataAvailable; if (!m_bMainXRefLoadTried) { - FX_SAFE_DWORD data_size = m_dwFileLen; + FX_SAFE_UINT32 data_size = m_dwFileLen; data_size -= m_dwLastXRefOffset; if (!data_size.IsValid()) return DataError; diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp index 18687e5fb7..3e08ead9ff 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp @@ -16,7 +16,7 @@ namespace { bool CanReadFromBitStream(const CFX_BitStream* hStream, - const FX_SAFE_DWORD& num_bits) { + const FX_SAFE_UINT32& num_bits) { return num_bits.IsValid() && hStream->BitsRemaining() >= num_bits.ValueOrDie(); } @@ -60,7 +60,7 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { // Item 2: The location of the first page's page object. uint32_t dwFirstObjLoc = hStream->GetBits(32); if (dwFirstObjLoc > static_cast<uint32_t>(nStreamOffset)) { - FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<uint32_t>(nStreamLen); + FX_SAFE_UINT32 safeLoc = pdfium::base::checked_cast<uint32_t>(nStreamLen); safeLoc += dwFirstObjLoc; if (!safeLoc.IsValid()) return FALSE; @@ -107,13 +107,13 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { if (nPages < 1) return FALSE; - FX_SAFE_DWORD required_bits = dwDeltaObjectsBits; + FX_SAFE_UINT32 required_bits = dwDeltaObjectsBits; required_bits *= pdfium::base::checked_cast<uint32_t>(nPages); if (!CanReadFromBitStream(hStream, required_bits)) return FALSE; for (int i = 0; i < nPages; ++i) { - FX_SAFE_DWORD safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits); + FX_SAFE_UINT32 safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits); safeDeltaObj += dwObjLeastNum; if (!safeDeltaObj.IsValid()) return FALSE; @@ -128,7 +128,7 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { CFX_ArrayTemplate<uint32_t> dwPageLenArray; for (int i = 0; i < nPages; ++i) { - FX_SAFE_DWORD safePageLen = hStream->GetBits(dwDeltaPageLenBits); + FX_SAFE_UINT32 safePageLen = hStream->GetBits(dwDeltaPageLenBits); safePageLen += dwPageLeastLen; if (!safePageLen.IsValid()) return FALSE; @@ -191,7 +191,7 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { hStream->ByteAlign(); for (int i = 0; i < nPages; i++) { - FX_SAFE_DWORD safeSize = m_dwNSharedObjsArray[i]; + FX_SAFE_UINT32 safeSize = m_dwNSharedObjsArray[i]; safeSize *= dwSharedNumeratorBits; if (!CanReadFromBitStream(hStream, safeSize)) return FALSE; @@ -200,7 +200,8 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { } hStream->ByteAlign(); - FX_SAFE_DWORD safeTotalPageLen = pdfium::base::checked_cast<uint32_t>(nPages); + FX_SAFE_UINT32 safeTotalPageLen = + pdfium::base::checked_cast<uint32_t>(nPages); safeTotalPageLen *= dwDeltaPageLenBits; if (!CanReadFromBitStream(hStream, safeTotalPageLen)) return FALSE; @@ -220,7 +221,7 @@ FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, if (nStreamOffset < 0 || nStreamLen < 1) return FALSE; - FX_SAFE_DWORD bit_offset = offset; + FX_SAFE_UINT32 bit_offset = offset; bit_offset *= 8; if (!bit_offset.IsValid() || hStream->GetPos() > bit_offset.ValueOrDie()) return FALSE; @@ -263,14 +264,14 @@ FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, uint32_t dwPrevObjLen = 0; uint32_t dwCurObjLen = 0; - FX_SAFE_DWORD required_bits = dwSharedObjTotal; + FX_SAFE_UINT32 required_bits = dwSharedObjTotal; required_bits *= dwDeltaGroupLen; if (!CanReadFromBitStream(hStream, required_bits)) return FALSE; for (uint32_t i = 0; i < dwSharedObjTotal; ++i) { dwPrevObjLen = dwCurObjLen; - FX_SAFE_DWORD safeObjLen = hStream->GetBits(dwDeltaGroupLen); + FX_SAFE_UINT32 safeObjLen = hStream->GetBits(dwDeltaGroupLen); safeObjLen += dwGroupLeastLen; if (!safeObjLen.IsValid()) return FALSE; @@ -281,7 +282,7 @@ FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, if (i == 0) m_szSharedObjOffsetArray.push_back(m_szFirstPageObjOffset); } else { - FX_SAFE_DWORD safeObjNum = dwFirstSharedObjNum; + FX_SAFE_UINT32 safeObjNum = dwFirstSharedObjNum; safeObjNum += i - m_nFirstPageSharedObjs; if (!safeObjNum.IsValid()) return FALSE; diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index 73ca71ef1a..15af1ca5c7 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -1012,7 +1012,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { } CFX_ArrayTemplate<uint32_t> WidthArray; - FX_SAFE_DWORD dwAccWidth = 0; + FX_SAFE_UINT32 dwAccWidth = 0; for (uint32_t i = 0; i < pArray->GetCount(); i++) { WidthArray.Add(pArray->GetIntegerAt(i)); dwAccWidth += WidthArray[i]; @@ -1039,7 +1039,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { pdfium::base::checked_cast<uint32_t, int32_t>(startnum); uint32_t count = pdfium::base::checked_cast<uint32_t, int32_t>(arrIndex[i].second); - FX_SAFE_DWORD dwCaculatedSize = segindex; + FX_SAFE_UINT32 dwCaculatedSize = segindex; dwCaculatedSize += count; dwCaculatedSize *= totalWidth; if (!dwCaculatedSize.IsValid() || @@ -1048,7 +1048,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { } const uint8_t* segstart = pData + segindex * totalWidth; - FX_SAFE_DWORD dwMaxObjNum = startnum; + FX_SAFE_UINT32 dwMaxObjNum = startnum; dwMaxObjNum += count; uint32_t dwV5Size = m_ObjectInfo.empty() ? 0 : GetLastObjNum() + 1; if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index 167570ba92..16c55c57af 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -931,7 +931,7 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, } CFX_FixedBufGrow<FX_FLOAT, 8> float_array(comps); FX_FLOAT* pFloats = float_array; - FX_SAFE_DWORD num_floats = comps; + FX_SAFE_UINT32 num_floats = comps; num_floats *= sizeof(FX_FLOAT); if (!num_floats.IsValid()) { return NULL; diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 61e47036fa..db1b8ccd71 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -38,8 +38,8 @@ unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { return (byte >> (8 - nbits - (bitpos % 8))) & ((1 << nbits) - 1); } -FX_SAFE_DWORD CalculatePitch8(uint32_t bpc, uint32_t components, int width) { - FX_SAFE_DWORD pitch = bpc; +FX_SAFE_UINT32 CalculatePitch8(uint32_t bpc, uint32_t components, int width) { + FX_SAFE_UINT32 pitch = bpc; pitch *= components; pitch *= width; pitch += 7; @@ -47,8 +47,8 @@ FX_SAFE_DWORD CalculatePitch8(uint32_t bpc, uint32_t components, int width) { return pitch; } -FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { - FX_SAFE_DWORD pitch = bpp; +FX_SAFE_UINT32 CalculatePitch32(int bpp, int width) { + FX_SAFE_UINT32 pitch = bpp; pitch *= width; pitch += 31; pitch /= 32; // quantized to number of 32-bit words. @@ -177,7 +177,7 @@ FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { return FALSE; } - FX_SAFE_DWORD src_size = + FX_SAFE_UINT32 src_size = CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; if (!src_size.IsValid()) { return FALSE; @@ -202,7 +202,7 @@ FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, } else { m_bpp = 24; } - FX_SAFE_DWORD pitch = CalculatePitch32(m_bpp, m_Width); + FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width); if (!pitch.IsValid()) { return FALSE; } @@ -246,7 +246,7 @@ int CPDF_DIBSource::ContinueToLoadMask() { if (!m_bpc || !m_nComponents) { return 0; } - FX_SAFE_DWORD pitch = CalculatePitch32(m_bpp, m_Width); + FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width); if (!pitch.IsValid()) { return 0; } @@ -299,7 +299,7 @@ int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { return 0; } - FX_SAFE_DWORD src_size = + FX_SAFE_UINT32 src_size = CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; if (!src_size.IsValid()) { return 0; @@ -611,12 +611,12 @@ int CPDF_DIBSource::CreateDecoder() { if (!m_pDecoder) return 0; - FX_SAFE_DWORD requested_pitch = + FX_SAFE_UINT32 requested_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); if (!requested_pitch.IsValid()) { return 0; } - FX_SAFE_DWORD provided_pitch = CalculatePitch8( + FX_SAFE_UINT32 provided_pitch = CalculatePitch8( m_pDecoder->GetBPC(), m_pDecoder->CountComps(), m_pDecoder->GetWidth()); if (!provided_pitch.IsValid()) { return 0; @@ -1030,7 +1030,7 @@ const uint8_t* CPDF_DIBSource::GetScanline(int line) const { if (m_bpc == 0) { return nullptr; } - FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); + FX_SAFE_UINT32 src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); if (!src_pitch.IsValid()) return nullptr; uint32_t src_pitch_value = src_pitch.ValueOrDie(); @@ -1176,7 +1176,7 @@ void CPDF_DIBSource::DownSampleScanline(int line, } uint32_t src_width = m_Width; - FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); + FX_SAFE_UINT32 pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); if (!pitch.IsValid()) return; diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp index 79e5da27c8..ef9414dbe5 100644 --- a/core/fxcodec/codec/fx_codec.cpp +++ b/core/fxcodec/codec/fx_codec.cpp @@ -294,7 +294,7 @@ FX_BOOL CCodec_RLScanlineDecoder::Create(const uint8_t* src_buf, m_nComps = nComps; m_bpc = bpc; // Aligning the pitch to 4 bytes requires an integer overflow check. - FX_SAFE_DWORD pitch = width; + FX_SAFE_UINT32 pitch = width; pitch *= nComps; pitch *= bpc; pitch += 31; diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp index ce39038438..33ebf1ba20 100644 --- a/core/fxcodec/codec/fx_codec_jpeg.cpp +++ b/core/fxcodec/codec/fx_codec_jpeg.cpp @@ -142,7 +142,7 @@ static void _JpegEncode(const CFX_DIBSource* pSource, uint32_t pitch = pSource->GetPitch(); uint32_t width = pdfium::base::checked_cast<uint32_t>(pSource->GetWidth()); uint32_t height = pdfium::base::checked_cast<uint32_t>(pSource->GetHeight()); - FX_SAFE_DWORD safe_buf_len = width; + FX_SAFE_UINT32 safe_buf_len = width; safe_buf_len *= height; safe_buf_len *= nComponents; safe_buf_len += 1024; diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp index 27b645c137..18d2c8d827 100644 --- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -301,7 +301,7 @@ void sycc420_to_rgb(opj_image_t* img) { OPJ_UINT32 crw = img->comps[2].w; bool extw = sycc420_must_extend_cbcr(yw, cbw); bool exth = sycc420_must_extend_cbcr(yh, cbh); - FX_SAFE_DWORD safeSize = yw; + FX_SAFE_UINT32 safeSize = yw; safeSize *= yh; if (!safeSize.IsValid()) return; diff --git a/core/fxcodec/jbig2/JBig2_Image.cpp b/core/fxcodec/jbig2/JBig2_Image.cpp index 7297199112..6a1c060b75 100644 --- a/core/fxcodec/jbig2/JBig2_Image.cpp +++ b/core/fxcodec/jbig2/JBig2_Image.cpp @@ -216,7 +216,7 @@ void CJBig2_Image::expand(int32_t h, FX_BOOL v) { uint32_t dwH = pdfium::base::checked_cast<uint32_t>(h); uint32_t dwStride = pdfium::base::checked_cast<uint32_t>(m_nStride); uint32_t dwHeight = pdfium::base::checked_cast<uint32_t>(m_nHeight); - FX_SAFE_DWORD safeMemSize = dwH; + FX_SAFE_UINT32 safeMemSize = dwH; safeMemSize *= dwStride; if (!safeMemSize.IsValid()) { return; diff --git a/core/fxcrt/include/fx_safe_types.h b/core/fxcrt/include/fx_safe_types.h index 84ea55a685..f12e74906b 100644 --- a/core/fxcrt/include/fx_safe_types.h +++ b/core/fxcrt/include/fx_safe_types.h @@ -11,7 +11,7 @@ #include "core/fxcrt/include/fx_system.h" #include "third_party/base/numerics/safe_math.h" -typedef pdfium::base::CheckedNumeric<uint32_t> FX_SAFE_DWORD; +typedef pdfium::base::CheckedNumeric<uint32_t> FX_SAFE_UINT32; typedef pdfium::base::CheckedNumeric<int32_t> FX_SAFE_INT32; typedef pdfium::base::CheckedNumeric<size_t> FX_SAFE_SIZE_T; typedef pdfium::base::CheckedNumeric<FX_FILESIZE> FX_SAFE_FILESIZE; |