Factor test/data/artificial into many directories

This commit is contained in:
Nigel Tao committed 2021-11-16 15:37:57 +11:00
1 parent 37ac4def8e
commit 3642d73714
53 files changed
+49 -49

No files matched your search

@@ -0,0 +1,29 @@
Running backref-crosses-blocks.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x00 0b_...._.000 Uncompressed block, non-final
000001 0x0001 . 0x04 0b_0000_0100 Literal length: 0x0004
000002 0x0002 . 0x00 0b_0000_0000
000003 0x0003 . 0xFB 0b_1111_1011 Inverse: 0xFFFB
000004 0x0004 . 0xFF 0b_1111_1111
000005 0x0005 a 0x61 0b_0110_0001 Literal "abcd"
000006 0x0006 b 0x62 0b_0110_0010
000007 0x0007 c 0x63 0b_0110_0011
000008 0x0008 d 0x64 0b_0110_0100
The fixed Huffman block contains a back-reference (into the previous block)
then an end of block. The length=3, distance=2 back-reference decodes to "cdc",
so the overall decoding is "abcdcdc".
000009 0x0009 . 0x03 0b_...._.011 Fixed Huffman block, final
000009 0x0009 . 0x03 0b_0000_0... lcode: 257 length: 3
000010 0x000A B 0x42 0b_...._..10
000010 0x000A B 0x42 0b_.100_00.. dcode: 1 distance: 2
000010 0x000A B 0x42 0b_0..._.... lcode: 256 end of block
000011 0x000B . 0x00 0b_..00_0000
This back-reference is valid, even though there is no prior data in that block,
because there is prior data in previous blocks. RFC 1951 section 2 "Compressed
representation overview" says that "the LZ77 algorithm may use a reference to a
duplicated string occurring in a previous block".
@@ -0,0 +1 @@
abcdcdc
@@ -0,0 +1,14 @@
# Feed this file to script/make-artificial.go
make deflate
blockNoCompression (nonFinal) {
literal "abcd"
}
blockFixedHuffman (final) {
len 3 dist 2
endOfBlock
}
# The decompressed data is 4 + 3 = 7 bytes:
# abcdcdc
@@ -0,0 +1,66 @@
Running degenerate-huffman-unused.deflate through script/print-bits.go and
adding commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x05 0b_...._.101 Dynamic Huffman block, final
000000 0x0000 . 0x05 0b_0000_0... NumLCodes: 257
000001 0x0001 . 0xC0 0b_...0_0000 NumDCodes: 1
000001 0x0001 . 0xC0 0b_110._.... NumCLCodeLengths: 18
000002 0x0002 ! 0x21 0b_...._...1
Decode the H-CL Huffman table (NumCLCodeLengths = 18). Recall the peculiar
code_order: 16, 17, 18, 0, 8, ..., 2, 14, 1, 15:
000002 0x0002 ! 0x21 0b_0010_000. CLCodeLengths: 18 x 3 bits
000003 0x0003 . 0x01 0b_0000_0001 CLCLs[ 1] is 2
000004 0x0004 . 0x00 0b_0000_0000 CLCLs[ 2] is 2
000005 0x0005 . 0x00 0b_0000_0000 CLCLs[17] is 2
000006 0x0006 . 0x00 0b_0000_0000 CLCLs[18] is 2
000007 0x0007 . 0x80 0b_1000_0000
000008 0x0008 . 0xA0 0b_.010_0000
The H-CL Huffman table is:
"00" -> CodeLength=1
"01" -> CodeLength=2
"10" -> CodeLength=17 which means a block of ( 3 + 3_extra_bits) zeroes
"11" -> CodeLength=18 which means a block of (11 + 7_extra_bits) zeroes
Decode the H-L Huffman table (NumLCodes = 257):
000008 0x0008 . 0xA0 0b_1..._.... "11" is CL=18: 11+7extra
000009 0x0009 . 0xB7 0b_...._...1
000009 0x0009 . 0xB7 0b_1011_011. 7extra=91: 102 zeroes
000010 0x000A V 0x56 0b_...._..10 "01" is CL= 2 (102='f')
000010 0x000A V 0x56 0b_...._01.. "10" is CL=17: 3+3extra
000010 0x000A V 0x56 0b_.101_.... 3extra=5: 8 zeroes
000010 0x000A V 0x56 0b_0..._.... "00" is CL= 1 (111='o')
000011 0x000B . 0xFE 0b_...._...0
000011 0x000B . 0xFE 0b_...._.11. "11" is CL=18: 11+7extra
000011 0x000B . 0xFE 0b_1111_1... 7extra=127: 138 zeroes
000012 0x000C 7 0x37 0b_...._..11
000012 0x000C 7 0x37 0b_...._01.. "10" is CL=17: 3+3extra
000012 0x000C 7 0x37 0b_.011_.... 3extra=3: 6 zeroes
000012 0x000C 7 0x37 0b_0..._.... "01" is CL=2 (256=EOB)
000013 0x000D . 0x89 0b_...._...1
The H-L Huffman table is:
"0" -> 'o'
"10" -> 'f'
"11" -> EOB
Decode the H-D Huffman table (NumDCodes = 1):
000013 0x000D . 0x89 0b_...._.00. "00" is CL= 1 (DCode 0)
The H-D Huffman table is:
"0" -> 0
This table is incomplete: there is no entry starting with a "1" bit. It is
therefore degenerate, but not used below.
Apply H-L and H-D.
000013 0x000D . 0x89 0b_...0_1... lcode: 102 literal 'f'
000013 0x000D . 0x89 0b_..0._.... lcode: 111 literal 'o'
000013 0x000D . 0x89 0b_.0.._.... lcode: 111 literal 'o'
000013 0x000D . 0x89 0b_1..._.... lcode: 256 end of block
000014 0x000E . 0x01 0b_...._...1
@@ -0,0 +1,27 @@
# Feed this file to script/make-artificial.go
make deflate
blockDynamicHuffman (final) {
huffman CodeLength {
1 00
2 01
17 10
18 11
}
huffman Literal/Length {
# 102='f', 111='o', 256=EOB
111 0
102 10
256 11
}
huffman Distance {
# Incomplete. There is no key/value pair whose value starts with "1".
0 0
}
literal "foo"
endOfBlock
}
Binary file not shown.
@@ -0,0 +1,52 @@
Running distance-32768.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 K 0x4B 0b_...._.011 Fixed Huffman block, final
000000 0x0000 K 0x4B 0b_0100_1... lcode: 97 literal 'a'
000001 0x0001 L 0x4C 0b_...._.100
000001 0x0001 L 0x4C 0b_0100_1... lcode: 98 literal 'b'
000002 0x0002 J 0x4A 0b_...._.010
etc
000015 0x000F 3 0x33 0b_0011_0... lcode: 55 literal '7'
000016 0x0010 . 0x1F 0b_...._.111
000016 0x0010 . 0x1F 0b_0001_1... lcode: 285 length: 258
000017 0x0011 . 0xA5 0b_...._.101
000017 0x0011 . 0xA5 0b_1010_0... dcode: 5 base: 7
000018 0x0012 G 0x47 0b_...._...1 extra: 1 distance: 8
000018 0x0012 G 0x47 0b_0100_011. lcode: 285 length: 258
000019 0x0013 . 0xE9 0b_...._...1
000019 0x0013 . 0xE9 0b_..10_100. dcode: 5 base: 7
000019 0x0013 . 0xE9 0b_.1.._.... extra: 1 distance: 8
etc
000236 0x00EC . 0xE9 0b_1..._.... lcode: 284 base: 227
000237 0x00ED . 0x91 0b_.001_0001
000237 0x00ED . 0x91 0b_1..._.... extra: 17 length: 244
000238 0x00EE H 0x48 0b_...._1000
000238 0x00EE H 0x48 0b_0100_.... dcode: 5 base: 7
000239 0x00EF . 0x03 0b_...._...1
000239 0x00EF . 0x03 0b_...._..1. extra: 1 distance: 8
000239 0x00EF . 0x03 0b_0000_00.. lcode: 257 length: 3
000240 0x00F0 . 0xEF 0b_...._...1
000240 0x00F0 . 0xEF 0b_..10_111. dcode: 29 base: 24577
000240 0x00F0 . 0xEF 0b_11.._.... extra: 8191 distance: 32768
000241 0x00F1 . 0xFF 0b_1111_1111
000242 0x00F2 . 0x07 0b_...._.111
000242 0x00F2 . 0x07 0b_0000_0... lcode: 257 length: 3
000243 0x00F3 * 0x2A 0b_...._..10
000243 0x00F3 * 0x2A 0b_.010_10.. dcode: 10 base: 33
000243 0x00F3 * 0x2A 0b_0..._.... extra: 2 distance: 35
000244 0x00F4 . 0x01 0b_...._.001
000244 0x00F4 . 0x01 0b_0000_0... lcode: 257 length: 3
000245 0x00F5 . 0xDE 0b_...._..10
000245 0x00F5 . 0xDE 0b_.101_11.. dcode: 29 base: 24577
000245 0x00F5 . 0xDE 0b_1..._.... extra: 8191 distance: 32768
000246 0x00F6 . 0xFF 0b_1111_1111
000247 0x00F7 . 0x0F 0b_...._1111
000247 0x00F7 . 0x0F 0b_0000_.... lcode: 258 length: 4
000248 0x00F8 . 0xBA 0b_...._.010
000248 0x00F8 . 0xBA 0b_1011_1... dcode: 29 base: 24577
000249 0x00F9 . 0xFE 0b_1111_1110 extra: 8190 distance: 32767
000250 0x00FA . 0x1F 0b_...1_1111
000250 0x00FA . 0x1F 0b_000._.... lcode: 256 end of block
000251 0x00FB . 0x00 0b_...._0000
@@ -0,0 +1 @@
abcdefgh01234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456701234567012345670123456Line truncated
@@ -0,0 +1,30 @@
# Feed this file to script/make-artificial.go
make deflate
blockFixedHuffman (final) {
# Make 16 + 126*258 + 244 = 32768 bytes:
# abcdefgh0123456701234567...01234567
literal "abcdefgh01234567"
repeat 126 [
len 258 dist 8
]
len 244 dist 8
# Copy "abc".
len 3 dist 32768
# Copy "012".
len 3 dist 35
# Copy "gh0".
len 3 dist 32768
# Copy "2345".
len 4 dist 32767
endOfBlock
}
# The decompressed data is 32768 + 3 + 3 + 3 + 4 = 32781 bytes:
# abcdefgh0123456701234567...01234567abc012gh02345
@@ -0,0 +1 @@
~
@@ -0,0 +1,8 @@
Running distance-code-31.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x03 0b_...._.011 Fixed Huffman block, final
000000 0x0000 . 0x03 0b_0000_0... lcode: 257 length: 3
000001 0x0001 ~ 0x7E 0b_...._..10
000001 0x0001 ~ 0x7E 0b_.111_11.. dcode: 31 INVALID
Whitespace-only changes.
@@ -0,0 +1,19 @@
# Feed this file to script/make-artificial.go
make deflate
# RFC 1951 section 3.2.6 says that for fixed Huffman codes, "distance codes
# 30-31 will never actually occur in the compressed data", and likewise for
# literal/length values 286-287.
#
# This dates from a more innocent time, before widespread concerns about
# malicious actors deliberately supplying invalid input to probe for security
# vulnerabilities. Upon encountering such input, a robust decoder shouldn't
# enter an internally inconsistent state.
#
# In terms of the Wuffs implementation (and error message convention), we
# should return an error, as it is indeed invalid input, but we shouldn't
# return an "internal error".
blockFixedHuffman (final) {
len 3 distCode 31
}
@@ -0,0 +1 @@
逹m�$I�$I#quwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww�面面面面面面面面面面面爺=��Wwwww鰐面勿黠璧嫌萱
@@ -0,0 +1,112 @@
Running huffman-primlen-9.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0xED 0b_...._.101 Dynamic Huffman block, final
000000 0x0000 . 0xED 0b_1110_1... NumLCodes: 286
000001 0x0001 . 0xFD 0b_...1_1101 NumDCodes: 30
000001 0x0001 . 0xFD 0b_111._.... NumCLCodeLengths: 19
000002 0x0002 m 0x6D 0b_...._...1
Decode the H-CL Huffman table (NumCLCodeLengths = 18). Recall the peculiar
code_order: 16, 17, 18, 0, 8, ..., 2, 14, 1, 15:
000002 0x0002 m 0x6D 0b_0110_110. CLCodeLengths: 19 x 3 bits
000003 0x0003 . 0x93 0b_1001_0011 CLCLs[ 0] is 4
000004 0x0004 $ 0x24 0b_0010_0100 CLCLs[...] is 4
000005 0x0005 I 0x49 0b_0100_1001 CLCLs[ 14] is 4
000006 0x0006 . 0x92 0b_1001_0010 CLCLs[ 15] is 6
000007 0x0007 $ 0x24 0b_0010_0100 CLCLs[ 16] is 6
000008 0x0008 I 0x49 0b_0100_1001 CLCLs[ 17] is 6
000009 0x0009 # 0x23 0b_...._..11 CLCLs[ 18] is 6
The H-CL Huffman table is:
"0000" -> CodeLength=0
"0001" -> CodeLength=1
"0010" -> CodeLength=2
etc
"1110" -> CodeLength=14
"111100" -> CodeLength=15
"111101" -> CodeLength=16 which means run-length encoding
"111110" -> CodeLength=17 which means a block of ( 3 + 3_extra_bits) zeroes
"111111" -> CodeLength=18 which means a block of (11 + 7_extra_bits) zeroes
Decode the H-L Huffman table (NumLCodes = 286):
000009 0x0009 # 0x23 0b_..10_00.. "0001" is CL=1
000009 0x0009 # 0x23 0b_00.._.... "0010" is CL=2
000010 0x000A q 0x71 0b_...._..01
000010 0x000A q 0x71 0b_..11_00.. "0011" is CL=3
000010 0x000A q 0x71 0b_01.._....
000011 0x000B u 0x75 0b_...._..01 "1010" is CL=10
000011 0x000B u 0x75 0b_..11_01.. "1011" is CL=11
000011 0x000B u 0x75 0b_01.._.... "1011" is CL=11
000012 0x000C w 0x77 0b_...._..11
000012 0x000C w 0x77 0b_..11_01.. "1011" is CL=11
etc
000149 0x0095 . 0xCC 0b_..00_11.. "1100" is CL=12
000149 0x0095 . 0xCC 0b_11.._.... "1100" is CL=12
000150 0x0096 . 0xEC 0b_...._..00
000150 0x0096 . 0xEC 0b_..10_11.. "1101" is CL=13
000150 0x0096 . 0xEC 0b_11.._.... "1110" is CL=14
000151 0x0097 = 0x3D 0b_...._..01
000151 0x0097 = 0x3D 0b_0011_11.. "111100" is CL=15
000152 0x0098 . 0x0F 0b_..00_1111 "111100" is CL=15
The H-L Huffman table is:
"0" -> '\x00'
"10" -> '\x01'
"110" -> '\x02'
"1110000000" -> '\x03'
"11100000010" -> '\x04'
etc
"11101011111" -> '\x61' aka 'a' aka 97
"11101100000" -> '\x62' aka 'b' aka 98
etc
"111111100101" -> Lit/Len code 256 (EOB)
"111111100110" -> Lit/Len code 257 (Length = 3)
etc
"111111111111111" -> Lit/Len code 285 (Length = 258)
Decode the H-D Huffman table (NumDCodes = 30):
000152 0x0098 . 0x0F 0b_00.._.... "0001" is CL=1
000153 0x0099 . 0x12 0b_...._..10
000153 0x0099 . 0x12 0b_..01_00.. "0010" is CL=2
000153 0x0099 . 0x12 0b_00.._....
000154 0x009A . 0x8B 0b_...._..11 "0011" is CL=3
000154 0x009A . 0x8B 0b_..00_10.. "0100" is CL=4
etc
000165 0x00A5 . 0xCC 0b_..00_11.. "1100" is CL=12
000165 0x00A5 . 0xCC 0b_11.._.... "1101" is CL=13
000166 0x00A6 . 0xDE 0b_...._..10
000166 0x00A6 . 0xDE 0b_..01_11.. "1110" is CL=14
000166 0x00A6 . 0xDE 0b_11.._.... "111100" is CL=15
000167 0x00A7 . 0xF3 0b_...._0011
000167 0x00A7 . 0xF3 0b_1111_.... "111100" is CL=15
000168 0x00A8 . 0xDC 0b_...._..00
The H-D Huffman table is:
"0" -> Distance code 0 (Distance = 1)
"10" -> Distance code 1 (Distance = 2)
"110" -> Distance code 2 (Distance = 3)
etc
"11111110010" -> Distance code 8 (Distance = 17 + 3_extra_bits)
etc
"111111111111111" -> Distance code 29 (Distance = 24577 + 13_extra_bits)
Apply H-L and H-D. The length=3, distance=2 back-reference decodes to "ana", so
the overall decoding is "banana".
000168 0x00A8 . 0xDC 0b_1101_11.. lcode: 98 literal 'b'
000169 0x00A9 . 0xE0 0b_...0_0000
000169 0x00A9 . 0xE0 0b_111._.... lcode: 97 literal 'a'
000170 0x00AA . 0xFA 0b_1111_1010
000171 0x00AB . 0xB7 0b_1011_0111 lcode: 110 literal 'n'
000172 0x00AC . 0xF9 0b_...._.001
000172 0x00AC . 0xF9 0b_1111_1... lcode: 256 length=3
000173 0x00AD . 0xB3 0b_.011_0011
000173 0x00AD . 0xB3 0b_1..._.... dcode: 1 distance=2
000174 0x00AE . 0xFE 0b_...._...0
000174 0x00AE . 0xFE 0b_1111_111. lcode: 256 end of block
000175 0x00AF . 0x14 0b_...1_0100
@@ -0,0 +1 @@
banana
@@ -0,0 +1,93 @@
# Feed this file to script/make-artificial.go
make deflate
blockDynamicHuffman (final) {
huffman CodeLength {
# 15 codes of length 4.
0 0000
1 0001
etcetera
13 1101
14 1110
# 4 codes of length 6.
15 111100
16 111101
17 111110
18 111111
}
# script/print-deflate-huff-table-size.go prints:
# primLen 9: 852 entries = 512 prim + 340 seco
# @1 @2 @3 @4 @5 @6 @7 @8 @9 @10 @11 @12 @13 @14 @15
# 1 1 1 0 0 0 0 0 0; 1 229 49 1 1 2
huffman Literal/Length {
0 0
1 10
2 110
3 1110000000
# 229 codes of length 11.
4 11100000010
5 11100000011
etcetera
231 11111100101
232 11111100110
# 49 codes of length 12.
233 111111001110
234 111111001111
etcetera
256 111111100101
257 111111100110
etcetera
280 111111111101
281 111111111110
# 1+1+2 = 4 codes of length 13+.
282 1111111111110
283 11111111111110
284 111111111111110
285 111111111111111
}
# script/print-deflate-huff-table-size.go prints:
# primLen 9: 592 entries = 512 prim + 80 seco
# @1 @2 @3 @4 @5 @6 @7 @8 @9 @10 @11 @12 @13 @14 @15
# 1 1 1 1 1 1 1 0 0; 1 9 9 1 1 2
huffman Distance {
0 0
1 10
2 110
3 1110
4 11110
5 111110
6 1111110
7 1111111000
# 9 codes of length 11.
8 11111110010
9 11111110011
etcetera
15 11111111001
16 11111111010
# 9 codes of length 12.
17 111111110110
18 111111110111
etcetera
24 111111111101
25 111111111110
# 1+1+2 = 4 codes of length 13+.
26 1111111111110
27 11111111111110
28 111111111111110
29 111111111111111
}
literal "ban"
len 3 dist 2
endOfBlock
}