Bug 750983 - ICO crash [mozilla::image::Decoder::Write]. r=joe

This commit is contained in:
Brian R. Bondy 2012-05-08 08:38:43 -04:00
parent e0ba4eb257
commit eb5d0026e1
2 changed files with 22 additions and 15 deletions

View File

@ -365,9 +365,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
if (mIsPNG) {
mContainedDecoder = new nsPNGDecoder(mImage, mObserver);
mContainedDecoder->InitSharedDecoder();
mContainedDecoder->Write(mSignature, PNGSIGNATURESIZE);
mDataError = mContainedDecoder->HasDataError();
if (mContainedDecoder->HasDataError()) {
if (!WriteToContainedDecoder(mSignature, PNGSIGNATURESIZE)) {
return;
}
}
@ -375,9 +373,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
// If we have a PNG, let the PNG decoder do all of the rest of the work
if (mIsPNG && mContainedDecoder && mPos >= mImageOffset + PNGSIGNATURESIZE) {
mContainedDecoder->Write(aBuffer, aCount);
mDataError = mContainedDecoder->HasDataError();
if (mContainedDecoder->HasDataError()) {
if (!WriteToContainedDecoder(aBuffer, aCount)) {
return;
}
mPos += aCount;
@ -445,9 +441,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
PostDataError();
return;
}
mContainedDecoder->Write((const char*)bfhBuffer, sizeof(bfhBuffer));
mDataError = mContainedDecoder->HasDataError();
if (mContainedDecoder->HasDataError()) {
if (!WriteToContainedDecoder((const char*)bfhBuffer, sizeof(bfhBuffer))) {
return;
}
@ -468,9 +462,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
}
// Write out the BMP's bitmap info header
mContainedDecoder->Write(mBIHraw, sizeof(mBIHraw));
mDataError = mContainedDecoder->HasDataError();
if (mContainedDecoder->HasDataError()) {
if (!WriteToContainedDecoder(mBIHraw, sizeof(mBIHraw))) {
return;
}
@ -515,9 +507,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
toFeed = aCount;
}
mContainedDecoder->Write(aBuffer, toFeed);
mDataError = mContainedDecoder->HasDataError();
if (mContainedDecoder->HasDataError()) {
if (!WriteToContainedDecoder(aBuffer, toFeed)) {
return;
}
@ -592,6 +582,19 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
}
}
bool
nsICODecoder::WriteToContainedDecoder(const char* aBuffer, PRUint32 aCount)
{
mContainedDecoder->Write(aBuffer, aCount);
if (mContainedDecoder->HasDataError()) {
mDataError = mContainedDecoder->HasDataError();
}
if (mContainedDecoder->HasDecoderError()) {
PostDecoderError(mContainedDecoder->GetDecoderError());
}
return !HasError();
}
void
nsICODecoder::ProcessDirEntry(IconDirEntry& aTarget)
{

View File

@ -77,6 +77,10 @@ public:
virtual void FinishInternal();
private:
// Writes to the contained decoder and sets the appropriate errors
// Returns true if there are no errors.
bool WriteToContainedDecoder(const char* aBuffer, PRUint32 aCount);
// Processes a single dir entry of the icon resource
void ProcessDirEntry(IconDirEntry& aTarget);
// Sets the hotspot property of if we have a cursor