Skip to content
Memory corruption Disclosed report Advanced

Latent write beyond bounds in nsDirIndexParser::OnDataAvailable()

The nsDirIndexParser::OnDataAvailable() function adds a 32-bit length and a 32-bit count to calculate a buffer size, which can overflow and cause an undersized allocation followed by a write beyond bounds. The bug is latent because incoming data is limited to 0x20000-byte chunks, so the overflow is not reachable in practice.

mozillabugs Follow

Originally disclosed on Mozilla

  • Fixed in 3 months
  • Paid in 4 months
  • Disclosed after 3 months
Text
`nsDirIndexParser::OnDataAvailable()` (`netwerk/streamconv/converters/nsDirIndexParser.cpp`) unsafely adds 32-bit integers to calculate an allocation length, potentially causing an overflow, subsequent underallocation, and a write beyond bounds (WBB). The bug appears latent, since the size of the incoming data `aCount` appears to be limited to the size sent via the chain beginning in `HttpBackgroundChannelParent::OnTransportAndData()` (`netwerk/protocol/http/HttpBackgroundChannelParent.cpp`), which calls `SendDataInChunks()` (`netwerk/protocol/http/nsHttp.h`), which sends the data to the child process in chunks no larger than `0x20000` bytes.

The bug is on line 357, and the WBB would occur on line 362:

'''
   348: NS_IMETHODIMP
   349: nsDirIndexParser::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aStream,
   350:                                   uint64_t aSourceOffset, uint32_t aCount) {
   351:   if (aCount < 1) return NS_OK;
   352: 
   353:   int32_t len = mBuf.Length();
   354: 
   355:   // Ensure that our mBuf has capacity to hold the data we're about to
   356:   // read.
   357:   if (!mBuf.SetLength(len + aCount, fallible)) return NS_ERROR_OUT_OF_MEMORY;
   358: 
   359:   // Now read the data into our buffer.
   360:   nsresult rv;
   361:   uint32_t count;
   362:   rv = aStream->Read(mBuf.BeginWriting() + len, aCount, &count);
   ...
   371: }
'''

The original report as published on Mozilla's Bugzilla, by mozillabugs. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code uses 32-bit signed integer arithmetic for the buffer length calculation without checking for overflow before calling SetLength.

Impact

The overflow could lead to a write beyond bounds, but the bug is latent because the incoming data size is limited to 0x20000 bytes, so it is not exploitable in the current code path.

What the attacker needed

None

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A program calculates how much memory to reserve by adding two numbers, but if the sum is too large it wraps around to a small value. The program then writes more data than it reserved, which can corrupt memory. Here the bug is hidden because the data is always sent in small chunks, so the dangerous large sum never happens.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by mozillabugs

View all

41 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.