Fix flate decoding across multiple I/O calls.

This commit is contained in:
Nigel Tao committed 2017-10-14 16:27:53 +11:00
1 parent 42933d4557
commit e7d01e7b2a
3 files changed
+26 -28

No files matched your search

+9 -10
View File
@@ -1461,7 +1461,6 @@ puffs_flate_status puffs_flate_decoder_decode_huffman(
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
v_n_copied = 0;
label_5_continue:;
while (true) {
if (((uint64_t)(v_distance)) >
((uint64_t)(b_wptr_dst - b_wstart_dst))) {
@@ -1472,8 +1471,8 @@ puffs_flate_status puffs_flate_decoder_decode_huffman(
v_length -= v_hdist;
v_hlen = v_hdist;
} else {
v_length = 0;
v_hlen = v_length;
v_length = 0;
}
if (self->private_impl.f_history_index < v_hdist) {
status = PUFFS_FLATE_ERROR_BAD_DISTANCE;
@@ -1490,19 +1489,19 @@ puffs_flate_status puffs_flate_decoder_decode_huffman(
v_hlen);
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label_6_break;
goto label_5_break;
}
if (v_n_copied > 0) {
v_hlen -= v_n_copied;
v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767);
if (v_hdist == 0) {
goto label_6_break;
goto label_5_break;
}
}
status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE;
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
}
label_6_break:;
label_5_break:;
if (v_hlen > 0) {
while (true) {
v_n_copied = puffs_base_writer1_copy_from_slice32(
@@ -1514,30 +1513,30 @@ puffs_flate_status puffs_flate_decoder_decode_huffman(
v_hlen);
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label_7_break;
goto label_6_break;
}
v_hlen -= v_n_copied;
v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767);
status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE;
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
}
label_7_break:;
label_6_break:;
}
if (v_length == 0) {
goto label_5_continue;
goto label_0_continue;
}
}
v_n_copied = puffs_base_writer1_copy_from_history32(
&b_wptr_dst, b_wstart_dst, b_wend_dst, v_distance, v_length);
if (v_length <= v_n_copied) {
v_length = 0;
goto label_5_break;
goto label_7_break;
}
v_length -= v_n_copied;
status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE;
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
}
label_5_break:;
label_7_break:;
}
label_0_break:;
self->private_impl.f_bits = v_bits;
+3 -3
View File
@@ -232,7 +232,7 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
var table_entry_n_bits u32[..15]
var lmask u32[..511] = ((1 as u32) << this.n_huffs_bits[0]) - 1
var dmask u32[..511] = ((1 as u32) << this.n_huffs_bits[1]) - 1
while true {
while:loop true {
// Decode an lcode symbol from H-L.
while true {
table_entry = this.huffs[0][bits & lmask]
@@ -371,8 +371,8 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
length -= hdist
hlen = hdist
} else {
length = 0
hlen = length
length = 0
}
if this.history_index < hdist {
return error "bad distance"
@@ -423,7 +423,7 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
if length == 0 {
// No need to copy from in.dst.
continue
continue:loop
}
}
+14 -15
View File
@@ -712,21 +712,20 @@ void bench_mimic_zlib_decode_100k() {
// The empty comments forces clang-format to place one element per line.
proc tests[] = {
// Flate Tests
test_puffs_flate_decode_256_bytes, //
test_puffs_flate_decode_midsummer, //
test_puffs_flate_decode_pi, //
// TODO: uncomment.
// test_puffs_flate_decode_pi_many_big_reads, //
// test_puffs_flate_decode_pi_many_medium_reads, //
// test_puffs_flate_decode_pi_many_small_writes_reads, //
test_puffs_flate_decode_romeo, //
test_puffs_flate_decode_romeo_fixed, //
test_puffs_flate_decode_split_src, //
test_puffs_flate_history_full, //
test_puffs_flate_history_partial, //
test_puffs_flate_table_redirect, //
test_puffs_zlib_decode_midsummer, //
test_puffs_zlib_decode_pi, //
test_puffs_flate_decode_256_bytes, //
test_puffs_flate_decode_midsummer, //
test_puffs_flate_decode_pi, //
test_puffs_flate_decode_pi_many_big_reads, //
test_puffs_flate_decode_pi_many_medium_reads, //
test_puffs_flate_decode_pi_many_small_writes_reads, //
test_puffs_flate_decode_romeo, //
test_puffs_flate_decode_romeo_fixed, //
test_puffs_flate_decode_split_src, //
test_puffs_flate_history_full, //
test_puffs_flate_history_partial, //
test_puffs_flate_table_redirect, //
test_puffs_zlib_decode_midsummer, //
test_puffs_zlib_decode_pi, //
#ifdef PUFFS_MIMIC