зеркало из https://github.com/mozilla/gecko-dev.git
Bug 965362 - Part 1: Make sure that nsScriptableInputStream::Read reads all of the allowed available bytes from the input stream; r=bsmedberg
This commit is contained in:
Родитель
5e4435640e
Коммит
8a08eed87d
|
@ -45,14 +45,13 @@ nsScriptableInputStream::Read(uint32_t aCount, char **_retval) {
|
|||
buffer = (char*)moz_malloc(count+1); // make room for '\0'
|
||||
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
uint32_t amtRead = 0;
|
||||
rv = mInputStream->Read(buffer, count, &amtRead);
|
||||
rv = ReadHelper(buffer, count);
|
||||
if (NS_FAILED(rv)) {
|
||||
nsMemory::Free(buffer);
|
||||
return rv;
|
||||
}
|
||||
|
||||
buffer[amtRead] = '\0';
|
||||
buffer[count] = '\0';
|
||||
*_retval = buffer;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -69,10 +68,20 @@ nsScriptableInputStream::ReadBytes(uint32_t aCount, nsACString &_retval) {
|
|||
}
|
||||
|
||||
char *ptr = _retval.BeginWriting();
|
||||
nsresult rv = ReadHelper(ptr, aCount);
|
||||
if (NS_FAILED(rv)) {
|
||||
_retval.Truncate();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsScriptableInputStream::ReadHelper(char* aBuffer, uint32_t aCount)
|
||||
{
|
||||
uint32_t totalBytesRead = 0;
|
||||
while (1) {
|
||||
uint32_t bytesRead;
|
||||
nsresult rv = mInputStream->Read(ptr + totalBytesRead,
|
||||
nsresult rv = mInputStream->Read(aBuffer + totalBytesRead,
|
||||
aCount - totalBytesRead,
|
||||
&bytesRead);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -86,7 +95,6 @@ nsScriptableInputStream::ReadBytes(uint32_t aCount, nsACString &_retval) {
|
|||
|
||||
// If we have read zero bytes, we have hit EOF.
|
||||
if (bytesRead == 0) {
|
||||
_retval.Truncate();
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
private:
|
||||
~nsScriptableInputStream() {}
|
||||
|
||||
nsresult ReadHelper(char* aBuffer, uint32_t aCount);
|
||||
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче