Bug 1919031 - Also check for out of bounds before populating the cache. r=smaug

I guess since facebook does this it is probably worth it.

Differential Revision: https://phabricator.services.mozilla.com/D224314
This commit is contained in:
Emilio Cobos Álvarez 2024-10-02 20:34:58 +00:00
parent c28b75f295
commit 15378d9238

View File

@ -433,8 +433,11 @@ nsIContent* nsParentNodeChildContentList::Item(uint32_t aIndex) {
if (aIndex == 0) {
return mNode->GetFirstChild();
}
// This is correct even if the addition overflows.
if (aIndex + 1 == mNode->GetChildCount()) {
uint32_t childCount = mNode->GetChildCount();
if (aIndex >= childCount) {
return nullptr;
}
if (aIndex + 1 == childCount) {
return mNode->GetLastChild();
}
ValidateCache();