commit cb7adc2901ab8582b02d3a77e9139c3fb70c6a49
parent 144b062df1777a3fe05588e5c62d5e4aed9f4c13
Author: nsz@tpx <unknown>
Date: Fri, 7 Aug 2009 10:50:26 +0200
deflate match: let it overflow
Diffstat:
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/deflate.c b/deflate.c
@@ -509,30 +509,28 @@ static Match getmatch(State *s, ushort pos, ushort mpos) {
ushort chainlen = MaxChainLen;
uchar *q;
uchar *p = s->win + pos;
- uchar *end = p + maxlen;
+ uchar *end = p + MaxMatch; /* out of bound if avail < MaxMatch */
do {
q = s->win + mpos;
/* at least m.len+1 long */
if (q[m.len] != p[m.len] || q[0] != p[0])
continue;
- /* loop unroll: MaxMatch % 10 == 8 */
-/* TODO: if maxlen == MaxMatch
+ /* loop unroll: MaxMatch % 10 == 8, overflow if avail < MaxMatch */
while (*++q == *++p && *++q == *++p
&& *++q == *++p && *++q == *++p
&& *++q == *++p && *++q == *++p
&& *++q == *++p && ++p != end && *++q == *p
&& *++q == *++p && *++q == *++p);
len = MaxMatch - (end - p);
-*/
- while (++p != end && *++q == *p);
- len = maxlen - (end - p);
p -= len;
if (len > m.len) {
m.dist = pos - mpos;
- m.len = len;
- if (len == maxlen)
+ if (len >= maxlen) {
+ m.len = maxlen;
return m;
+ }
+ m.len = len;
}
} while ((mpos = s->chain[mpos % WinSize]) > limit && --chainlen);
if (m.len < MinMatch || (m.len == MinMatch && m.dist > BigDist))
@@ -577,7 +575,7 @@ static int fillwin(State *s) {
static int deflate_state(State *s) {
Match m;
Match prevm = {0, 0};
- int pos = s->pos;
+ int pos;
int head;
/* messy.. */
diff --git a/flate.h b/flate.h
@@ -7,7 +7,7 @@ enum {
FlateOk = 0,
FlateErr = -1,
FlateIn = -2,
- FlateOut = -3,
+ FlateOut = -3
};
/* TODO inflate assume Flate* < 0 */