diff options
author | Pale Moon <git-repo@palemoon.org> | 2017-10-01 01:34:26 +0200 |
---|---|---|
committer | Pale Moon <git-repo@palemoon.org> | 2017-10-01 01:35:36 +0200 |
commit | 0311227437a30a0014805fbd130b04a511bb28bf (patch) | |
tree | 8e3ddca873e0c1e6e2e405f1d500d9ceb4eb66fe /netwerk | |
parent | d607a565557b0a2dc54f9294354d258ed1db32a8 (diff) | |
download | palemoon-gre-0311227437a30a0014805fbd130b04a511bb28bf.tar.gz |
Update Brotli decompressor.
This bring us up-to date for enabling of Brotli content-encoding.
This resolves #1290.
Diffstat (limited to 'netwerk')
-rw-r--r-- | netwerk/streamconv/converters/nsHTTPCompressConv.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/netwerk/streamconv/converters/nsHTTPCompressConv.cpp b/netwerk/streamconv/converters/nsHTTPCompressConv.cpp index c990aae02..2f62ae3d5 100644 --- a/netwerk/streamconv/converters/nsHTTPCompressConv.cpp +++ b/netwerk/streamconv/converters/nsHTTPCompressConv.cpp @@ -140,6 +140,7 @@ NS_METHOD nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const char *dataIn, uint32_t, uint32_t aAvail, uint32_t *countRead) { + MOZ_ASSERT(stream); nsHTTPCompressConv *self = static_cast<nsHTTPCompressConv *>(closure); *countRead = 0; @@ -155,13 +156,19 @@ nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const c return NS_OK; } + if (outBuffer == nullptr) { + self->mBrotli->mStatus = NS_ERROR_OUT_OF_MEMORY; + return self->mBrotli->mStatus; + } + do { outSize = kOutSize; outPtr = outBuffer; - // brotli api is documented in brotli/dec/decode.h - res = ::BrotliDecompressBufferStreaming( - &avail, reinterpret_cast<const unsigned char **>(&dataIn), stream ? 0 : 1, + // brotli api is documented in brotli/dec/decode.h and brotli/dec/decode.c + + res = ::BrotliDecompressStream( + &avail, reinterpret_cast<const unsigned char **>(&dataIn), &outSize, &outPtr, &self->mBrotli->mTotalOut, &self->mBrotli->mState); outSize = kOutSize - outSize; @@ -170,11 +177,14 @@ nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const c return self->mBrotli->mStatus; } - // in 'the current implementation' brotli consumes all input on success - MOZ_ASSERT(!avail); - if (avail) { - self->mBrotli->mStatus = NS_ERROR_UNEXPECTED; - return self->mBrotli->mStatus; + // in 'the current implementation' brotli must consume everything before + // asking for more input + if (res == BROTLI_RESULT_NEEDS_MORE_INPUT) { + MOZ_ASSERT(!avail); + if (avail) { + self->mBrotli->mStatus = NS_ERROR_UNEXPECTED; + return self->mBrotli->mStatus; + } } if (outSize > 0) { nsresult rv = self->do_OnDataAvailable(self->mBrotli->mRequest, |