From 81f9eeef041f2974274751d7508598049ae32db2 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Tue, 5 Sep 2017 15:33:18 -0400 Subject: Convert FX_STRSIZE int->size_t Change the underlying type for FX_STRSIZE to size_t from int. This will make the value unsigned and thus all values in the range of the type will be valid. This allows for the final remove of negative length strings, but also introduces a some casting and functional errors, since many parts of the code base assume that FX_STRSIZE is int or another signed type. This also CL fixes these errors. BUG=pdfium:828 Change-Id: I231dca59e96fc9330cbb099eecbdfc41fcf86f5b Reviewed-on: https://pdfium-review.googlesource.com/11830 Reviewed-by: Henrique Nakashima Reviewed-by: Tom Sepez Commit-Queue: Ryan Harrison --- fxbarcode/datamatrix/BC_ErrorCorrection.cpp | 3 ++- fxbarcode/datamatrix/BC_HighLevelEncoder.cpp | 17 +++++++++++------ fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'fxbarcode') diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp index 2e84df5c59..c45eadcf9a 100644 --- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -122,7 +122,8 @@ CBC_ErrorCorrection::~CBC_ErrorCorrection() {} CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, CBC_SymbolInfo* symbolInfo, int32_t& e) { - if (codewords.GetLength() != symbolInfo->dataCapacity()) { + if (pdfium::base::checked_cast(codewords.GetLength()) != + symbolInfo->dataCapacity()) { e = BCExceptionIllegalArgument; return CFX_WideString(); } diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index d2f40dd060..b8c63946db 100644 --- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -118,18 +118,20 @@ CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, } } CFX_WideString codewords = context.m_codewords; - if (codewords.GetLength() < capacity) { + if (pdfium::base::checked_cast(codewords.GetLength()) < capacity) { codewords += PAD; } - while (codewords.GetLength() < capacity) { - codewords += (randomize253State(PAD, codewords.GetLength() + 1)); + while (pdfium::base::checked_cast(codewords.GetLength()) < + capacity) { + codewords += (randomize253State( + PAD, pdfium::base::checked_cast(codewords.GetLength()) + 1)); } return codewords; } int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, int32_t startpos, int32_t currentMode) { - if (startpos >= msg.GetLength()) { + if (startpos >= pdfium::base::checked_cast(msg.GetLength())) { return currentMode; } std::vector charCounts; @@ -151,7 +153,8 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, } int32_t charsProcessed = 0; while (true) { - if ((startpos + charsProcessed) == msg.GetLength()) { + if ((startpos + charsProcessed) == + pdfium::base::checked_cast(msg.GetLength())) { int32_t min = std::numeric_limits::max(); std::vector mins(6); std::vector intCharCounts(6); @@ -252,7 +255,9 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, } if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) { int32_t p = startpos + charsProcessed + 1; - while (p < msg.GetLength()) { + int32_t checked_length = + pdfium::base::checked_cast(msg.GetLength()); + while (p < checked_length) { wchar_t tc = msg[p]; if (isX12TermSep(tc)) { return X12_ENCODATION; diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index 911730fbe5..4c488418d9 100644 --- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp @@ -380,8 +380,8 @@ void MergeString(std::vector* result, CBC_QRCoderMode::sBYTE, versionNum, e); if (e != BCExceptionNO) return; - if (element2.first == CBC_QRCoderMode::sBYTE && - element1.second.GetLength() < tmp) { + if (element2.first == CBC_QRCoderMode::sBYTE && tmp >= 0 && + element1.second.GetLength() < static_cast(tmp)) { element2.second = element1.second + element2.second; result->erase(result->begin() + i); i--; @@ -399,8 +399,8 @@ void MergeString(std::vector* result, CBC_QRCoderMode::sBYTE, versionNum, e); if (e != BCExceptionNO) return; - if (element2.first == CBC_QRCoderMode::sBYTE && - element1.second.GetLength() < tmp) { + if (element2.first == CBC_QRCoderMode::sBYTE && tmp >= 0 && + element1.second.GetLength() < static_cast(tmp)) { element2.second = element1.second + element2.second; result->erase(result->begin() + i); i--; @@ -410,8 +410,8 @@ void MergeString(std::vector* result, CBC_QRCoderMode::sALPHANUMERIC, versionNum, e); if (e != BCExceptionNO) return; - if (element2.first == CBC_QRCoderMode::sALPHANUMERIC && - element1.second.GetLength() < tmp) { + if (element2.first == CBC_QRCoderMode::sALPHANUMERIC && tmp >= 0 && + element1.second.GetLength() < static_cast(tmp)) { element2.second = element1.second + element2.second; result->erase(result->begin() + i); i--; -- cgit v1.2.3