Skip to content

Commit 2e24e5f

Browse files
ericstjstephentoub
authored andcommitted
Update zlib-intel to v1.2.11.1_jtkv6.3 (dotnet/corefx#36795)
* inflate: handle windowBits == 16 * deflate_medium: add dist -1 to hash even for long matches This fixes an issue where a repeat sequence longer than 258 would be encoded using longer distance values after the first match. * deflate_medium: avoid emitting a suboptimal literal in the restart case When we load new data into the window, we invalidate the next match, in case the match would improve. In this case, the hash has already been updated with this data, so when we look for a new match it will point it back at itself. As a result, a literal is generated even when a better match is available. This avoids that by catching this case and ensuring we're looking at the past. Commit migrated from dotnet/corefx@6322a40
1 parent a0c9a29 commit 2e24e5f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/libraries/Native/Windows/clrcompression/zlib-intel/deflate_medium.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ static void insert_match(deflate_state *s, struct match match)
9494
match.strstart += match.match_length;
9595
match.match_length = 0;
9696
s->ins_h = s->window[match.strstart];
97-
if (match.strstart >= 1)
98-
UPDATE_HASH(s, s->ins_h, match.strstart+2-MIN_MATCH);
97+
if (match.strstart >= 1) {
98+
IPos hash_head = 0;
99+
INSERT_STRING(s, match.strstart - 1, hash_head);
100+
}
99101
#if MIN_MATCH != 3
100102
#warning Call UPDATE_HASH() MIN_MATCH-3 more times
101103
#endif
@@ -214,6 +216,9 @@ block_state deflate_medium(deflate_state *s, int flush)
214216
if (s->lookahead >= MIN_MATCH) {
215217
INSERT_STRING(s, s->strstart, hash_head);
216218
}
219+
220+
if (hash_head && hash_head == s->strstart)
221+
hash_head--;
217222

218223
/* set up the initial match to be a 1 byte literal */
219224
current_match.match_start = 0;
@@ -247,6 +252,9 @@ block_state deflate_medium(deflate_state *s, int flush)
247252
if (s->lookahead > MIN_LOOKAHEAD) {
248253
s->strstart = current_match.strstart + current_match.match_length;
249254
INSERT_STRING(s, s->strstart, hash_head);
255+
256+
if (hash_head && hash_head == s->strstart)
257+
hash_head--;
250258

251259
/* set up the initial match to be a 1 byte literal */
252260
next_match.match_start = 0;

src/libraries/Native/Windows/clrcompression/zlib-intel/inflate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ int stream_size;
239239
return ret;
240240
}
241241

242+
if (state->wbits == 0)
243+
state->wbits = 15;
244+
242245
if (state->wbits > 0) {
243246
state->wsize = 1UL << state->wbits;
244247
state->window = (unsigned char FAR *)ZALLOC(strm, state->wsize + 16, 4);

0 commit comments

Comments
 (0)