From 42de49a938cbf0f629f298ed36e4ae3e40d889c3 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 9 Jan 2022 10:45:47 +1100 Subject: [PATCH] Have make-artificial.go mark incomplete Huffman --- script/make-artificial.go | 14 ++++++++++++-- .../degenerate-huffman.deflate.make-artificial.txt | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/script/make-artificial.go b/script/make-artificial.go index ebbfedf6..24a4fcd8 100644 --- a/script/make-artificial.go +++ b/script/make-artificial.go @@ -264,8 +264,9 @@ var deflateGlobals struct { huffmans [4]deflateHuffmanTable // DHH (Dynamic Huffman, inside a Huffman table) state. - prevLine string - etcetera bool + prevLine string + etcetera bool + incomplete bool } func deflateGlobalsClearDynamicHuffmanState() { @@ -273,6 +274,7 @@ func deflateGlobalsClearDynamicHuffmanState() { deflateGlobals.huffmans = [4]deflateHuffmanTable{} deflateGlobals.prevLine = "" deflateGlobals.etcetera = false + deflateGlobals.incomplete = false } func deflateGlobalsCountCodes() (numLCodes uint32, numDCodes uint32, numCLCodeLengths uint32, retErr error) { @@ -365,6 +367,9 @@ func deflateGlobalsIsHuffmanCanonical() bool { } prevV = p.v } + if next() != g.incomplete { + return false // Under-subscribed. + } return true } @@ -696,6 +701,7 @@ outer: g.whichHuffman = 0 g.prevLine = "" g.etcetera = false + g.incomplete = false // If we have all three Huffman tables, write them. for i := 1; ; i++ { @@ -716,6 +722,10 @@ outer: g.etcetera = true return stateDeflateDynamicHuffmanHuffman, nil + case line == "incomplete": + g.incomplete = true + return stateDeflateDynamicHuffmanHuffman, nil + default: s := line n, s, ok := parseNum(s) diff --git a/test/data/artificial-deflate/degenerate-huffman.deflate.make-artificial.txt b/test/data/artificial-deflate/degenerate-huffman.deflate.make-artificial.txt index f7598cd9..06937c2d 100644 --- a/test/data/artificial-deflate/degenerate-huffman.deflate.make-artificial.txt +++ b/test/data/artificial-deflate/degenerate-huffman.deflate.make-artificial.txt @@ -22,6 +22,7 @@ blockDynamicHuffman (nonFinal) { # # The sole key/value pair is also unused. (The one below is used.) 0 0 + incomplete } literal "foo" @@ -56,6 +57,7 @@ blockDynamicHuffman (final) { # Per the second table in RFC 1951 section 3.2.5. "Compressed blocks # (length and distance codes)", code 3 means a distance of 4. 3 0 + incomplete } literal "ABCD"