Update zlib-intel to v1.2.11.1_jtkv6.3 (dotnet/corefx#36795)
authorEric StJohn <ericstj@microsoft.com>
Fri, 12 Apr 2019 13:20:07 +0000 (06:20 -0700)
committerStephen Toub <stoub@microsoft.com>
Fri, 12 Apr 2019 13:20:07 +0000 (09:20 -0400)
* 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 https://github.com/dotnet/corefx/commit/6322a406f88e854c5b827ab838f988f8992048f8

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

index f6f671c..582e8b2 100644 (file)
@@ -94,8 +94,10 @@ static void insert_match(deflate_state *s, struct match match)
                 match.strstart += match.match_length;
                 match.match_length = 0;
                 s->ins_h = s->window[match.strstart];
-                if (match.strstart >= 1)
-                    UPDATE_HASH(s, s->ins_h, match.strstart+2-MIN_MATCH);
+                if (match.strstart >= 1) {
+                    IPos hash_head = 0;
+                   INSERT_STRING(s, match.strstart - 1, hash_head);
+                }
 #if MIN_MATCH != 3
 #warning Call UPDATE_HASH() MIN_MATCH-3 more times
 #endif
@@ -214,6 +216,9 @@ block_state deflate_medium(deflate_state *s, int flush)
             if (s->lookahead >= MIN_MATCH) {
                 INSERT_STRING(s, s->strstart, hash_head);
             }
+
+            if (hash_head && hash_head == s->strstart)
+                hash_head--;
         
             /* set up the initial match to be a 1 byte literal */
             current_match.match_start = 0;
@@ -247,6 +252,9 @@ block_state deflate_medium(deflate_state *s, int flush)
         if (s->lookahead > MIN_LOOKAHEAD) {
             s->strstart = current_match.strstart + current_match.match_length;
             INSERT_STRING(s, s->strstart, hash_head);
+
+            if (hash_head && hash_head == s->strstart)
+                hash_head--;
         
             /* set up the initial match to be a 1 byte literal */
             next_match.match_start = 0;
index 6179e16..165e465 100644 (file)
@@ -239,6 +239,9 @@ int stream_size;
         return ret;
     }
 
+    if (state->wbits == 0)
+           state->wbits = 15;
+
     if (state->wbits > 0) {
         state->wsize = 1UL << state->wbits;
         state->window = (unsigned char FAR *)ZALLOC(strm, state->wsize + 16, 4);