Files
roytam1 89830cff26 disable log2 in jsmath, and import changes from tenfourfox:
- #334: more tele from TabBrowser; also remove gMultiProcessBrowser since we don't support it (16f8592aa)
- #431: M1388354 M1388014 (da843afa1)
- #438: M1393098 (539efce0c)
- #388: M1354564 (d375d57d3)
- #429: Brotli 1.0.1 (c69914a5a) (with ppc-only defines removed)
- #429: install modules/woff2 (current to Fx57) (87b560912) (with ppc-only defines removed)
- #429: update OTS to 5.2.0 plus patches and M1396026 (1ce2a83ec) (with binary literals removed)
- #317: update graphite2 to 1.3.10 (f4bf5ad97)
- #429: update Harfbuzz to 1.5.1 (083639c71)
- #317: patch thebes for graphite2 alignment issues; enable graphite fonts (b7fead52b)
- #434: adjust video queue settings; Mach factor decode delay logic (default off) (9b5b09a6c)
- clean up a couple warnings (f37f7669d)
- #426: M1385395 (b8ebae839)
- #438: M1375599 (84bfb83b1)
- #442: M1381157 (ffbe7ea3a)
2018-05-31 14:43:36 +08:00

95 lines
2.9 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Compression.h"
#include "mozilla/CheckedInt.h"
// Without including <string>, MSVC 2015 complains about e.g. the impossibility
// to convert `const void* const` to `void*` when calling memchr from
// corecrt_memory.h.
#include <string>
using namespace mozilla::Compression;
namespace {
#include "lz4.c"
}/* anonymous namespace */
/* Our wrappers */
size_t
LZ4::compress(const char* aSource, size_t aInputSize, char* aDest)
{
CheckedInt<int> inputSizeChecked = aInputSize;
MOZ_ASSERT(inputSizeChecked.isValid());
return LZ4_compress(aSource, aDest, inputSizeChecked.value());
}
size_t
LZ4::compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest,
size_t aMaxOutputSize)
{
CheckedInt<int> inputSizeChecked = aInputSize;
MOZ_ASSERT(inputSizeChecked.isValid());
CheckedInt<int> maxOutputSizeChecked = aMaxOutputSize;
MOZ_ASSERT(maxOutputSizeChecked.isValid());
return LZ4_compress_limitedOutput(aSource, aDest, inputSizeChecked.value(),
maxOutputSizeChecked.value());
}
bool
LZ4::decompress(const char* aSource, char* aDest, size_t aOutputSize)
{
CheckedInt<int> outputSizeChecked = aOutputSize;
MOZ_ASSERT(outputSizeChecked.isValid());
int ret = LZ4_decompress_fast(aSource, aDest, outputSizeChecked.value());
return ret >= 0;
}
bool
LZ4::decompress(const char* aSource, size_t aInputSize, char* aDest,
size_t aMaxOutputSize, size_t* aOutputSize)
{
CheckedInt<int> maxOutputSizeChecked = aMaxOutputSize;
MOZ_ASSERT(maxOutputSizeChecked.isValid());
CheckedInt<int> inputSizeChecked = aInputSize;
MOZ_ASSERT(inputSizeChecked.isValid());
int ret = LZ4_decompress_safe(aSource, aDest, inputSizeChecked.value(),
maxOutputSizeChecked.value());
if (ret >= 0) {
*aOutputSize = ret;
return true;
}
*aOutputSize = 0;
return false;
}
bool
LZ4::decompressPartial(const char* aSource, size_t aInputSize, char* aDest,
size_t aMaxOutputSize, size_t* aOutputSize)
{
CheckedInt<int> maxOutputSizeChecked = aMaxOutputSize;
MOZ_ASSERT(maxOutputSizeChecked.isValid());
CheckedInt<int> inputSizeChecked = aInputSize;
MOZ_ASSERT(inputSizeChecked.isValid());
int ret = LZ4_decompress_safe_partial(aSource, aDest,
inputSizeChecked.value(),
maxOutputSizeChecked.value(),
maxOutputSizeChecked.value());
if (ret >= 0) {
*aOutputSize = ret;
return true;
}
*aOutputSize = 0;
return false;
}