mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 10:20:57 +00:00
(libz) Backport 9852c209ac
This commit is contained in:
parent
da9a0786f7
commit
2063f4ac41
51
deps/libz/inflate.c
vendored
51
deps/libz/inflate.c
vendored
@ -125,9 +125,11 @@ int inflateResetKeep(z_streamp strm)
|
|||||||
|
|
||||||
int inflateReset(z_streamp strm)
|
int inflateReset(z_streamp strm)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
struct inflate_state FAR *state;
|
struct inflate_state FAR *state;
|
||||||
|
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL)
|
if ( strm == Z_NULL ||
|
||||||
|
strm->state == Z_NULL)
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
state = (struct inflate_state FAR *)strm->state;
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
@ -135,7 +137,9 @@ int inflateReset(z_streamp strm)
|
|||||||
state->whave = 0;
|
state->whave = 0;
|
||||||
state->wnext = 0;
|
state->wnext = 0;
|
||||||
|
|
||||||
return inflateResetKeep(strm);
|
ret = inflateResetKeep(strm);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inflateReset2(z_streamp strm, int windowBits)
|
int inflateReset2(z_streamp strm, int windowBits)
|
||||||
@ -157,7 +161,7 @@ int inflateReset2(z_streamp strm, int windowBits)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wrap = (windowBits >> 4) + 1;
|
wrap = (windowBits >> 4) + 5;
|
||||||
#ifdef GUNZIP
|
#ifdef GUNZIP
|
||||||
if (windowBits < 48)
|
if (windowBits < 48)
|
||||||
windowBits &= 15;
|
windowBits &= 15;
|
||||||
@ -657,14 +661,16 @@ int inflate(z_streamp strm, int flush)
|
|||||||
}
|
}
|
||||||
if (state->head != Z_NULL)
|
if (state->head != Z_NULL)
|
||||||
state->head->text = (int)((hold >> 8) & 1);
|
state->head->text = (int)((hold >> 8) & 1);
|
||||||
if (state->flags & 0x0200) CRC2(state->check, hold);
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
|
CRC2(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
state->mode = TIME;
|
state->mode = TIME;
|
||||||
case TIME:
|
case TIME:
|
||||||
NEEDBITS(32);
|
NEEDBITS(32);
|
||||||
if (state->head != Z_NULL)
|
if (state->head != Z_NULL)
|
||||||
state->head->time = hold;
|
state->head->time = hold;
|
||||||
if (state->flags & 0x0200) CRC4(state->check, hold);
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
|
CRC4(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
state->mode = OS;
|
state->mode = OS;
|
||||||
case OS:
|
case OS:
|
||||||
@ -673,7 +679,8 @@ int inflate(z_streamp strm, int flush)
|
|||||||
state->head->xflags = (int)(hold & 0xff);
|
state->head->xflags = (int)(hold & 0xff);
|
||||||
state->head->os = (int)(hold >> 8);
|
state->head->os = (int)(hold >> 8);
|
||||||
}
|
}
|
||||||
if (state->flags & 0x0200) CRC2(state->check, hold);
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
|
CRC2(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
state->mode = EXLEN;
|
state->mode = EXLEN;
|
||||||
case EXLEN:
|
case EXLEN:
|
||||||
@ -682,7 +689,8 @@ int inflate(z_streamp strm, int flush)
|
|||||||
state->length = (unsigned)(hold);
|
state->length = (unsigned)(hold);
|
||||||
if (state->head != Z_NULL)
|
if (state->head != Z_NULL)
|
||||||
state->head->extra_len = (unsigned)hold;
|
state->head->extra_len = (unsigned)hold;
|
||||||
if (state->flags & 0x0200) CRC2(state->check, hold);
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
|
CRC2(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
}
|
}
|
||||||
else if (state->head != Z_NULL)
|
else if (state->head != Z_NULL)
|
||||||
@ -700,7 +708,7 @@ int inflate(z_streamp strm, int flush)
|
|||||||
len + copy > state->head->extra_max ?
|
len + copy > state->head->extra_max ?
|
||||||
state->head->extra_max - len : copy);
|
state->head->extra_max - len : copy);
|
||||||
}
|
}
|
||||||
if (state->flags & 0x0200)
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
state->check = crc32(state->check, next, copy);
|
state->check = crc32(state->check, next, copy);
|
||||||
have -= copy;
|
have -= copy;
|
||||||
next += copy;
|
next += copy;
|
||||||
@ -721,7 +729,7 @@ int inflate(z_streamp strm, int flush)
|
|||||||
state->length < state->head->name_max)
|
state->length < state->head->name_max)
|
||||||
state->head->name[state->length++] = len;
|
state->head->name[state->length++] = len;
|
||||||
} while (len && copy < have);
|
} while (len && copy < have);
|
||||||
if (state->flags & 0x0200)
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
state->check = crc32(state->check, next, copy);
|
state->check = crc32(state->check, next, copy);
|
||||||
have -= copy;
|
have -= copy;
|
||||||
next += copy;
|
next += copy;
|
||||||
@ -742,7 +750,7 @@ int inflate(z_streamp strm, int flush)
|
|||||||
state->length < state->head->comm_max)
|
state->length < state->head->comm_max)
|
||||||
state->head->comment[state->length++] = len;
|
state->head->comment[state->length++] = len;
|
||||||
} while (len && copy < have);
|
} while (len && copy < have);
|
||||||
if (state->flags & 0x0200)
|
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||||
state->check = crc32(state->check, next, copy);
|
state->check = crc32(state->check, next, copy);
|
||||||
have -= copy;
|
have -= copy;
|
||||||
next += copy;
|
next += copy;
|
||||||
@ -754,7 +762,7 @@ int inflate(z_streamp strm, int flush)
|
|||||||
case HCRC:
|
case HCRC:
|
||||||
if (state->flags & 0x0200) {
|
if (state->flags & 0x0200) {
|
||||||
NEEDBITS(16);
|
NEEDBITS(16);
|
||||||
if (hold != (state->check & 0xffff)) {
|
if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
|
||||||
strm->msg = (char *)"header crc mismatch";
|
strm->msg = (char *)"header crc mismatch";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
@ -1097,11 +1105,11 @@ int inflate(z_streamp strm, int flush)
|
|||||||
out -= left;
|
out -= left;
|
||||||
strm->total_out += out;
|
strm->total_out += out;
|
||||||
state->total += out;
|
state->total += out;
|
||||||
if (out)
|
if ((state->wrap & 4) && out)
|
||||||
strm->adler = state->check =
|
strm->adler = state->check =
|
||||||
UPDATE(state->check, put - out, out);
|
UPDATE(state->check, put - out, out);
|
||||||
out = left;
|
out = left;
|
||||||
if ((
|
if ((state->wrap & 4) && (
|
||||||
#ifdef GUNZIP
|
#ifdef GUNZIP
|
||||||
state->flags ? hold :
|
state->flags ? hold :
|
||||||
#endif
|
#endif
|
||||||
@ -1158,7 +1166,7 @@ inf_leave:
|
|||||||
strm->total_in += in;
|
strm->total_in += in;
|
||||||
strm->total_out += out;
|
strm->total_out += out;
|
||||||
state->total += out;
|
state->total += out;
|
||||||
if (state->wrap && out)
|
if ((state->wrap & 4) && out)
|
||||||
strm->adler = state->check =
|
strm->adler = state->check =
|
||||||
UPDATE(state->check, strm->next_out - out, out);
|
UPDATE(state->check, strm->next_out - out, out);
|
||||||
strm->data_type = state->bits + (state->last ? 64 : 0) +
|
strm->data_type = state->bits + (state->last ? 64 : 0) +
|
||||||
@ -1482,6 +1490,21 @@ int inflateUndermine(z_streamp strm, int subvert)
|
|||||||
return Z_DATA_ERROR;
|
return Z_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int inflateValidate(z_streamp strm, int check)
|
||||||
|
{
|
||||||
|
struct inflate_state FAR *state;
|
||||||
|
|
||||||
|
if ( strm == Z_NULL ||
|
||||||
|
strm->state == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
|
if (check)
|
||||||
|
state->wrap |= 4;
|
||||||
|
else
|
||||||
|
state->wrap &= ~4;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
long inflateMark(z_streamp strm)
|
long inflateMark(z_streamp strm)
|
||||||
{
|
{
|
||||||
struct inflate_state FAR *state = NULL;
|
struct inflate_state FAR *state = NULL;
|
||||||
|
3
deps/libz/inflate.h
vendored
3
deps/libz/inflate.h
vendored
@ -84,7 +84,8 @@ typedef enum {
|
|||||||
struct inflate_state {
|
struct inflate_state {
|
||||||
inflate_mode mode; /* current inflate mode */
|
inflate_mode mode; /* current inflate mode */
|
||||||
int last; /* true if processing last block */
|
int last; /* true if processing last block */
|
||||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
|
||||||
|
bit 2 true to validate check value */
|
||||||
int havedict; /* true if dictionary provided */
|
int havedict; /* true if dictionary provided */
|
||||||
int flags; /* gzip header method and flags (0 if zlib) */
|
int flags; /* gzip header method and flags (0 if zlib) */
|
||||||
unsigned long check; /* protected copy of check value */
|
unsigned long check; /* protected copy of check value */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user