Skip to content
Memory corruption Disclosed report

Overflow in nsTextFragment::Append causes potential memory-safety bug

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 32 days
  • Paid in 45 days
  • Disclosed after 32 days
Text
User Agent: Mozilla/5.0 (Windows NT 5.1; rv:36.0) Gecko/20100101 Firefox/36.0
Build ID: 20150305021524

Steps to reproduce:

nsTextFragment::Append (38.0.1\dom\base\nsTextFragment.cpp) can experience an overflow, causing a realloc to a tiny buffer size. The function then writes to unallocated space, potentially permitting the execution of attacker-chosen code, as by modifying an object's virtual-function table. Four separate lines can overflow:

329:    char16_t* buff = (char16_t*)moz_realloc(m2b, (mState.mLength + aLength) * sizeof(char16_t));

351:    char16_t* buff = (char16_t*)moz_malloc((mState.mLength + aLength) *
352:                                                  sizeof(char16_t));

382:    buff = (char*)moz_realloc(const_cast<char*>(m1b),
383:                                    (mState.mLength + aLength) * sizeof(char));

389:    buff = (char*)moz_malloc((mState.mLength + aLength) * sizeof(char));

In all cases, mState.mLength isa 29-bit uint32_t, and aLength isa uint32_t. If the sum mState.mLength + aLength overflows, the corresponding realloc or malloc allocates a buffer that is too small to hold the copied data.

This bug is a reiteration and expansion of https://bugzilla.mozilla.org/show_bug.cgi?id=620892 . A comment to that report said that "the only caller of nsTextFragment::Append() is nsGenericDOMData::SetTextInternal(), and it already checks that the fragment can grow to the requested size". While that appears still to be true as of 38.0.1, nothing guarantees that other potential callers of nsTextFragment::Append will first call nsTextFragment::CanGrowBy. nsTextFragment::Append should protect itself to prevent someone from inadvertently introducing a security bug.

The original report as published on Mozilla's Bugzilla, by q1. 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.

What is known

A memory corruption bug in DOM: Core & HTML. Mozilla made it public on 7 July 2015.

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

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

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 q1

View all

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