Bug 1717947 - Remove support for brotli streams in Jar archives. r=valentin

This was added in bug 1355661, has been kept Nightly-only since then,
and was only used briefly for omni.ja, and eventually we switched
compression off entirely on omni.ja. If we ever switch compression on
again on omni.ja, it would likely be with zstd, which is much faster
on the compression side.

Differential Revision: https://phabricator.services.mozilla.com/D118654
This commit is contained in:
Mike Hommey 2021-06-25 00:20:10 +00:00
Родитель 5c4959c5b5
Коммит a53b913e63
5 изменённых файлов: 2 добавлений и 122 удалений

Просмотреть файл

@ -7,9 +7,6 @@
#include "nsJARInputStream.h"
#include "zipstruct.h" // defines ZIP compression codes
#ifdef MOZ_JAR_BROTLI
# include "brotli/decode.h" // brotli
#endif
#include "nsZipArchive.h"
#include "mozilla/MmapFaultHandler.h"
@ -52,15 +49,6 @@ nsresult nsJARInputStream::InitFile(nsJAR* aJar, nsZipItem* item) {
mOutCrc = crc32(0L, Z_NULL, 0);
break;
#ifdef MOZ_JAR_BROTLI
case MOZ_JAR_BROTLI:
mBrotliState = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
mMode = MODE_BROTLI;
mInCrc = item->CRC32();
mOutCrc = crc32(0L, Z_NULL, 0);
break;
#endif
default:
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -173,9 +161,6 @@ nsJARInputStream::Available(uint64_t* _retval) {
break;
case MODE_INFLATE:
#ifdef MOZ_JAR_BROTLI
case MODE_BROTLI:
#endif
case MODE_COPY:
*_retval = mOutSize - mZs.total_out;
break;
@ -204,9 +189,6 @@ nsJARInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytesRead) {
return ReadDirectory(aBuffer, aCount, aBytesRead);
case MODE_INFLATE:
#ifdef MOZ_JAR_BROTLI
case MODE_BROTLI:
#endif
if (mZs.total_out < mOutSize) {
rv = ContinueInflate(aBuffer, aCount, aBytesRead);
}
@ -259,11 +241,6 @@ nsJARInputStream::Close() {
if (mMode == MODE_INFLATE) {
inflateEnd(&mZs);
}
#ifdef MOZ_JAR_BROTLI
if (mMode == MODE_BROTLI) {
BrotliDecoderDestroyInstance(mBrotliState);
}
#endif
mMode = MODE_CLOSED;
mFd = nullptr;
return NS_OK;
@ -284,9 +261,6 @@ nsresult nsJARInputStream::ContinueInflate(char* aBuffer, uint32_t aCount,
mZs.avail_out = std::min(aCount, (mOutSize - oldTotalOut));
mZs.next_out = (unsigned char*)aBuffer;
#ifndef MOZ_JAR_BROTLI
MOZ_ASSERT(mMode == MODE_INFLATE);
#endif
if (mMode == MODE_INFLATE) {
// now inflate
int zerr = inflate(&mZs, Z_SYNC_FLUSH);
@ -294,28 +268,6 @@ nsresult nsJARInputStream::ContinueInflate(char* aBuffer, uint32_t aCount,
return NS_ERROR_FILE_CORRUPTED;
}
finished = (zerr == Z_STREAM_END);
#ifdef MOZ_JAR_BROTLI
} else {
MOZ_ASSERT(mMode == MODE_BROTLI);
/* The brotli library wants size_t, but z_stream only contains
* unsigned int for avail_* and unsigned long for total_*.
* So use temporary stack values. */
size_t avail_in = mZs.avail_in;
size_t avail_out = mZs.avail_out;
size_t total_out = mZs.total_out;
BrotliDecoderResult result = BrotliDecoderDecompressStream(
mBrotliState, &avail_in,
const_cast<const unsigned char**>(&mZs.next_in), &avail_out,
&mZs.next_out, &total_out);
/* We don't need to update avail_out, it's not used outside this
* function. */
mZs.total_out = total_out;
mZs.avail_in = avail_in;
if (result == BROTLI_DECODER_RESULT_ERROR) {
return NS_ERROR_FILE_CORRUPTED;
}
finished = (result == BROTLI_DECODER_RESULT_SUCCESS);
#endif
}
*aBytesRead = (mZs.total_out - oldTotalOut);

Просмотреть файл

@ -12,10 +12,6 @@
#include "nsTArray.h"
#include "mozilla/Attributes.h"
#ifdef MOZ_JAR_BROTLI
struct BrotliDecoderStateStruct;
#endif
/*-------------------------------------------------------------------------
* Class nsJARInputStream declaration. This class defines the type of the
* object returned by calls to nsJAR::GetInputStream(filename) for the
@ -26,12 +22,7 @@ class nsJARInputStream final : public nsIInputStream {
nsJARInputStream()
: mOutSize(0),
mInCrc(0),
mOutCrc(0)
#ifdef MOZ_JAR_BROTLI
,
mBrotliState(nullptr)
#endif
,
mOutCrc(0),
mNameLen(0),
mCurPos(0),
mArrPos(0),
@ -56,9 +47,6 @@ class nsJARInputStream final : public nsIInputStream {
uint32_t mInCrc; // CRC as provided by the zipentry
uint32_t mOutCrc; // CRC as calculated by me
z_stream mZs; // zip data structure
#ifdef MOZ_JAR_BROTLI
BrotliDecoderStateStruct* mBrotliState; // Brotli decoder state
#endif
/* For directory reading */
RefPtr<nsJAR> mJar; // string reference to zipreader
@ -73,9 +61,6 @@ class nsJARInputStream final : public nsIInputStream {
MODE_CLOSED,
MODE_DIRECTORY,
MODE_INFLATE,
#ifdef MOZ_JAR_BROTLI
MODE_BROTLI,
#endif
MODE_COPY
} JISMode;

Просмотреть файл

@ -12,9 +12,6 @@
#define READTYPE int32_t
#include "zlib.h"
#ifdef MOZ_JAR_BROTLI
# include "brotli/decode.h" // brotli
#endif
#include "nsISupportsUtils.h"
#include "mozilla/MmapFaultHandler.h"
#include "prio.h"
@ -1096,12 +1093,7 @@ nsZipCursor::nsZipCursor(nsZipItem* item, nsZipArchive* aZip, uint8_t* aBuf,
: mItem(item),
mBuf(aBuf),
mBufSize(aBufSize),
mZs()
#ifdef MOZ_JAR_BROTLI
,
mBrotliState(nullptr)
#endif
,
mZs(),
mCRC(0),
mDoCRC(doCRC) {
if (mItem->Compression() == DEFLATED) {
@ -1116,12 +1108,6 @@ nsZipCursor::nsZipCursor(nsZipItem* item, nsZipArchive* aZip, uint8_t* aBuf,
mZs.avail_in = item->Size();
mZs.next_in = (Bytef*)aZip->GetData(item);
#ifdef MOZ_JAR_BROTLI
if (mItem->Compression() == MOZ_JAR_BROTLI) {
mBrotliState = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
}
#endif
if (doCRC) mCRC = crc32(0L, Z_NULL, 0);
}
@ -1129,11 +1115,6 @@ nsZipCursor::~nsZipCursor() {
if (mItem->Compression() == DEFLATED) {
inflateEnd(&mZs);
}
#ifdef MOZ_JAR_BROTLI
if (mItem->Compression() == MOZ_JAR_BROTLI) {
BrotliDecoderDestroyInstance(mBrotliState);
}
#endif
}
uint8_t* nsZipCursor::ReadOrCopy(uint32_t* aBytesRead, bool aCopy) {
@ -1168,31 +1149,6 @@ uint8_t* nsZipCursor::ReadOrCopy(uint32_t* aBytesRead, bool aCopy) {
*aBytesRead = mZs.next_out - buf;
verifyCRC = (zerr == Z_STREAM_END);
break;
#ifdef MOZ_JAR_BROTLI
case MOZ_JAR_BROTLI: {
buf = mBuf;
mZs.next_out = buf;
/* The brotli library wants size_t, but z_stream only contains
* unsigned int for avail_*. So use temporary stack values. */
size_t avail_out = mBufSize;
size_t avail_in = mZs.avail_in;
BrotliDecoderResult result = BrotliDecoderDecompressStream(
mBrotliState, &avail_in,
const_cast<const unsigned char**>(&mZs.next_in), &avail_out,
&mZs.next_out, nullptr);
/* We don't need to update avail_out, it's not used outside this
* function. */
mZs.avail_in = avail_in;
if (result == BROTLI_DECODER_RESULT_ERROR) {
return nullptr;
}
*aBytesRead = mZs.next_out - buf;
verifyCRC = (result == BROTLI_DECODER_RESULT_SUCCESS);
break;
}
#endif
default:
return nullptr;
}
@ -1216,9 +1172,6 @@ nsZipItemPtr_base::nsZipItemPtr_base(nsZipArchive* aZip, const char* aEntryName,
uint32_t size = 0;
bool compressed = (item->Compression() == DEFLATED);
#ifdef MOZ_JAR_BROTLI
compressed |= (item->Compression() == MOZ_JAR_BROTLI);
#endif
if (compressed) {
size = item->RealSize();
mAutoBuf = MakeUniqueFallible<uint8_t[]>(size);

Просмотреть файл

@ -24,9 +24,6 @@
class nsZipFind;
struct PRFileDesc;
#ifdef MOZ_JAR_BROTLI
struct BrotliDecoderStateStruct;
#endif
/**
* This file defines some of the basic structures used by libjar to
@ -301,9 +298,6 @@ class nsZipCursor final {
uint8_t* mBuf;
uint32_t mBufSize;
z_stream mZs;
#ifdef MOZ_JAR_BROTLI
BrotliDecoderStateStruct* mBrotliState;
#endif
uint32_t mCRC;
bool mDoCRC;
};

Просмотреть файл

@ -99,9 +99,5 @@ typedef struct ZipEnd_ {
#define TOKENIZED 7
#define DEFLATED 8
#define UNSUPPORTED 0xFF
/* non-standard extension */
#ifdef NIGHTLY_BUILD
# define MOZ_JAR_BROTLI 0x81
#endif
#endif /* _zipstruct_h */