Heap buffer overflow in nsDirIndexParser::ParseData
A heap buffer overflow occurs in Firefox's directory index parser when it reads past the end of a buffer while processing a crafted HTTP index response. An attacker could host a malicious page that crashes the browser tab, and the out-of-bounds read may allow further memory corruption.
Originally disclosed on Mozilla
- Fixed in 17 days
- Paid in 23 days
- Disclosed after 17 days
Created attachment 8843558 httpindex.php
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Steps to reproduce:
- Build Firefox with Address Sanitizer. I built with options and instructions mentioned in "Manual Build" section in https://developer.mozilla.org/en-US/docs/Mozilla/Testing/Firefox_and_Address_Sanitizer
- Download and host httpindex.php file on a web server. Web server should support PHP.
- Start firefox.
- Visit httpindex.php.
Actual results:
Firefox tab crashed.
Address Sanitizer Output
==4312==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6030002b7ac0 at pc 0x7fea5b5e3fc5 bp 0x7fff6d37d1b0 sp 0x7fff6d37d1a8 READ of size 1 at 0x6030002b7ac0 thread T0 (Web Content) #0 0x7fea5b5e3fc4 in nsDirIndexParser::ParseData(nsIDirIndex*, char*) firefox/netwerk/streamconv/converters/nsDirIndexParser.cpp:233 (discriminator 1) #1 0x7fea5b5e3fc4 in ?? ??:0 #2 0x7fea5b5e27bf in nsDirIndexParser::ProcessData(nsIRequest*, nsISupports*) firefox/netwerk/streamconv/converters/nsDirIndexParser.cpp:407 (discriminator 1) #3 0x7fea5b5e27bf in ?? ??:0 #4 0x7fea5b5e41a3 in nsDirIndexParser::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) firefox/netwerk/streamconv/converters/nsDirIndexParser.cpp:350 #5 0x7fea5b5e41a3 in ?? ??:0 #6 0x7fea5b783b9b in mozilla::net::HttpChannelChild::DoOnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) firefox/netwerk/protocol/http/HttpChannelChild.cpp:799 (discriminator 2) #7 0x7fea5b783b9b in ?? ??:0 ...............................
0x6030002b7ac0 is located 0 bytes to the right of 32-byte region [0x6030002b7aa0,0x6030002b7ac0) allocated by thread T0 (Web Content) here: #0 0x4d2628 in __interceptor_malloc asan_rtl #1 0x4d2628 in ?? ??:0 #2 0x7fea5aedd939 in nsStringBuffer::Alloc(unsigned long) firefox/xpcom/string/nsSubstring.cpp:217 #3 0x7fea5aedd939 in ?? ??:0 #4 0x7fea5aedbdc4 in nsACString_internal::MutatePrep(unsigned int, char**, unsigned int*) firefox/xpcom/string/nsTSubstring.cpp:172 #5 0x7fea5aedbdc4 in ?? ??:0 #6 0x7fea5aed1170 in nsACString_internal::SetCapacity(unsigned int, mozilla::fallible_t const&) firefox/xpcom/string/nsTSubstring.cpp:710 #7 0x7fea5aed1170 in ?? ??:0 #8 0x7fea5aed1501 in nsACString_internal::SetLength(unsigned int, mozilla::fallible_t const&) firefox/xpcom/string/nsTSubstring.cpp:748 #9 0x7fea5aed1501 in ?? ??:0 #10 0x7fea5b5e40eb in nsDirIndexParser::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) firefox/netwerk/streamconv/converters/nsDirIndexParser.cpp:336 #11 0x7fea5b5e40eb in ?? ??:0 #12 0x7fea5b783b9b in mozilla::net::HttpChannelChild::DoOnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) firefox/netwerk/protocol/http/HttpChannelChild.cpp:799 (discriminator 2) #13 0x7fea5b783b9b in ?? ??:0 ...............................
Expected results:
Firefox tab should not crash due to a Heap buffer overflow.
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 parser does not check that the buffer has enough remaining bytes before reading a character at the current position.
Impact
The browser tab crashes due to the heap buffer overflow; the out-of-bounds read could potentially lead to further memory corruption.
What the attacker needed
Firefox build with Address Sanitizer; PHP-capable web server; victim visits attacker page
How it was found
- Build Firefox with Address Sanitizer enabled.
- Host the provided PHP file on a PHP-capable web server.
- Start Firefox.
- Visit the hosted PHP file.
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 buffer is a fixed-size area of memory. The parser read one byte past the end of its buffer, which is an out-of-bounds read. This can crash the browser and, in some cases, let an attacker influence memory.
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.