Bug 1421873: Fix infinite loop in HandlerProvider::GetAllTextInfoMainThread when invalid attribute offsets are returned. r=MarcoZ

When querying text attributes, Gecko can return an end offset less than the requested offset in some rare cases, which isn't valid.
This is perhaps because the text mutated during the attribute fetching loop for some reason, making the requested offset invalid.
We now check the end offset and break out of the loop in this case.
This fixes a freeze after sending a message in OX Mail with NVDA.

MozReview-Commit-ID: 1lVSLAdOcS7

--HG--
extra : rebase_source : 048fbed8ddc591f62c17d559483bfe2f1542431c
This commit is contained in:
James Teh 2017-11-30 16:44:02 +10:00
Родитель 0d7066652a
Коммит 31c03e927b
1 изменённых файлов: 6 добавлений и 2 удалений

Просмотреть файл

@ -614,11 +614,15 @@ HandlerProvider::GetAllTextInfoMainThread(BSTR* aText,
long end = 0;
long length = ::SysStringLen(*aText);
while (end < length) {
long offset = end;
long start;
BSTR attribs;
// The (exclusive) end of the last run is the start of the next run.
hr = ht->get_attributes(end, &start, &end, &attribs);
if (FAILED(hr)) {
hr = ht->get_attributes(offset, &start, &end, &attribs);
// Bug 1421873: Gecko can return end <= offset in some rare cases, which
// isn't valid. This is perhaps because the text mutated during the loop
// for some reason, making this offset invalid.
if (FAILED(hr) || end <= offset) {
break;
}
attribRuns.AppendElement(IA2TextSegment({attribs, start, end}));