Skip to content
Memory corruption Disclosed report Advanced CVE-2017-5443

Out of bound read in nsBinHexDecoder::DetectContentType

A heap buffer overflow (out-of-bounds read) occurs in Firefox's BinHex decoder when it processes a crafted .hqx file. An attacker could trigger a crash of the web content process by getting a victim to open such a file.

Chamal De Silva Follow

Originally disclosed on Mozilla

  • Fixed in 11 days
  • Paid in 30 days
  • Disclosed after 11 days

Created attachment 8841189 binhex.hqx

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:

  1. 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
  2. Start firefox.
  3. Open attached binhex.hqx.

Actual results:

Address Sanitizer will display this error.

==28086==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000232040 at pc 0x00000044b58e bp 0x7fff4a98c270 sp 0x7fff4a98ba20 READ of size 10 at 0x602000232040 thread T0 (Web Content) #0 0x44b58d in __interceptor_strrchr.part.28 clang/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:499 #1 0x44b58d in ?? ??:0 #2 0x7f984665893e in mozilla::net::nsBinHexDecoder::DetectContentType(nsIRequest*, nsCString const&) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:486 (discriminator 2) #3 0x7f984665893e in ?? ??:0 #4 0x7f9846657dd9 in mozilla::net::nsBinHexDecoder::ProcessNextState(nsIRequest*, nsISupports*) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:185 #5 0x7f9846657dd9 in ?? ??:0 #6 0x7f984665731d in mozilla::net::nsBinHexDecoder::ProcessNextChunk(nsIRequest*, nsISupports*, unsigned int) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:408 #7 0x7f984665731d in ?? ??:0 #8 0x7f9846656b24 in mozilla::net::nsBinHexDecoder::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:141 ...................

0x602000232040 is located 0 bytes to the right of 16-byte region [0x602000232030,0x602000232040) allocated by thread T0 (Web Content) here: #0 0x4d2628 in __interceptor_malloc asan_rtl #1 0x4d2628 in ?? ??:0 #2 0x7f9845f57709 in nsStringBuffer::Alloc(unsigned long) /firefox/xpcom/string/nsSubstring.cpp:217 #3 0x7f9845f57709 in ?? ??:0 #4 0x7f9845f55b94 in nsACString_internal::MutatePrep(unsigned int, char**, unsigned int*) /firefox/xpcom/string/nsTSubstring.cpp:158 #5 0x7f9845f55b94 in ?? ??:0 #6 0x7f9845f4ae40 in nsACString_internal::SetCapacity(unsigned int, mozilla::fallible_t const&) /firefox/xpcom/string/nsTSubstring.cpp:696 #7 0x7f9845f4ae40 in ?? ??:0 #8 0x7f9845f5eb2c in nsACString_internal::SetCapacity(unsigned int) /firefox/xpcom/string/nsTSubstring.cpp:675 #9 0x7f9845f5eb2c in ?? ??:0 #10 0x7f9845f4a741 in nsACString_internal::SetLength(unsigned int) /firefox/xpcom/string/nsTSubstring.cpp:727 #11 0x7f9845f4a741 in ?? ??:0 #12 0x7f9846657ce6 in mozilla::net::nsBinHexDecoder::ProcessNextState(nsIRequest*, nsISupports*) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:170 #13 0x7f9846657ce6 in ?? ??:0 #14 0x7f984665731d in mozilla::net::nsBinHexDecoder::ProcessNextChunk(nsIRequest*, nsISupports*, unsigned int) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:408 #15 0x7f984665731d in ?? ??:0 #16 0x7f9846656b24 in mozilla::net::nsBinHexDecoder::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /firefox/netwerk/streamconv/converters/nsBinHexDecoder.cpp:141 ...................

Expected results:

Should not read out of bound data .

The original report as published on Mozilla's Bugzilla, by Chamal De Silva. 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 decoder calls a string search function on a buffer that is not null-terminated or is shorter than expected, so the search reads past the allocated region.

Impact

Opening a crafted BinHex file causes an out-of-bounds read that crashes the web content process; the report does not show code execution.

What the attacker needed

Victim opens a crafted .hqx file; Firefox build with ASan to observe the crash

How it was found

  1. Build Firefox with Address Sanitizer enabled.
  2. Start Firefox.
  3. Open the attached BinHex 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.

Firefox can decode a file format called BinHex, used on old Macs. When it reads a specially crafted file of this type, it looks past the end of a memory buffer, which is a memory safety bug. The report shows this only as a crash detected by a debugging tool, not as a way to run attacker code.

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 Chamal De Silva

View all

3 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.