mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Check that extra-field types aren't refined
This commit is contained in:
1 parent
21eb64f4c6
commit
92959fb81f
6 files changed
+63
-37
No files matched your search
@@ -107,7 +107,7 @@ pub struct decoder?(
|
||||
//
|
||||
// Exactly one of the eight bits 31-24 should be set.
|
||||
huffs array[2] array[huffs_table_size] base.u32,
|
||||
n_huffs_bits array[2] base.u32[..9],
|
||||
n_huffs_bits array[2] base.u32,
|
||||
|
||||
// history holds up to the last 32KiB of decoded output, if the decoding
|
||||
// was incomplete (e.g. due to a short read or write). RFC 1951 (DEFLATE)
|
||||
@@ -126,7 +126,7 @@ pub struct decoder?(
|
||||
//
|
||||
// code_lengths[args.n_codes0 + i] holds the number of bits in the i'th
|
||||
// code.
|
||||
code_lengths array[320] base.u8[..15],
|
||||
code_lengths array[320] base.u8,
|
||||
)
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
@@ -389,7 +389,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
}
|
||||
|
||||
// Decode the code lengths for the next two Huffman tables.
|
||||
mask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
|
||||
mask = ((1 as base.u32) << (this.n_huffs_bits[0].min(x:9))) - 1
|
||||
i = 0
|
||||
while i < (n_lit + n_dist) {
|
||||
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
|
||||
@@ -433,7 +433,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
if i <= 0 {
|
||||
return "?bad Huffman code length repetition"
|
||||
}
|
||||
rep_symbol = this.code_lengths[i - 1]
|
||||
rep_symbol = this.code_lengths[i - 1] & 15
|
||||
rep_count = 3
|
||||
assert rep_count <= 11
|
||||
} else if table_entry == 17 {
|
||||
@@ -561,10 +561,10 @@ pri func decoder.init_huff!(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
|
||||
// TODO: this if should be unnecessary. Have some way to assert that,
|
||||
// for all j, counts[j] <= i, and thus counts[j]++ will not overflow.
|
||||
if counts[this.code_lengths[i]] >= 320 {
|
||||
if counts[this.code_lengths[i] & 15] >= 320 {
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
counts[this.code_lengths[i]] += 1
|
||||
counts[this.code_lengths[i] & 15] += 1
|
||||
i += 1
|
||||
}
|
||||
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
|
||||
@@ -648,11 +648,11 @@ pri func decoder.init_huff!(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
if this.code_lengths[i] != 0 {
|
||||
if offsets[this.code_lengths[i]] >= 320 {
|
||||
if offsets[this.code_lengths[i] & 15] >= 320 {
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
symbols[offsets[this.code_lengths[i]]] = (i - args.n_codes0) as base.u16
|
||||
offsets[this.code_lengths[i]] += 1
|
||||
symbols[offsets[this.code_lengths[i] & 15]] = (i - args.n_codes0) as base.u16
|
||||
offsets[this.code_lengths[i] & 15] += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
@@ -718,7 +718,7 @@ pri func decoder.init_huff!(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
if max_cl < 9 {
|
||||
initial_high_bits = (1 as base.u32) << max_cl
|
||||
}
|
||||
prev_cl = this.code_lengths[args.n_codes0 + (symbols[0] as base.u32)] as base.u32
|
||||
prev_cl = (this.code_lengths[args.n_codes0 + (symbols[0] as base.u32)] & 15) as base.u32
|
||||
prev_redirect_key = 0xFFFFFFFF
|
||||
top = 0
|
||||
next_top = 512
|
||||
@@ -733,7 +733,7 @@ pri func decoder.init_huff!(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 {
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
cl = this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] as base.u32
|
||||
cl = (this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] & 15) as base.u32
|
||||
if cl > prev_cl {
|
||||
code <<= cl - prev_cl
|
||||
if code >= (1 << 15) {
|
||||
|
||||
@@ -41,8 +41,8 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
|
||||
bits = this.bits
|
||||
n_bits = this.n_bits
|
||||
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0].min(x:9)) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1].min(x:9)) - 1
|
||||
|
||||
// Check up front, on each iteration, that we have enough buffer space to
|
||||
// both read (12 bytes) and write (258 bytes) as much as we need to. Doing
|
||||
|
||||
@@ -45,8 +45,8 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
bits = this.bits
|
||||
n_bits = this.n_bits
|
||||
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0].min(x:9)) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1].min(x:9)) - 1
|
||||
|
||||
while:loop not coroutine_resumed {
|
||||
// Decode an lcode symbol from H-L.
|
||||
|
||||
@@ -57,10 +57,10 @@ pub struct decoder?(
|
||||
)(
|
||||
// read_from per-code state.
|
||||
suffixes array[4096] array[8] base.u8,
|
||||
prefixes array[4096] base.u16[..4095],
|
||||
prefixes array[4096] base.u16,
|
||||
// lm1s is the "length minus 1"s of the values for the implicit key-value
|
||||
// table in this decoder. See std/lzw/README.md for more detail.
|
||||
lm1s array[4096] base.u16[..4095],
|
||||
lm1s array[4096] base.u16,
|
||||
|
||||
// output[output_ri:output_wi] is the buffered output, connecting read_from
|
||||
// with write_to and flush.
|
||||
@@ -199,7 +199,7 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
this.output[output_wi] = code as base.u8
|
||||
output_wi = (output_wi + 1) & 8191
|
||||
if save_code <= 4095 {
|
||||
lm1_a = (this.lm1s[prev_code] + 1) & 4095
|
||||
lm1_a = (this.lm1s[prev_code] ~mod+ 1) & 4095
|
||||
this.lm1s[save_code] = lm1_a
|
||||
|
||||
if (lm1_a % 8) != 0 {
|
||||
@@ -262,7 +262,7 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
// This line is essentially "o -= 8". The "& 8191" is a no-op
|
||||
// in practice, but is necessary for the overflow checker.
|
||||
o = (o ~mod- 8) & 8191
|
||||
c = this.prefixes[c] as base.u32
|
||||
c = (this.prefixes[c] as base.u32) & 4095
|
||||
}
|
||||
first_byte = this.suffixes[c][0]
|
||||
|
||||
@@ -272,7 +272,7 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
}
|
||||
|
||||
if save_code <= 4095 {
|
||||
lm1_b = (this.lm1s[prev_code] + 1) & 4095
|
||||
lm1_b = (this.lm1s[prev_code] ~mod+ 1) & 4095
|
||||
this.lm1s[save_code] = lm1_b
|
||||
|
||||
if (lm1_b % 8) != 0 {
|
||||
|
||||
Reference in new issue
Block a user