[Library] Update zlibng (#1255)

* Update zlibng

* Set cmake path more directly in zlibng to hopefully fix an issue with the build on drone

* I'm dumb, missing / in path

* Mackal helps with a dumb gitignore issue

* Adding all the files, not sure what's ignoring them and im tired of looking

* Some tweaks to zlibng build to hopefully get it to build properly. works on msvc now
This commit is contained in:
Alex
2021-02-23 17:00:26 -08:00
committed by GitHub
parent e6dee96266
commit 2957f5084d
184 changed files with 22029 additions and 11703 deletions
+62 -63
View File
@@ -24,14 +24,13 @@ static const uint8_t *data;
static size_t dataLen;
static alloc_func zalloc = NULL;
static free_func zfree = NULL;
static size_t dictionaryLen = 0;
static unsigned int dictionaryLen = 0;
static unsigned long dictId; /* Adler32 value of the dictionary */
/* ===========================================================================
* Test deflate() with preset dictionary
*/
void test_dict_deflate(unsigned char **compr, size_t *comprLen)
{
void test_dict_deflate(unsigned char **compr, size_t *comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
int level = data[0] % 11 - 1; /* [-1..9]
@@ -58,7 +57,7 @@ void test_dict_deflate(unsigned char **compr, size_t *comprLen)
/* deflate would fail for no-compression or for speed levels. */
if (level == 0 || level == 1)
level = -1;
level = -1;
c_stream.zalloc = zalloc;
c_stream.zfree = zfree;
@@ -73,15 +72,15 @@ void test_dict_deflate(unsigned char **compr, size_t *comprLen)
CHECK_ERR(err, "deflateSetDictionary");
/* deflateBound does not provide enough space for low compression levels. */
*comprLen = 100 + 2 * PREFIX(deflateBound)(&c_stream, dataLen);
*comprLen = 100 + 2 * PREFIX(deflateBound)(&c_stream, (unsigned long)dataLen);
*compr = (uint8_t *)calloc(1, *comprLen);
dictId = c_stream.adler;
c_stream.next_out = *compr;
c_stream.avail_out = (unsigned int)(*comprLen);
c_stream.next_in = data;
c_stream.avail_in = dataLen;
c_stream.next_in = (z_const unsigned char *)data;
c_stream.avail_in = (uint32_t)dataLen;
err = PREFIX(deflate)(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
@@ -96,75 +95,75 @@ void test_dict_deflate(unsigned char **compr, size_t *comprLen)
* Test inflate() with a preset dictionary
*/
void test_dict_inflate(unsigned char *compr, size_t comprLen) {
int err;
PREFIX3(stream) d_stream; /* decompression stream */
unsigned char *uncompr;
int err;
PREFIX3(stream) d_stream; /* decompression stream */
unsigned char *uncompr;
d_stream.zalloc = zalloc;
d_stream.zfree = zfree;
d_stream.opaque = (void *)0;
d_stream.zalloc = zalloc;
d_stream.zfree = zfree;
d_stream.opaque = (void *)0;
d_stream.next_in = compr;
d_stream.avail_in = (unsigned int)comprLen;
d_stream.next_in = compr;
d_stream.avail_in = (unsigned int)comprLen;
err = PREFIX(inflateInit)(&d_stream);
CHECK_ERR(err, "inflateInit");
err = PREFIX(inflateInit)(&d_stream);
CHECK_ERR(err, "inflateInit");
uncompr = (uint8_t *)calloc(1, dataLen);
d_stream.next_out = uncompr;
d_stream.avail_out = (unsigned int)dataLen;
uncompr = (uint8_t *)calloc(1, dataLen);
d_stream.next_out = uncompr;
d_stream.avail_out = (unsigned int)dataLen;
for (;;) {
err = PREFIX(inflate)(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END)
break;
if (err == Z_NEED_DICT) {
if (d_stream.adler != dictId) {
fprintf(stderr, "unexpected dictionary");
exit(1);
}
err = PREFIX(inflateSetDictionary)(
&d_stream, (const unsigned char *)data, dictionaryLen);
for (;;) {
err = PREFIX(inflate)(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END)
break;
if (err == Z_NEED_DICT) {
if (d_stream.adler != dictId) {
fprintf(stderr, "unexpected dictionary");
exit(1);
}
err = PREFIX(inflateSetDictionary)(
&d_stream, (const unsigned char *)data, dictionaryLen);
}
CHECK_ERR(err, "inflate with dict");
}
CHECK_ERR(err, "inflate with dict");
}
err = PREFIX(inflateEnd)(&d_stream);
CHECK_ERR(err, "inflateEnd");
err = PREFIX(inflateEnd)(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (memcmp(uncompr, data, dataLen)) {
fprintf(stderr, "bad inflate with dict\n");
exit(1);
}
if (memcmp(uncompr, data, dataLen)) {
fprintf(stderr, "bad inflate with dict\n");
exit(1);
}
free(uncompr);
free(uncompr);
}
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) {
size_t comprLen = 0;
uint8_t *compr;
size_t comprLen = 0;
uint8_t *compr;
/* Discard inputs larger than 100Kb. */
static size_t kMaxSize = 100 * 1024;
/* Discard inputs larger than 100Kb. */
static size_t kMaxSize = 100 * 1024;
if (size < 1 || size > kMaxSize)
if (size < 1 || size > kMaxSize)
return 0;
data = d;
dataLen = size;
/* Set up the contents of the dictionary. The size of the dictionary is
intentionally selected to be of unusual size. To help cover more corner
cases, the size of the dictionary is read from the input data. */
dictionaryLen = data[0];
if (dictionaryLen > dataLen)
dictionaryLen = (unsigned int)dataLen;
test_dict_deflate(&compr, &comprLen);
test_dict_inflate(compr, comprLen);
free(compr);
/* This function must return 0. */
return 0;
data = d;
dataLen = size;
/* Set up the contents of the dictionary. The size of the dictionary is
intentionally selected to be of unusual size. To help cover more corner
cases, the size of the dictionary is read from the input data. */
dictionaryLen = data[0];
if (dictionaryLen > dataLen)
dictionaryLen = dataLen;
test_dict_deflate(&compr, &comprLen);
test_dict_inflate(compr, comprLen);
free(compr);
/* This function must return 0. */
return 0;
}