if (mFirstRead && length < 4) break;
ImageConsumer::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length){  PRUint32 max_read;  PRUint32 bytes_read = 0, str_length;  ilINetReader *reader = mURL->GetReader();  if (mInterrupted || mStatus != 0) {    mStatus = MK_INTERRUPTED;    reader->StreamAbort(mStatus);    NS_RELEASE(reader);    return NS_ERROR_ABORT;  }  nsresult err = 0;  PRUint32 nb;  do {    max_read = reader->WriteReady();    if (0 == max_read) {      break;    }    if (max_read > IMAGE_BUF_SIZE) {      max_read = IMAGE_BUF_SIZE;    }    err = pIStream->Read(mBuffer,                        max_read, &nb);    if (err != NS_OK) {      break;    }    bytes_read += nb;    if (mFirstRead == PR_TRUE) {      PRInt32 ilErr;                  ilErr = reader->FirstWrite((const unsigned char *)mBuffer, nb);      mFirstRead = PR_FALSE;      /*        * If FirstWrite(...) fails then the image type       * cannot be determined and the il_container        * stream functions have not been initialized!       */      if (ilErr != 0) {        mStatus = MK_IMAGE_LOSSAGE;        mInterrupted = PR_TRUE;	    NS_RELEASE(reader);        return NS_ERROR_ABORT;      }    }            reader->Write((const unsigned char *)mBuffer, (int32)nb);  } while(nb != 0);  if ((NS_OK != err) && (NS_BASE_STREAM_EOF != err)) {    mStatus = MK_IMAGE_LOSSAGE;    mInterrupted = PR_TRUE;  }  err = pIStream->GetLength(&str_length);  if ((NS_OK == err) && (bytes_read < str_length)) {    // If we haven't emptied the stream, hold onto it, because    // we will need to read from it subsequently and we don't    // know if we'll get a OnDataAvailable call again.    //    // Addref the new stream before releasing the old one,    // in case it is the same stream!    NS_ADDREF(pIStream);    NS_IF_RELEASE(mStream);    mStream = pIStream;  }  NS_RELEASE(reader);  return NS_OK;}