Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIA: throw E_FAIL for out-of-bounds text #8052

Merged
2 commits merged into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/spell-check/dictionary/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mikemaccana
miloush
miniksa
niksa
nvaccess
nvda
oising
oldnewthing
osgwiki
Expand Down
16 changes: 9 additions & 7 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ CATCH_RETURN();
// - the text that the UiaTextRange encompasses
#pragma warning(push)
#pragma warning(disable : 26447) // compiler isn't filtering throws inside the try/catch
std::wstring UiaTextRangeBase::_getTextValue(std::optional<unsigned int> maxLength) const noexcept
try
std::wstring UiaTextRangeBase::_getTextValue(std::optional<unsigned int> maxLength) const
{
_pData->LockConsole();
auto Unlock = wil::scope_exit([&]() noexcept {
Expand All @@ -540,6 +539,14 @@ try
const auto& buffer = _pData->GetTextBuffer();
const auto bufferSize = buffer.GetSize();

// TODO GH#5406: create a different UIA parent object for each TextBuffer
// nvaccess/nvda#11428: Ensure our endpoints are in bounds
// otherwise, we'll FailFast catastrophically
if (!bufferSize.IsInBounds(_start, true) || !bufferSize.IsInBounds(_end, true))
{
THROW_HR(E_FAIL);
}

// convert _end to be inclusive
auto inclusiveEnd = _end;
bufferSize.DecrementInBounds(inclusiveEnd, true);
Expand All @@ -564,11 +571,6 @@ try

return textData;
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
return {};
}
#pragma warning(pop)

IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit,
Expand Down
2 changes: 1 addition & 1 deletion src/types/UiaTextRangeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Microsoft::Console::Types
// This is used by tracing to extract the text value
// that the UiaTextRange currently encompasses.
// GetText() cannot be used as it's not const
std::wstring _getTextValue(std::optional<unsigned int> maxLength = std::nullopt) const noexcept;
std::wstring _getTextValue(std::optional<unsigned int> maxLength = std::nullopt) const;

RECT _getTerminalRect() const;

Expand Down