From 3221dc0be8edce9e4fbaa5af1311debb298675cb Mon Sep 17 00:00:00 2001 From: QiangHeisenberg <46313511+QiangHeisenberg@users.noreply.github.com> Date: Tue, 21 Jul 2020 14:44:40 +0800 Subject: [PATCH 1/2] Update deflate.go --- src/compress/flate/deflate.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/compress/flate/deflate.go b/src/compress/flate/deflate.go index 550032176d76ca..f64927a7d6ff19 100644 --- a/src/compress/flate/deflate.go +++ b/src/compress/flate/deflate.go @@ -401,9 +401,6 @@ Loop: if !d.sync { break Loop } - if d.index > d.windowEnd { - panic("index > windowEnd") - } if lookahead == 0 { // Flush current output block if any. if d.byteAvailable { @@ -527,10 +524,11 @@ func (d *compressor) fillStore(b []byte) int { } func (d *compressor) store() { - if d.windowEnd > 0 && (d.windowEnd == maxStoreBlockSize || d.sync) { - d.err = d.writeStoredBlock(d.window[:d.windowEnd]) - d.windowEnd = 0 + if !d.sync || d.windowEnd == 0 && d.windowEnd < maxStoreBlockSize { + return } + d.err = d.writeStoredBlock(d.window[:d.windowEnd]) + d.windowEnd = 0 } // storeHuff compresses and stores the currently added data From ea207222c82ba8240bf70f2e67246a4f95920717 Mon Sep 17 00:00:00 2001 From: QiangHeisenberg <46313511+QiangHeisenberg@users.noreply.github.com> Date: Tue, 21 Jul 2020 14:46:07 +0800 Subject: [PATCH 2/2] Update huffman_code.go --- src/compress/flate/huffman_code.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/compress/flate/huffman_code.go b/src/compress/flate/huffman_code.go index 891537ed5e6343..aa2e3798056849 100644 --- a/src/compress/flate/huffman_code.go +++ b/src/compress/flate/huffman_code.go @@ -287,12 +287,9 @@ func (h *huffmanEncoder) generate(freq []int32, maxBits int32) { list[count] = literalNode{uint16(i), f} count++ } else { - list[count] = literalNode{} h.codes[i].len = 0 } } - list[len(freq)] = literalNode{} - list = list[:count] if count <= 2 { // Handle the small cases here, because they are awkward for the general case code. With