diff --git a/src/buffer/out/Row.cpp b/src/buffer/out/Row.cpp index 7a46215b6fc..adea9599131 100644 --- a/src/buffer/out/Row.cpp +++ b/src/buffer/out/Row.cpp @@ -433,7 +433,9 @@ OutputCellIterator ROW::WriteCells(OutputCellIterator it, const til::CoordType c auto colorStarts = gsl::narrow_cast(columnBegin); auto currentIndex = colorStarts; - while (it && currentIndex <= finalColumnInRow) + // finalColumnInRow is 32-bit and currentIndex is 16-bit. If finalColumnInRow is higher + // than the 16-bit integer limit, we will loop indefinitely. + while (it && currentIndex <= saturated_cast(finalColumnInRow)) { // Fill the color if the behavior isn't set to keeping the current color. if (it->TextAttrBehavior() != TextAttributeBehavior::Current) diff --git a/src/terminal/adapter/SixelParser.cpp b/src/terminal/adapter/SixelParser.cpp index 979dd42371c..edd1e09bf6a 100644 --- a/src/terminal/adapter/SixelParser.cpp +++ b/src/terminal/adapter/SixelParser.cpp @@ -610,7 +610,9 @@ void SixelParser::_updateTextColors() // the text output as well. if (_conformanceLevel <= 3 && _maxColors > 2 && _colorTableChanged) [[unlikely]] { - for (IndexType tableIndex = 0; tableIndex < _maxColors; tableIndex++) + // _maxColors is 64-bit and tableIndex is 8-bit. If _maxColors is higher + // than the 8-bit integer limit, we will loop indefinitely. + for (IndexType tableIndex = 0; tableIndex < (saturated_cast(_maxColors)); tableIndex++) { _dispatcher.SetColorTableEntry(tableIndex, _colorFromIndex(tableIndex)); } diff --git a/src/terminal/adapter/charsets.hpp b/src/terminal/adapter/charsets.hpp index bc81e31e72f..f90edcc760e 100644 --- a/src/terminal/adapter/charsets.hpp +++ b/src/terminal/adapter/charsets.hpp @@ -19,7 +19,7 @@ namespace Microsoft::Console::VirtualTerminal public: constexpr CharSet(const std::initializer_list> replacements) { - for (auto i = L'\0'; i < _translationTable.size(); i++) + for (size_t i = L'\0'; i < _translationTable.size(); i++) _translationTable.at(i) = BaseChar + i; for (auto replacement : replacements) _translationTable.at(replacement.first - BaseChar) = replacement.second;