Skip to content
Memory corruption Disclosed report CVE-2015-2736

nsZipArchive::BuildFileList has memory-safety bug

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 12 days
  • Paid in 23 days
  • Disclosed after 12 days

User Agent: Mozilla/5.0 (Windows; rv:) Gecko/20100101 Firefox/. Build ID: 20150305021524

Steps to reproduce:

An attacker could force nsZipArchive::BuildFileList to read memory that it does not own, possibly leading to a crash, disclosure of sensitive information, or execution of code chosen by an attacker.

The problem is in the function's failure to validate the offsets of zip central directories.

Code beginning at line 624 extracts the first central directory offset from the zip-end record:

624: for (buf = endp - ZIPEND_SIZE; buf > startp; buf--) 625: { 626: if (xtolong(buf) == ENDSIG) { 627: centralOffset = xtolong(((ZipEnd *)buf)->offset_central_dir); 628: break; 629: } 630: } 631: }

Line 637 then sets the buffer pointer buf to "startp + centralOffset" without doing more than a cursory validation of centralOffset:

632: 633: if (!centralOffset) 634: return NS_ERROR_FILE_CORRUPTED; 635: 636: //-- Read the central directory headers 637: buf = startp + centralOffset;

The code then uses buf to find and read central directories:

638: uint32_t sig = 0; 639: while (buf + int32_t(sizeof(uint32_t)) <= endp && 640: (sig = xtolong(buf)) == CENTRALSIG) { 641: // Make sure there is enough data available. 642: if (endp - buf < ZIPCENTRAL_SIZE) 643: return NS_ERROR_FILE_CORRUPTED; 644: 645: // Read the fixed-size data. 646: ZipCentral* central = (ZipCentral*)buf; 647: 648: uint16_t namelen = xtoint(central->filename_len); 649: ... // lots more where that came from

The problem occurs if the first-encountered zip-end record contains an offset_central_dir field that is very large, thus making centralOffset very large. In this case, the RHS of line 637 can overflow (especially on 32-bit platforms), setting buf to somewhere < startp. Since buf is then perforce < endp, this does not trip the check on line 639.

If *buf happens to contain CENTRALSIG, the code at line 638 et seq interprets it as a valid central directory, with unpredictable consequences further down the road when it's used. I guess that this defect could be used, for example, to inject Javascript from domain A into domain B.

This bug might explain https://bugzilla.mozilla.org/show_bug.cgi?id=596826 .

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 high-severity memory corruption bug in Networking: JAR. Mozilla made it public on 5 June 2015 as CVE-2015-2736.

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.