mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 17:59:34 +00:00
reland the part of bug 801466 backed out in 02a65951d77d since it wasn't at fault
This commit is contained in:
parent
6472ad7f01
commit
4a0bc291e4
@ -24,8 +24,6 @@
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIMemory.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "pratom.h"
|
||||
#include "prmem.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsTextFormatter.h"
|
||||
#include "nsIErrorService.h"
|
||||
|
@ -4,9 +4,8 @@
|
||||
|
||||
#include "nsSerializationHelper.h"
|
||||
|
||||
#include "plbase64.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "mozilla/Base64.h"
|
||||
#include "nsISerializable.h"
|
||||
#include "nsIObjectOutputStream.h"
|
||||
#include "nsIObjectInputStream.h"
|
||||
@ -16,6 +15,8 @@
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsStringStream.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
nsresult
|
||||
NS_SerializeToString(nsISerializable* obj, nsCSubstring& str)
|
||||
{
|
||||
@ -38,30 +39,12 @@ NS_SerializeToString(nsISerializable* obj, nsCSubstring& str)
|
||||
nsresult
|
||||
NS_DeserializeObject(const nsCSubstring& str, nsISupports** obj)
|
||||
{
|
||||
// Base64 maps 3 binary bytes -> 4 ASCII bytes. If the original byte array
|
||||
// does not have length 0 mod 3, the input is padded with zeros and the
|
||||
// output is padded with a corresponding number of trailing '=' (which are
|
||||
// then sometimes dropped). To compute the correct length of the original
|
||||
// byte array, we have to subtract the number of trailing '=' and then
|
||||
// multiply by 3 and then divide by 4 (making sure this is an integer
|
||||
// division).
|
||||
nsCString decodedData;
|
||||
nsresult rv = Base64Decode(str, decodedData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t size = str.Length();
|
||||
if (size > 0 && str[size-1] == '=') {
|
||||
if (size > 1 && str[size-2] == '=') {
|
||||
size -= 2;
|
||||
} else {
|
||||
size -= 1;
|
||||
}
|
||||
}
|
||||
size = (size * 3) / 4;
|
||||
char* buf = PL_Base64Decode(str.BeginReading(), str.Length(), nullptr);
|
||||
if (!buf)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream),
|
||||
Substring(buf, size));
|
||||
PR_Free(buf);
|
||||
rv = NS_NewCStringInputStream(getter_AddRefs(stream), decodedData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIObjectInputStream> objstream =
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "netCore.h"
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "prnetdb.h"
|
||||
#include "prerror.h"
|
||||
|
3
netwerk/cache/nsCacheMetaData.cpp
vendored
3
netwerk/cache/nsCacheMetaData.cpp
vendored
@ -6,7 +6,6 @@
|
||||
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "prmem.h"
|
||||
|
||||
const char *
|
||||
nsCacheMetaData::GetElement(const char * key)
|
||||
@ -152,7 +151,7 @@ nsresult
|
||||
nsCacheMetaData::EnsureBuffer(uint32_t bufSize)
|
||||
{
|
||||
if (mBufferSize < bufSize) {
|
||||
char * buf = (char *)PR_REALLOC(mBuffer, bufSize);
|
||||
char * buf = (char *)moz_realloc(mBuffer, bufSize);
|
||||
if (!buf) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
3
netwerk/cache/nsCacheMetaData.h
vendored
3
netwerk/cache/nsCacheMetaData.h
vendored
@ -18,7 +18,8 @@ public:
|
||||
|
||||
~nsCacheMetaData() {
|
||||
mBufferSize = mMetaSize = 0;
|
||||
PR_FREEIF(mBuffer);
|
||||
moz_free(mBuffer);
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
|
||||
const char * GetElement(const char * key);
|
||||
|
@ -5,8 +5,10 @@
|
||||
|
||||
// data implementation
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsDataChannel.h"
|
||||
|
||||
#include "mozilla/Base64.h"
|
||||
#include "nsIOService.h"
|
||||
#include "nsDataHandler.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIPipe.h"
|
||||
@ -14,9 +16,8 @@
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsEscape.h"
|
||||
#include "plbase64.h"
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
nsresult
|
||||
nsDataChannel::OpenContentStream(bool async, nsIInputStream **result,
|
||||
@ -70,17 +71,10 @@ nsDataChannel::OpenContentStream(bool async, nsIInputStream **result,
|
||||
}
|
||||
resultLen = ((resultLen * 3) / 4);
|
||||
|
||||
// XXX PL_Base64Decode will return a null pointer for decoding
|
||||
// errors. Since those are more likely than out-of-memory,
|
||||
// should we return NS_ERROR_MALFORMED_URI instead?
|
||||
char * decodedData = PL_Base64Decode(dataBuffer.get(), dataLen, nullptr);
|
||||
if (!decodedData) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
rv = bufOutStream->Write(decodedData, resultLen, &contentLen);
|
||||
|
||||
PR_Free(decodedData);
|
||||
nsAutoCString decodedData;
|
||||
rv = Base64Decode(dataBuffer, decodedData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = bufOutStream->Write(decodedData.get(), resultLen, &contentLen);
|
||||
} else {
|
||||
rv = bufOutStream->Write(dataBuffer.get(), dataBuffer.Length(), &contentLen);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user