зеркало из https://github.com/mozilla/pjs.git
Bug 117119�BMP and ICO decoders should use ReadSegments, not Read
patch by cbiesinger@web.de r=pavlov sr=tor
This commit is contained in:
Родитель
711d78a28b
Коммит
526aad740d
|
@ -122,22 +122,19 @@ NS_IMETHODIMP nsBMPDecoder::Flush()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsBMPDecoder::ReadSegCb(nsIInputStream* aIn, void* aClosure,
|
||||||
|
const char* aFromRawSegment, PRUint32 aToOffset,
|
||||||
|
PRUint32 aCount, PRUint32 *aWriteCount) {
|
||||||
|
nsBMPDecoder *decoder = NS_REINTERPRET_CAST(nsBMPDecoder*, aClosure);
|
||||||
|
*aWriteCount = aCount;
|
||||||
|
return decoder->ProcessData(aFromRawSegment, aCount);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsBMPDecoder::WriteFrom(nsIInputStream *aInStr, PRUint32 aCount, PRUint32 *aRetval)
|
NS_IMETHODIMP nsBMPDecoder::WriteFrom(nsIInputStream *aInStr, PRUint32 aCount, PRUint32 *aRetval)
|
||||||
{
|
{
|
||||||
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::WriteFrom(%p, %lu, %p)\n", aInStr, aCount, aRetval));
|
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::WriteFrom(%p, %lu, %p)\n", aInStr, aCount, aRetval));
|
||||||
|
|
||||||
char* buffer = new char[aCount];
|
return aInStr->ReadSegments(ReadSegCb, this, aCount, aRetval);
|
||||||
if (!buffer) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
unsigned int realCount = aCount;
|
|
||||||
nsresult rv = aInStr->Read(buffer, aCount, &realCount);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
*aRetval = realCount;
|
|
||||||
|
|
||||||
rv = ProcessData(buffer, realCount);
|
|
||||||
delete []buffer;
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
|
@ -125,6 +125,11 @@ public:
|
||||||
virtual ~nsBMPDecoder();
|
virtual ~nsBMPDecoder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** Callback for ReadSegments to avoid copying the data */
|
||||||
|
static NS_METHOD ReadSegCb(nsIInputStream* aIn, void* aClosure,
|
||||||
|
const char* aFromRawSegment, PRUint32 aToOffset,
|
||||||
|
PRUint32 aCount, PRUint32 *aWriteCount);
|
||||||
|
|
||||||
/** Processes the data.
|
/** Processes the data.
|
||||||
* @param aBuffer Data to process.
|
* @param aBuffer Data to process.
|
||||||
* @oaram count Number of bytes in mBuffer */
|
* @oaram count Number of bytes in mBuffer */
|
||||||
|
|
|
@ -191,21 +191,18 @@ NS_IMETHODIMP nsICODecoder::Flush()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_METHOD nsICODecoder::ReadSegCb(nsIInputStream* aIn, void* aClosure,
|
||||||
|
const char* aFromRawSegment, PRUint32 aToOffset,
|
||||||
|
PRUint32 aCount, PRUint32 *aWriteCount) {
|
||||||
|
nsICODecoder *decoder = NS_REINTERPRET_CAST(nsICODecoder*, aClosure);
|
||||||
|
*aWriteCount = aCount;
|
||||||
|
return decoder->ProcessData(aFromRawSegment, aCount);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsICODecoder::WriteFrom(nsIInputStream *aInStr, PRUint32 aCount, PRUint32 *aRetval)
|
NS_IMETHODIMP nsICODecoder::WriteFrom(nsIInputStream *aInStr, PRUint32 aCount, PRUint32 *aRetval)
|
||||||
{
|
{
|
||||||
char* buffer = new char[aCount];
|
return aInStr->ReadSegments(ReadSegCb, this, aCount, aRetval);
|
||||||
if (!buffer)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
unsigned int realCount = aCount;
|
|
||||||
nsresult rv = aInStr->Read(buffer, aCount, &realCount);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
*aRetval = realCount;
|
|
||||||
|
|
||||||
rv = ProcessData(buffer, realCount);
|
|
||||||
delete []buffer;
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) {
|
nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) {
|
||||||
|
|
|
@ -80,6 +80,11 @@ public:
|
||||||
virtual ~nsICODecoder();
|
virtual ~nsICODecoder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** Callback for ReadSegments to avoid copying the data */
|
||||||
|
static NS_METHOD ReadSegCb(nsIInputStream* aIn, void* aClosure,
|
||||||
|
const char* aFromRawSegment, PRUint32 aToOffset,
|
||||||
|
PRUint32 aCount, PRUint32 *aWriteCount);
|
||||||
|
|
||||||
// Private helper methods
|
// Private helper methods
|
||||||
nsresult ProcessData(const char* aBuffer, PRUint32 aCount);
|
nsresult ProcessData(const char* aBuffer, PRUint32 aCount);
|
||||||
void ProcessDirEntry();
|
void ProcessDirEntry();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче