diff --git a/src/main/java/com/jcraft/jsch/jzlib/Deflate.java b/src/main/java/com/jcraft/jsch/jzlib/Deflate.java index 4e15b04c..beac568d 100644 --- a/src/main/java/com/jcraft/jsch/jzlib/Deflate.java +++ b/src/main/java/com/jcraft/jsch/jzlib/Deflate.java @@ -1309,7 +1309,9 @@ int longest_match(int cur_match) { && window[++scan] == window[++match] && window[++scan] == window[++match] && scan < strend); - len = MAX_MATCH - strend - scan; + // len here is set to MAX_MATCH minus (strend minus scan, i.e. the distance between scan and + // strend) to ensure that best_len is set to the best possible length to lookahead + len = MAX_MATCH - (strend - scan); scan = strend - MAX_MATCH; if (len > best_len) {