Integer overflow in nsZipHandle::findDataStart() — CRX header parsing corrupts ZIP structures pre-auth in parent process
An integer overflow in the CRX header parsing of nsZipHandle::findDataStart() lets a crafted XPI file wrap the computed header size to zero, so the whole file is treated as ZIP data. An attacker could then have attacker-controlled central directory entries, including a fake signature file, parsed from the wrong offset.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 13 days
- Disclosed after 5 days
Created attachment 9570617
oC XPI file (898 bytes) — triggers integer overflow in findDataStart(). CRX v3 header with subHeaderSize=0xFFFFFFF4 causes headerSize to wrap to 0.
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Steps to reproduce:
1. Craft an XPI file starting with CRX magic bytes (see attached crx_overflow_v2.xpi)
2. The file has: CRX magic "Cr24" + version=3 + subHeaderSize=0xFFFFFFF4
3. Open this file via nsIZipReader (e.g., extension install, or Load Temporary Add-on via about:debugging)
4. Compile and run the attached test_crx.c verifier: gcc -o test_crx test_crx.c -fsanitize=address -g && ./test_crx crx_overflow_v2.xpi
Actual results:
Integer overflow in findDataStart() at modules/libjar/nsZipArchive.cpp line 328:
uint32_t headerSize = CRXIntSize * 2; // = 8
headerSize += CRXIntSize + subHeaderSize; // 8 + 4 + 0xFFFFFFF4 = 0x100000000 wraps to 0
- headerSize = 0 (wrapped)
- mFileData = mFileStart + 0 = byte 0 of file (should be byte 16)
- mLen = mTotalLen (entire file treated as ZIP data)
- BuildFileList parses attacker-crafted central directory from wrong offset
- All 4 fake ZIP entries (including META-INF/zigbert.rsa) are created successfully
- Signature verifier reads attacker-controlled PKCS7/COSE data
Expected results:
findDataStart() should validate that the addition won't overflow before computing headerSize. Suggested fix:
if (version == 3) {
uint32_t subHeaderSize = xtolong(headerData);
+ if (subHeaderSize > mTotalLen ||
+ headerSize > mTotalLen - CRXIntSize - subHeaderSize) {
+ return NS_ERROR_FILE_CORRUPTED;
+ }
headerSize += CRXIntSize + subHeaderSize;
}
The file should be rejected as corrupted rather than parsed with wrapped headerSize.
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 addition computing headerSize is performed without checking for overflow, so a large subHeaderSize wraps the result to zero and the data offset is miscalculated.
Impact
The file is parsed with a wrapped header size, so all fake ZIP entries including a signature file are created and the signature verifier reads attacker-controlled data; the text does not demonstrate code execution.
What the attacker needed
A crafted XPI file; the file is opened by nsIZipReader
The fix
The code should check that subHeaderSize and the computed headerSize do not exceed the file length before adding, and reject the file as corrupted.
How it was found
- Craft an XPI file beginning with the CRX magic bytes and a version 3 header.
- Set the sub-header size field to a value that makes the header size addition wrap.
- Open the file through nsIZipReader, for example during extension install or temporary add-on loading.
- Run the supplied verifier to observe the wrapped header size and parsed entries.
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 ZIP file is a container of files, and Firefox reads a small header before the ZIP part to know where it starts. The code adds up some numbers from that header to find the start, but a huge number makes the sum wrap around to zero, so Firefox starts reading the ZIP from the very beginning of the file instead. That means the file's own bytes are treated as the list of contents, which the attacker controls.
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.