Multiple fixes to address DD CodeQL requirements (#18451)

After taking in 1.22, our CodeQL process caught a few locations where we
weren't following the right guidance:
- Performing integer comparisons of different sizes which could lead to
an infinite loop if the larger integer goes out of range of the smaller
integer
- Not checking HResult of a called method

Co-authored-by: aphistra <102989060+aphistra@users.noreply.github.com>
This commit is contained in:
Javier 2025-03-18 13:26:31 -05:00 committed by GitHub
parent a86c90a045
commit 6e89242373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 4 deletions

View File

@ -431,7 +431,7 @@ OutputCellIterator ROW::WriteCells(OutputCellIterator it, const til::CoordType c
THROW_HR_IF(E_INVALIDARG, limitRight.value_or(0) >= size());
// If we're given a right-side column limit, use it. Otherwise, the write limit is the final column index available in the char row.
const auto finalColumnInRow = limitRight.value_or(size() - 1);
const auto finalColumnInRow = gsl::narrow_cast<uint16_t>(limitRight.value_or(size() - 1));
auto currentColor = it->TextAttr();
uint16_t colorUses = 0;

View File

@ -574,7 +574,8 @@ try
}
const auto cpt = gsl::narrow_cast<DWORD>(points.size());
return PolyBezier(_hdcMemoryContext, points.data(), cpt);
RETURN_HR_IF(E_FAIL, !PolyBezier(_hdcMemoryContext, points.data(), cpt));
return S_OK;
};
if (lines.test(GridLines::Left))

View File

@ -610,7 +610,7 @@ void SixelParser::_updateTextColors()
// the text output as well.
if (_conformanceLevel <= 3 && _maxColors > 2 && _colorTableChanged) [[unlikely]]
{
for (IndexType tableIndex = 0; tableIndex < _maxColors; tableIndex++)
for (IndexType tableIndex = 0; _maxColors <= 16 && tableIndex < _maxColors; tableIndex++)
{
_dispatcher.SetColorTableEntry(tableIndex, _colorFromIndex(tableIndex));
}

View File

@ -19,7 +19,7 @@ namespace Microsoft::Console::VirtualTerminal
public:
constexpr CharSet(const std::initializer_list<std::pair<wchar_t, wchar_t>> replacements)
{
for (auto i = L'\0'; i < _translationTable.size(); i++)
for (auto i = L'\0'; i < gsl::narrow_cast<wchar_t>(_translationTable.size()); i++)
_translationTable.at(i) = BaseChar + i;
for (auto replacement : replacements)
_translationTable.at(replacement.first - BaseChar) = replacement.second;