Bug 1823551 - add overflow check in nsDirIndexParser::OnDataAvailable(). r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D181874
This commit is contained in:
sunil mayya 2023-07-04 07:23:50 +00:00
parent d940a81b38
commit 04090eba6f

View file

@ -350,10 +350,13 @@ nsDirIndexParser::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aStream,
uint64_t aSourceOffset, uint32_t aCount) {
if (aCount < 1) return NS_OK;
int32_t len = mBuf.Length();
uint32_t len = mBuf.Length();
// Ensure that our mBuf has capacity to hold the data we're about to
// read.
// Before adjusting the capacity, guard against any potential overflow
// resulting from the addition of aCount with len. See Bug 1823551.
NS_ENSURE_TRUE((UINT32_MAX - aCount) >= len, NS_ERROR_FAILURE);
if (!mBuf.SetLength(len + aCount, fallible)) return NS_ERROR_OUT_OF_MEMORY;
// Now read the data into our buffer.