Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 586002
Collapse All | Expand All

(-)a/netwerk/streamconv/converters/nsHTTPCompressConv.cpp (-5 / +10 lines)
Lines 160-190 nsHTTPCompressConv::OnStopRequest(nsIReq Link Here
160
NS_METHOD
160
NS_METHOD
161
nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const char *dataIn,
161
nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const char *dataIn,
162
                                  uint32_t, uint32_t aAvail, uint32_t *countRead)
162
                                  uint32_t, uint32_t aAvail, uint32_t *countRead)
163
{
163
{
164
  MOZ_ASSERT(stream);
164
  MOZ_ASSERT(stream);
165
  nsHTTPCompressConv *self = static_cast<nsHTTPCompressConv *>(closure);
165
  nsHTTPCompressConv *self = static_cast<nsHTTPCompressConv *>(closure);
166
  *countRead = 0;
166
  *countRead = 0;
167
167
168
  const uint32_t kOutSize = 128 * 1024; // just a chunk size, we call in a loop
168
  const size_t kOutSize = 128 * 1024; // just a chunk size, we call in a loop
169
  unsigned char outBuffer[kOutSize];
169
  uint8_t *outPtr;
170
  unsigned char *outPtr;
171
  size_t outSize;
170
  size_t outSize;
172
  size_t avail = aAvail;
171
  size_t avail = aAvail;
173
  BrotliResult res;
172
  BrotliResult res;
174
173
175
  if (!self->mBrotli) {
174
  if (!self->mBrotli) {
176
    *countRead = aAvail;
175
    *countRead = aAvail;
177
    return NS_OK;
176
    return NS_OK;
178
  }
177
  }
179
178
179
  auto outBuffer = MakeUniqueFallible<uint8_t[]>(kOutSize);
180
  if (outBuffer == nullptr) {
181
    self->mBrotli->mStatus = NS_ERROR_OUT_OF_MEMORY;
182
    return self->mBrotli->mStatus;
183
  }
184
180
  do {
185
  do {
181
    outSize = kOutSize;
186
    outSize = kOutSize;
182
    outPtr = outBuffer;
187
    outPtr = outBuffer.get();
183
188
184
    // brotli api is documented in brotli/dec/decode.h and brotli/dec/decode.c
189
    // brotli api is documented in brotli/dec/decode.h and brotli/dec/decode.c
185
    LOG(("nsHttpCompresssConv %p brotlihandler decompress %d\n", self, avail));
190
    LOG(("nsHttpCompresssConv %p brotlihandler decompress %d\n", self, avail));
186
    res = ::BrotliDecompressStream(
191
    res = ::BrotliDecompressStream(
187
      &avail, reinterpret_cast<const unsigned char **>(&dataIn),
192
      &avail, reinterpret_cast<const unsigned char **>(&dataIn),
188
      &outSize, &outPtr, &self->mBrotli->mTotalOut, &self->mBrotli->mState);
193
      &outSize, &outPtr, &self->mBrotli->mTotalOut, &self->mBrotli->mState);
189
    outSize = kOutSize - outSize;
194
    outSize = kOutSize - outSize;
190
    LOG(("nsHttpCompresssConv %p brotlihandler decompress rv=%x out=%d\n",
195
    LOG(("nsHttpCompresssConv %p brotlihandler decompress rv=%x out=%d\n",
Lines 205-221 nsHTTPCompressConv::BrotliHandler(nsIInp Link Here
205
        self->mBrotli->mStatus = NS_ERROR_UNEXPECTED;
210
        self->mBrotli->mStatus = NS_ERROR_UNEXPECTED;
206
        return self->mBrotli->mStatus;
211
        return self->mBrotli->mStatus;
207
      }
212
      }
208
    }
213
    }
209
    if (outSize > 0) {
214
    if (outSize > 0) {
210
      nsresult rv = self->do_OnDataAvailable(self->mBrotli->mRequest,
215
      nsresult rv = self->do_OnDataAvailable(self->mBrotli->mRequest,
211
                                             self->mBrotli->mContext,
216
                                             self->mBrotli->mContext,
212
                                             self->mBrotli->mSourceOffset,
217
                                             self->mBrotli->mSourceOffset,
213
                                             reinterpret_cast<const char *>(outBuffer),
218
                                             reinterpret_cast<const char *>(outBuffer.get()),
214
                                             outSize);
219
                                             outSize);
215
      LOG(("nsHttpCompressConv %p BrotliHandler ODA rv=%x", self, rv));
220
      LOG(("nsHttpCompressConv %p BrotliHandler ODA rv=%x", self, rv));
216
      if (NS_FAILED(rv)) {
221
      if (NS_FAILED(rv)) {
217
        self->mBrotli->mStatus = rv;
222
        self->mBrotli->mStatus = rv;
218
        return self->mBrotli->mStatus;
223
        return self->mBrotli->mStatus;
219
      }
224
      }
220
    }
225
    }
221
226

Return to bug 586002