Format code with clang-format
This commit is contained in:
parent
60ec4a72b9
commit
8714fd3cd8
@ -44,3 +44,4 @@ SpacesInCStyleCastParentheses: false
|
|||||||
SpaceAfterControlStatementKeyword: true
|
SpaceAfterControlStatementKeyword: true
|
||||||
SpaceBeforeAssignmentOperators: true
|
SpaceBeforeAssignmentOperators: true
|
||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
|
SortIncludes: false
|
||||||
@ -7,12 +7,12 @@ typedef unsigned short uint16;
|
|||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
|
||||||
// The string to compress.
|
// The string to compress.
|
||||||
static const char *s_pStr = "Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
static const char *s_pStr = "Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson.";
|
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson.";
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
@ -21,12 +21,12 @@ typedef unsigned int uint;
|
|||||||
|
|
||||||
// The string to compress.
|
// The string to compress.
|
||||||
static const char *s_pTest_str =
|
static const char *s_pTest_str =
|
||||||
"MISSION CONTROL I wouldn't worry too much about the computer. First of all, there is still a chance that he is right, despite your tests, and" \
|
"MISSION CONTROL I wouldn't worry too much about the computer. First of all, there is still a chance that he is right, despite your tests, and"
|
||||||
"if it should happen again, we suggest eliminating this possibility by allowing the unit to remain in place and seeing whether or not it" \
|
"if it should happen again, we suggest eliminating this possibility by allowing the unit to remain in place and seeing whether or not it"
|
||||||
"actually fails. If the computer should turn out to be wrong, the situation is still not alarming. The type of obsessional error he may be" \
|
"actually fails. If the computer should turn out to be wrong, the situation is still not alarming. The type of obsessional error he may be"
|
||||||
"guilty of is not unknown among the latest generation of HAL 9000 computers. It has almost always revolved around a single detail, such as" \
|
"guilty of is not unknown among the latest generation of HAL 9000 computers. It has almost always revolved around a single detail, such as"
|
||||||
"the one you have described, and it has never interfered with the integrity or reliability of the computer's performance in other areas." \
|
"the one you have described, and it has never interfered with the integrity or reliability of the computer's performance in other areas."
|
||||||
"No one is certain of the cause of this kind of malfunctioning. It may be over-programming, but it could also be any number of reasons. In any" \
|
"No one is certain of the cause of this kind of malfunctioning. It may be over-programming, but it could also be any number of reasons. In any"
|
||||||
"event, it is somewhat analogous to human neurotic behavior. Does this answer your query? Zero-five-three-Zero, MC, transmission concluded.";
|
"event, it is somewhat analogous to human neurotic behavior. Does this answer your query? Zero-five-three-Zero, MC, transmission concluded.";
|
||||||
|
|
||||||
static const char *s_pComment = "This is a comment";
|
static const char *s_pComment = "This is a comment";
|
||||||
|
|||||||
@ -29,12 +29,17 @@ static void hsv_to_rgb(int hue, int min, int max, rgb_t *p)
|
|||||||
const int saturation = 1;
|
const int saturation = 1;
|
||||||
const int color_rotate = 0;
|
const int color_rotate = 0;
|
||||||
|
|
||||||
if (min == max) max = min + 1;
|
if (min == max)
|
||||||
if (invert) hue = max - (hue - min);
|
max = min + 1;
|
||||||
if (!saturation) {
|
if (invert)
|
||||||
|
hue = max - (hue - min);
|
||||||
|
if (!saturation)
|
||||||
|
{
|
||||||
p->r = p->g = p->b = 255 * (max - hue) / (max - min);
|
p->r = p->g = p->b = 255 * (max - hue) / (max - min);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
const double h_dbl = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6);
|
const double h_dbl = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6);
|
||||||
const double c_dbl = 255 * saturation;
|
const double c_dbl = 255 * saturation;
|
||||||
const double X_dbl = c_dbl * (1 - fabs(fmod(h_dbl, 2) - 1));
|
const double X_dbl = c_dbl * (1 - fabs(fmod(h_dbl, 2) - 1));
|
||||||
@ -44,13 +49,31 @@ static void hsv_to_rgb(int hue, int min, int max, rgb_t *p)
|
|||||||
|
|
||||||
p->r = p->g = p->b = 0;
|
p->r = p->g = p->b = 0;
|
||||||
|
|
||||||
switch(h) {
|
switch (h)
|
||||||
case 0: p->r = c; p->g = X; return;
|
{
|
||||||
case 1: p->r = X; p->g = c; return;
|
case 0:
|
||||||
case 2: p->g = c; p->b = X; return;
|
p->r = c;
|
||||||
case 3: p->g = X; p->b = c; return;
|
p->g = X;
|
||||||
case 4: p->r = X; p->b = c; return;
|
return;
|
||||||
default:p->r = c; p->b = X;
|
case 1:
|
||||||
|
p->r = X;
|
||||||
|
p->g = c;
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
p->g = c;
|
||||||
|
p->b = X;
|
||||||
|
return;
|
||||||
|
case 3:
|
||||||
|
p->g = X;
|
||||||
|
p->b = c;
|
||||||
|
return;
|
||||||
|
case 4:
|
||||||
|
p->r = X;
|
||||||
|
p->b = c;
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
p->r = c;
|
||||||
|
p->b = X;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
miniz.c
9
miniz.c
@ -31,7 +31,8 @@ typedef unsigned char mz_validate_uint32[sizeof(mz_uint32) == 4 ? 1 : -1];
|
|||||||
typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1];
|
typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1];
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------- zlib-style API's */
|
/* ------------------- zlib-style API's */
|
||||||
@ -93,8 +94,7 @@ mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len);
|
|||||||
*/
|
*/
|
||||||
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
|
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
|
||||||
{
|
{
|
||||||
static const mz_uint32 s_crc_table[256] =
|
static const mz_uint32 s_crc_table[256] = {
|
||||||
{
|
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
|
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
|
||||||
0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
|
0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
|
||||||
0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
|
0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
|
||||||
@ -602,8 +602,7 @@ const char *mz_error(int err)
|
|||||||
{
|
{
|
||||||
int m_err;
|
int m_err;
|
||||||
const char *m_pDesc;
|
const char *m_pDesc;
|
||||||
} s_error_descs[] =
|
} s_error_descs[] = {
|
||||||
{
|
|
||||||
{ MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
|
{ MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
|
||||||
};
|
};
|
||||||
mz_uint i;
|
mz_uint i;
|
||||||
|
|||||||
3
miniz.h
3
miniz.h
@ -223,7 +223,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------- zlib-style API Definitions. */
|
/* ------------------- zlib-style API Definitions. */
|
||||||
|
|||||||
@ -81,7 +81,8 @@ typedef struct mz_dummy_time_t_tag
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size);
|
extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size);
|
||||||
|
|||||||
24
miniz_tdef.c
24
miniz_tdef.c
@ -29,14 +29,14 @@
|
|||||||
#ifndef MINIZ_NO_DEFLATE_APIS
|
#ifndef MINIZ_NO_DEFLATE_APIS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------- Low-level Compression (independent from all decompression API's) */
|
/* ------------------- Low-level Compression (independent from all decompression API's) */
|
||||||
|
|
||||||
/* Purposely making these tables static for faster init and thread safety. */
|
/* Purposely making these tables static for faster init and thread safety. */
|
||||||
static const mz_uint16 s_tdefl_len_sym[256] =
|
static const mz_uint16 s_tdefl_len_sym[256] = {
|
||||||
{
|
|
||||||
257, 258, 259, 260, 261, 262, 263, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 269, 269, 270, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 272,
|
257, 258, 259, 260, 261, 262, 263, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 269, 269, 270, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 272,
|
||||||
273, 273, 273, 273, 273, 273, 273, 273, 274, 274, 274, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 275, 275, 275, 276, 276, 276, 276, 276, 276, 276, 276,
|
273, 273, 273, 273, 273, 273, 273, 273, 274, 274, 274, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 275, 275, 275, 276, 276, 276, 276, 276, 276, 276, 276,
|
||||||
277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
||||||
@ -47,16 +47,14 @@ static const mz_uint16 s_tdefl_len_sym[256] =
|
|||||||
284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 285
|
284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 285
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mz_uint8 s_tdefl_len_extra[256] =
|
static const mz_uint8 s_tdefl_len_extra[256] = {
|
||||||
{
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mz_uint8 s_tdefl_small_dist_sym[512] =
|
static const mz_uint8 s_tdefl_small_dist_sym[512] = {
|
||||||
{
|
|
||||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
|
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
|
||||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
|
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
|
||||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||||
@ -71,8 +69,7 @@ static const mz_uint8 s_tdefl_small_dist_sym[512] =
|
|||||||
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17
|
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mz_uint8 s_tdefl_small_dist_extra[512] =
|
static const mz_uint8 s_tdefl_small_dist_extra[512] = {
|
||||||
{
|
|
||||||
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
|
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||||
@ -83,15 +80,13 @@ static const mz_uint8 s_tdefl_small_dist_extra[512] =
|
|||||||
7, 7, 7, 7, 7, 7, 7, 7
|
7, 7, 7, 7, 7, 7, 7, 7
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mz_uint8 s_tdefl_large_dist_sym[128] =
|
static const mz_uint8 s_tdefl_large_dist_sym[128] = {
|
||||||
{
|
|
||||||
0, 0, 18, 19, 20, 20, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
0, 0, 18, 19, 20, 20, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mz_uint8 s_tdefl_large_dist_extra[128] =
|
static const mz_uint8 s_tdefl_large_dist_extra[128] = {
|
||||||
{
|
|
||||||
0, 0, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
0, 0, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13
|
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13
|
||||||
@ -631,7 +626,8 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush)
|
|||||||
|
|
||||||
/* Determine compression level by reversing the process in tdefl_create_comp_flags_from_zip_params() */
|
/* Determine compression level by reversing the process in tdefl_create_comp_flags_from_zip_params() */
|
||||||
for (i = 0; i < mz_un; i++)
|
for (i = 0; i < mz_un; i++)
|
||||||
if (s_tdefl_num_probes[i] == (d->m_flags & 0xFFF)) break;
|
if (s_tdefl_num_probes[i] == (d->m_flags & 0xFFF))
|
||||||
|
break;
|
||||||
|
|
||||||
if (i < 2)
|
if (i < 2)
|
||||||
flevel = 0;
|
flevel = 0;
|
||||||
|
|||||||
@ -4,7 +4,8 @@
|
|||||||
#ifndef MINIZ_NO_DEFLATE_APIS
|
#ifndef MINIZ_NO_DEFLATE_APIS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
/* ------------------- Low-level Compression API Definitions */
|
/* ------------------- Low-level Compression API Definitions */
|
||||||
|
|
||||||
@ -115,7 +116,8 @@ enum
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. */
|
/* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
TDEFL_STATUS_BAD_PARAM = -2,
|
TDEFL_STATUS_BAD_PARAM = -2,
|
||||||
TDEFL_STATUS_PUT_BUF_FAILED = -1,
|
TDEFL_STATUS_PUT_BUF_FAILED = -1,
|
||||||
TDEFL_STATUS_OKAY = 0,
|
TDEFL_STATUS_OKAY = 0,
|
||||||
@ -123,7 +125,8 @@ typedef enum {
|
|||||||
} tdefl_status;
|
} tdefl_status;
|
||||||
|
|
||||||
/* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */
|
/* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
TDEFL_NO_FLUSH = 0,
|
TDEFL_NO_FLUSH = 0,
|
||||||
TDEFL_SYNC_FLUSH = 2,
|
TDEFL_SYNC_FLUSH = 2,
|
||||||
TDEFL_FULL_FLUSH = 3,
|
TDEFL_FULL_FLUSH = 3,
|
||||||
|
|||||||
@ -29,7 +29,8 @@
|
|||||||
#ifndef MINIZ_NO_INFLATE_APIS
|
#ifndef MINIZ_NO_INFLATE_APIS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------- Low-level Decompression (completely independent from all compression API's) */
|
/* ------------------- Low-level Decompression (completely independent from all compression API's) */
|
||||||
|
|||||||
@ -5,7 +5,8 @@
|
|||||||
#ifndef MINIZ_NO_INFLATE_APIS
|
#ifndef MINIZ_NO_INFLATE_APIS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
/* Decompression flags used by tinfl_decompress(). */
|
/* Decompression flags used by tinfl_decompress(). */
|
||||||
/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */
|
/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */
|
||||||
@ -55,7 +56,8 @@ MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor *pDecomp);
|
|||||||
#define TINFL_LZ_DICT_SIZE 32768
|
#define TINFL_LZ_DICT_SIZE 32768
|
||||||
|
|
||||||
/* Return status. */
|
/* Return status. */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
/* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
|
/* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
|
||||||
/* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
|
/* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
|
||||||
/* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
|
/* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
|
||||||
|
|||||||
23
miniz_zip.c
23
miniz_zip.c
@ -29,7 +29,8 @@
|
|||||||
#ifndef MINIZ_NO_ARCHIVE_APIS
|
#ifndef MINIZ_NO_ARCHIVE_APIS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------- .ZIP archive reading */
|
/* ------------------- .ZIP archive reading */
|
||||||
@ -1483,8 +1484,7 @@ mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, co
|
|||||||
return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
|
return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static mz_bool mz_zip_reader_extract_to_mem_no_alloc1(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size, const mz_zip_archive_file_stat *st)
|
||||||
mz_bool mz_zip_reader_extract_to_mem_no_alloc1(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size, const mz_zip_archive_file_stat *st)
|
|
||||||
{
|
{
|
||||||
int status = TINFL_STATUS_DONE;
|
int status = TINFL_STATUS_DONE;
|
||||||
mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
|
mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
|
||||||
@ -1497,10 +1497,11 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc1(mz_zip_archive *pZip, mz_uint fil
|
|||||||
if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
|
if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
|
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
|
||||||
|
|
||||||
if (st) {
|
if (st)
|
||||||
|
{
|
||||||
file_stat = *st;
|
file_stat = *st;
|
||||||
} else
|
}
|
||||||
if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
|
else if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
|
||||||
/* A directory or zero length file */
|
/* A directory or zero length file */
|
||||||
@ -3302,10 +3303,8 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|||||||
if (!pState->m_zip64)
|
if (!pState->m_zip64)
|
||||||
{
|
{
|
||||||
/* Bail early if the archive would obviously become too large */
|
/* Bail early if the archive would obviously become too large */
|
||||||
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size
|
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
|
||||||
+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
|
pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len + MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF)
|
||||||
pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len
|
|
||||||
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF)
|
|
||||||
{
|
{
|
||||||
pState->m_zip64 = MZ_TRUE;
|
pState->m_zip64 = MZ_TRUE;
|
||||||
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
|
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
|
||||||
@ -3563,9 +3562,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
|
|||||||
if (!pState->m_zip64)
|
if (!pState->m_zip64)
|
||||||
{
|
{
|
||||||
/* Bail early if the archive would obviously become too large */
|
/* Bail early if the archive would obviously become too large */
|
||||||
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
|
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024 + MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
|
||||||
+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024
|
|
||||||
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
|
|
||||||
{
|
{
|
||||||
pState->m_zip64 = MZ_TRUE;
|
pState->m_zip64 = MZ_TRUE;
|
||||||
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
|
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
|
||||||
|
|||||||
16
miniz_zip.h
16
miniz_zip.h
@ -7,7 +7,8 @@
|
|||||||
#ifndef MINIZ_NO_ARCHIVE_APIS
|
#ifndef MINIZ_NO_ARCHIVE_APIS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -82,14 +83,16 @@ typedef mz_bool (*mz_file_needs_keepalive)(void *pOpaque);
|
|||||||
struct mz_zip_internal_state_tag;
|
struct mz_zip_internal_state_tag;
|
||||||
typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
|
typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MZ_ZIP_MODE_INVALID = 0,
|
MZ_ZIP_MODE_INVALID = 0,
|
||||||
MZ_ZIP_MODE_READING = 1,
|
MZ_ZIP_MODE_READING = 1,
|
||||||
MZ_ZIP_MODE_WRITING = 2,
|
MZ_ZIP_MODE_WRITING = 2,
|
||||||
MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
|
MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
|
||||||
} mz_zip_mode;
|
} mz_zip_mode;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
|
MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
|
||||||
MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
|
MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
|
||||||
MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
|
MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
|
||||||
@ -104,7 +107,8 @@ typedef enum {
|
|||||||
MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000
|
MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000
|
||||||
} mz_zip_flags;
|
} mz_zip_flags;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MZ_ZIP_TYPE_INVALID = 0,
|
MZ_ZIP_TYPE_INVALID = 0,
|
||||||
MZ_ZIP_TYPE_USER,
|
MZ_ZIP_TYPE_USER,
|
||||||
MZ_ZIP_TYPE_MEMORY,
|
MZ_ZIP_TYPE_MEMORY,
|
||||||
@ -115,7 +119,8 @@ typedef enum {
|
|||||||
} mz_zip_type;
|
} mz_zip_type;
|
||||||
|
|
||||||
/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
|
/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MZ_ZIP_NO_ERROR = 0,
|
MZ_ZIP_NO_ERROR = 0,
|
||||||
MZ_ZIP_UNDEFINED_ERROR,
|
MZ_ZIP_UNDEFINED_ERROR,
|
||||||
MZ_ZIP_TOO_MANY_FILES,
|
MZ_ZIP_TOO_MANY_FILES,
|
||||||
@ -394,7 +399,6 @@ MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, c
|
|||||||
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||||
|
|
||||||
|
|
||||||
#ifndef MINIZ_NO_STDIO
|
#ifndef MINIZ_NO_STDIO
|
||||||
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
|
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
|
||||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||||
|
|||||||
@ -13,7 +13,8 @@ static const size_t kMaxSize = 1024 * 1024;
|
|||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen)
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen)
|
||||||
{
|
{
|
||||||
/* Discard inputs larger than 1Mb. */
|
/* Discard inputs larger than 1Mb. */
|
||||||
if (dataLen < 1 || dataLen > kMaxSize) return 0;
|
if (dataLen < 1 || dataLen > kMaxSize)
|
||||||
|
return 0;
|
||||||
|
|
||||||
uint32_t crc = crc32(0L, NULL, 0);
|
uint32_t crc = crc32(0L, NULL, 0);
|
||||||
uint32_t adler = adler32(0L, NULL, 0);
|
uint32_t adler = adler32(0L, NULL, 0);
|
||||||
|
|||||||
@ -26,7 +26,10 @@ static void check_compress_level(uint8_t *compr, size_t comprLen,
|
|||||||
assert(0 == memcmp(data, uncompr, dataLen));
|
assert(0 == memcmp(data, uncompr, dataLen));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define put_byte(s, i, c) {s[i] = (unsigned char)(c);}
|
#define put_byte(s, i, c) \
|
||||||
|
{ \
|
||||||
|
s[i] = (unsigned char)(c); \
|
||||||
|
}
|
||||||
|
|
||||||
static void write_zlib_header(uint8_t *s)
|
static void write_zlib_header(uint8_t *s)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
#include "miniz.h"
|
#include "miniz.h"
|
||||||
|
|
||||||
#define CHECK_ERR(err, msg) { \
|
#define CHECK_ERR(err, msg) \
|
||||||
if (err != Z_OK) { \
|
{ \
|
||||||
|
if (err != Z_OK) \
|
||||||
|
{ \
|
||||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} \
|
} \
|
||||||
@ -23,7 +25,6 @@ static size_t dataLen;
|
|||||||
static alloc_func zalloc = NULL;
|
static alloc_func zalloc = NULL;
|
||||||
static free_func zfree = NULL;
|
static free_func zfree = NULL;
|
||||||
|
|
||||||
|
|
||||||
void test_flush(unsigned char *compr, size_t *comprLen)
|
void test_flush(unsigned char *compr, size_t *comprLen)
|
||||||
{
|
{
|
||||||
z_stream c_stream; /* compression stream */
|
z_stream c_stream; /* compression stream */
|
||||||
|
|||||||
@ -30,7 +30,8 @@ int main(int argc, char **argv)
|
|||||||
siz_buf = ftell(f);
|
siz_buf = ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
|
|
||||||
if(siz_buf < 1) goto err;
|
if (siz_buf < 1)
|
||||||
|
goto err;
|
||||||
|
|
||||||
buf = (char *)malloc(siz_buf);
|
buf = (char *)malloc(siz_buf);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
|
|||||||
@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
#include "miniz.h"
|
#include "miniz.h"
|
||||||
|
|
||||||
#define CHECK_ERR(err, msg) { \
|
#define CHECK_ERR(err, msg) \
|
||||||
if (err != Z_OK) { \
|
{ \
|
||||||
|
if (err != Z_OK) \
|
||||||
|
{ \
|
||||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} \
|
} \
|
||||||
@ -94,7 +96,8 @@ void test_large_inflate(unsigned char *compr, size_t comprLen,
|
|||||||
d_stream.next_out = uncompr; /* discard the output */
|
d_stream.next_out = uncompr; /* discard the output */
|
||||||
d_stream.avail_out = (unsigned int)uncomprLen;
|
d_stream.avail_out = (unsigned int)uncomprLen;
|
||||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||||
if (err == Z_STREAM_END) break;
|
if (err == Z_STREAM_END)
|
||||||
|
break;
|
||||||
|
|
||||||
CHECK_ERR(err, "large inflate");
|
CHECK_ERR(err, "large inflate");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
#include "miniz.h"
|
#include "miniz.h"
|
||||||
|
|
||||||
#define CHECK_ERR(err, msg) { \
|
#define CHECK_ERR(err, msg) \
|
||||||
if (err != Z_OK) { \
|
{ \
|
||||||
|
if (err != Z_OK) \
|
||||||
|
{ \
|
||||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} \
|
} \
|
||||||
|
|||||||
@ -14,7 +14,8 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|||||||
{
|
{
|
||||||
unsigned long int buffer_length = sizeof(buffer);
|
unsigned long int buffer_length = sizeof(buffer);
|
||||||
|
|
||||||
if (Z_OK != uncompress2(buffer, &buffer_length, data, &size)) return 0;
|
if (Z_OK != uncompress2(buffer, &buffer_length, data, &size))
|
||||||
|
return 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,8 @@ static const size_t data_max = 1024 * 256;
|
|||||||
|
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
if(size > data_max) return 0;
|
if (size > data_max)
|
||||||
|
return 0;
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
mz_zip_archive zip;
|
mz_zip_archive zip;
|
||||||
@ -20,7 +21,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
|||||||
|
|
||||||
mz_uint flags = 0;
|
mz_uint flags = 0;
|
||||||
|
|
||||||
if(!mz_zip_reader_init_mem(&zip, data, size, flags)) return 0;
|
if (!mz_zip_reader_init_mem(&zip, data, size, flags))
|
||||||
|
return 0;
|
||||||
|
|
||||||
mz_uint i, files;
|
mz_uint i, files;
|
||||||
|
|
||||||
@ -30,22 +32,26 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
|||||||
{
|
{
|
||||||
mz_zip_clear_last_error(&zip);
|
mz_zip_clear_last_error(&zip);
|
||||||
|
|
||||||
if(mz_zip_reader_is_file_a_directory(&zip, i)) continue;
|
if (mz_zip_reader_is_file_a_directory(&zip, i))
|
||||||
|
continue;
|
||||||
|
|
||||||
mz_zip_validate_file(&zip, i, MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY);
|
mz_zip_validate_file(&zip, i, MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY);
|
||||||
|
|
||||||
if(mz_zip_reader_is_file_encrypted(&zip, i)) continue;
|
if (mz_zip_reader_is_file_encrypted(&zip, i))
|
||||||
|
continue;
|
||||||
|
|
||||||
mz_zip_clear_last_error(&zip);
|
mz_zip_clear_last_error(&zip);
|
||||||
|
|
||||||
mz_uint ret = mz_zip_reader_get_filename(&zip, i, filename, filename_max);
|
mz_uint ret = mz_zip_reader_get_filename(&zip, i, filename, filename_max);
|
||||||
|
|
||||||
if(mz_zip_get_last_error(&zip)) continue;
|
if (mz_zip_get_last_error(&zip))
|
||||||
|
continue;
|
||||||
|
|
||||||
mz_zip_archive_file_stat file_stat = { 0 };
|
mz_zip_archive_file_stat file_stat = { 0 };
|
||||||
mz_bool status = mz_zip_reader_file_stat(&zip, i, &file_stat) != 0;
|
mz_bool status = mz_zip_reader_file_stat(&zip, i, &file_stat) != 0;
|
||||||
|
|
||||||
if ((file_stat.m_method) && (file_stat.m_method != MZ_DEFLATED)) continue;
|
if ((file_stat.m_method) && (file_stat.m_method != MZ_DEFLATED))
|
||||||
|
continue;
|
||||||
|
|
||||||
mz_zip_reader_extract_file_to_mem(&zip, file_stat.m_filename, read_buf, read_buf_size, 0);
|
mz_zip_reader_extract_file_to_mem(&zip, file_stat.m_filename, read_buf, read_buf_size, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user