mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +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
+15
-1
@@ -342,7 +342,21 @@ func (p *parser) parseFieldNode() (*a.Node, error) {
|
||||
}
|
||||
|
||||
func (p *parser) parseExtraFieldNode() (*a.Node, error) {
|
||||
return p.parseFieldNode1(a.FlagsPrivateData)
|
||||
n, err := p.parseFieldNode1(a.FlagsPrivateData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
typ := n.AsField().XType()
|
||||
for typ.Decorator() == t.IDArray {
|
||||
typ = typ.Inner()
|
||||
}
|
||||
if (typ.Decorator() != 0) ||
|
||||
(typ.QID()[0] == t.IDBase) && (!typ.IsNumType() || typ.IsRefined()) {
|
||||
|
||||
return nil, fmt.Errorf(`parse: invalid extra-field type %q at %s:%d`,
|
||||
n.AsField().XType().Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (p *parser) parseFieldNode1(flags a.Flags) (*a.Node, error) {
|
||||
|
||||
@@ -6930,7 +6930,9 @@ wuffs_deflate__decoder__init_dynamic_huffman(wuffs_deflate__decoder* self,
|
||||
status = v_status;
|
||||
goto exit;
|
||||
}
|
||||
v_mask = ((((uint32_t)(1)) << self->private_data.f_n_huffs_bits[0]) - 1);
|
||||
v_mask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[0], 9)) -
|
||||
1);
|
||||
v_i = 0;
|
||||
label_0_continue:;
|
||||
while (v_i < (v_n_lit + v_n_dist)) {
|
||||
@@ -6975,7 +6977,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(wuffs_deflate__decoder* self,
|
||||
status = wuffs_deflate__error__bad_huffman_code_length_repetition;
|
||||
goto exit;
|
||||
}
|
||||
v_rep_symbol = self->private_data.f_code_lengths[(v_i - 1)];
|
||||
v_rep_symbol = (self->private_data.f_code_lengths[(v_i - 1)] & 15);
|
||||
v_rep_count = 3;
|
||||
} else if (v_table_entry == 17) {
|
||||
v_n_extra_bits = 3;
|
||||
@@ -7104,10 +7106,10 @@ wuffs_deflate__decoder__init_huff(wuffs_deflate__decoder* self,
|
||||
|
||||
v_i = a_n_codes0;
|
||||
while (v_i < a_n_codes1) {
|
||||
if (v_counts[self->private_data.f_code_lengths[v_i]] >= 320) {
|
||||
if (v_counts[(self->private_data.f_code_lengths[v_i] & 15)] >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
}
|
||||
v_counts[self->private_data.f_code_lengths[v_i]] += 1;
|
||||
v_counts[(self->private_data.f_code_lengths[v_i] & 15)] += 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((((uint32_t)(v_counts[0])) + a_n_codes0) == a_n_codes1) {
|
||||
@@ -7148,12 +7150,12 @@ wuffs_deflate__decoder__init_huff(wuffs_deflate__decoder* self,
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
}
|
||||
if (self->private_data.f_code_lengths[v_i] != 0) {
|
||||
if (v_offsets[self->private_data.f_code_lengths[v_i]] >= 320) {
|
||||
if (v_offsets[(self->private_data.f_code_lengths[v_i] & 15)] >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
}
|
||||
v_symbols[v_offsets[self->private_data.f_code_lengths[v_i]]] =
|
||||
v_symbols[v_offsets[(self->private_data.f_code_lengths[v_i] & 15)]] =
|
||||
((uint16_t)((v_i - a_n_codes0)));
|
||||
v_offsets[self->private_data.f_code_lengths[v_i]] += 1;
|
||||
v_offsets[(self->private_data.f_code_lengths[v_i] & 15)] += 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
@@ -7196,8 +7198,9 @@ label_1_break:;
|
||||
if (v_max_cl < 9) {
|
||||
v_initial_high_bits = (((uint32_t)(1)) << v_max_cl);
|
||||
}
|
||||
v_prev_cl = ((uint32_t)(self->private_data.f_code_lengths[(
|
||||
a_n_codes0 + ((uint32_t)(v_symbols[0])))]));
|
||||
v_prev_cl = ((uint32_t)((self->private_data.f_code_lengths[(
|
||||
a_n_codes0 + ((uint32_t)(v_symbols[0])))] &
|
||||
15)));
|
||||
v_prev_redirect_key = 4294967295;
|
||||
v_top = 0;
|
||||
v_next_top = 512;
|
||||
@@ -7208,8 +7211,9 @@ label_1_break:;
|
||||
if ((a_n_codes0 + ((uint32_t)(v_symbols[v_i]))) >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
}
|
||||
v_cl = ((uint32_t)(self->private_data.f_code_lengths[(
|
||||
a_n_codes0 + ((uint32_t)(v_symbols[v_i])))]));
|
||||
v_cl = ((uint32_t)((self->private_data.f_code_lengths[(
|
||||
a_n_codes0 + ((uint32_t)(v_symbols[v_i])))] &
|
||||
15)));
|
||||
if (v_cl > v_prev_cl) {
|
||||
v_code <<= (v_cl - v_prev_cl);
|
||||
if (v_code >= 32768) {
|
||||
@@ -7362,8 +7366,12 @@ wuffs_deflate__decoder__decode_huffman_fast(wuffs_deflate__decoder* self,
|
||||
}
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint32_t)(1)) << self->private_data.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint32_t)(1)) << self->private_data.f_n_huffs_bits[1]) - 1);
|
||||
v_lmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[0], 9)) -
|
||||
1);
|
||||
v_dmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[1], 9)) -
|
||||
1);
|
||||
label_0_continue:;
|
||||
while ((((uint64_t)(io1_a_dst - iop_a_dst)) >= 258) &&
|
||||
(((uint64_t)(io1_a_src - iop_a_src)) >= 12)) {
|
||||
@@ -7699,8 +7707,12 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
||||
}
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint32_t)(1)) << self->private_data.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint32_t)(1)) << self->private_data.f_n_huffs_bits[1]) - 1);
|
||||
v_lmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[0], 9)) -
|
||||
1);
|
||||
v_dmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[1], 9)) -
|
||||
1);
|
||||
label_0_continue:;
|
||||
while (!(self->private_impl.p_decode_huffman_slow[0] != 0)) {
|
||||
while (true) {
|
||||
@@ -8370,7 +8382,7 @@ wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
|
||||
}
|
||||
v_steps -= 1;
|
||||
v_o = ((v_o - 8) & 8191);
|
||||
v_c = ((uint32_t)(self->private_data.f_prefixes[v_c]));
|
||||
v_c = (((uint32_t)(self->private_data.f_prefixes[v_c])) & 4095);
|
||||
}
|
||||
label_1_break:;
|
||||
v_first_byte = self->private_data.f_suffixes[v_c][0];
|
||||
|
||||
@@ -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