mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
1 parent
e1b43cd767
commit
9256fe5e54
8 files changed
+81
-10
No files matched your search
@@ -6827,7 +6827,6 @@ extern const char wuffs_bzip2__error__bad_block_header[];
|
||||
extern const char wuffs_bzip2__error__bad_block_length[];
|
||||
extern const char wuffs_bzip2__error__bad_checksum[];
|
||||
extern const char wuffs_bzip2__error__bad_header[];
|
||||
extern const char wuffs_bzip2__error__bad_number_of_huffman_codes[];
|
||||
extern const char wuffs_bzip2__error__bad_number_of_sections[];
|
||||
extern const char wuffs_bzip2__error__unsupported_huffman_code[];
|
||||
extern const char wuffs_bzip2__error__unsupported_block_randomization[];
|
||||
@@ -24866,7 +24865,6 @@ const char wuffs_bzip2__error__bad_block_header[] = "#bzip2: bad block header";
|
||||
const char wuffs_bzip2__error__bad_block_length[] = "#bzip2: bad block length";
|
||||
const char wuffs_bzip2__error__bad_checksum[] = "#bzip2: bad checksum";
|
||||
const char wuffs_bzip2__error__bad_header[] = "#bzip2: bad header";
|
||||
const char wuffs_bzip2__error__bad_number_of_huffman_codes[] = "#bzip2: bad number of Huffman codes";
|
||||
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
|
||||
const char wuffs_bzip2__error__unsupported_huffman_code[] = "#bzip2: unsupported Huffman code";
|
||||
const char wuffs_bzip2__error__unsupported_block_randomization[] = "#bzip2: unsupported block randomization";
|
||||
@@ -26192,6 +26190,10 @@ wuffs_bzip2__decoder__decode_huffman_fast(
|
||||
} else {
|
||||
v_ticks = 49;
|
||||
v_section += 1;
|
||||
if (v_section >= self->private_impl.f_num_sections) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_number_of_sections);
|
||||
goto exit;
|
||||
}
|
||||
v_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(v_section & 32767)] & 7)];
|
||||
}
|
||||
v_bits |= (wuffs_base__peek_u32be__no_bounds_check(iop_a_src) >> v_n_bits);
|
||||
@@ -26311,6 +26313,10 @@ wuffs_bzip2__decoder__decode_huffman_slow(
|
||||
} else {
|
||||
self->private_impl.f_decode_huffman_ticks = 49;
|
||||
self->private_impl.f_decode_huffman_section += 1;
|
||||
if (self->private_impl.f_decode_huffman_section >= self->private_impl.f_num_sections) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_number_of_sections);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(self->private_impl.f_decode_huffman_section & 32767)] & 7)];
|
||||
}
|
||||
v_node_index = 0;
|
||||
|
||||
@@ -18,7 +18,6 @@ pub status "#bad block header"
|
||||
pub status "#bad block length"
|
||||
pub status "#bad checksum"
|
||||
pub status "#bad header"
|
||||
pub status "#bad number of Huffman codes"
|
||||
pub status "#bad number of sections"
|
||||
pub status "#unsupported Huffman code"
|
||||
pub status "#unsupported block randomization"
|
||||
|
||||
@@ -45,6 +45,9 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
} else {
|
||||
ticks = 49
|
||||
section ~mod+= 1
|
||||
if section >= this.num_sections {
|
||||
return "#bad number of sections"
|
||||
}
|
||||
which = CLAMP_TO_5[this.huffman_selectors[section & 32767] & 7]
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ pri func decoder.decode_huffman_slow?(src: base.io_reader) {
|
||||
} else {
|
||||
this.decode_huffman_ticks = 49
|
||||
this.decode_huffman_section ~mod+= 1
|
||||
if this.decode_huffman_section >= this.num_sections {
|
||||
return "#bad number of sections"
|
||||
}
|
||||
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[this.decode_huffman_section & 32767] & 7]
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,11 @@ golden_test g_bzip2_256_bytes_gt = {
|
||||
.src_filename = "test/data/256.bytes.bz2",
|
||||
};
|
||||
|
||||
golden_test g_bzip2_bad_number_of_sections_gt = {
|
||||
.want_filename = "test/data/0.bytes",
|
||||
.src_filename = "test/data/artificial-bzip2/bad-number-of-sections.bz2",
|
||||
};
|
||||
|
||||
golden_test g_bzip2_midsummer_gt = {
|
||||
.want_filename = "test/data/midsummer.txt",
|
||||
.src_filename = "test/data/midsummer.txt.bz2",
|
||||
@@ -137,6 +142,19 @@ test_wuffs_bzip2_decode_256_bytes() {
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_bad_number_of_sections() {
|
||||
CHECK_FOCUS(__func__);
|
||||
const char* have =
|
||||
do_test_io_buffers(wuffs_bzip2_decode, &g_bzip2_bad_number_of_sections_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
const char* want = wuffs_bzip2__error__bad_number_of_sections;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("have \"%s\", want \"%s\"", have, want);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_midsummer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -227,6 +245,7 @@ bench_mimic_bzip2_decode_100k() {
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_bzip2_decode_256_bytes,
|
||||
test_wuffs_bzip2_decode_bad_number_of_sections,
|
||||
test_wuffs_bzip2_decode_interface,
|
||||
test_wuffs_bzip2_decode_midsummer,
|
||||
test_wuffs_bzip2_decode_pi,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
# This script generates test/data/abraca.txt.bz2 exactly, following the
|
||||
# description in std/bzip2/README.md and its sections (a) ..= (s).
|
||||
# description in std/bzip2/README.md and its bitslices (a) ..= (s).
|
||||
#
|
||||
# By itself, this isn't a very interesting foo.make-artificial.txt file, in
|
||||
# that it doesn't make *artificial* bzip2 test data (as opposed to test data
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
make bzip2
|
||||
|
||||
# Sections (a) ..= (g)
|
||||
# Bitslices (a) ..= (g)
|
||||
bits 16 0x425A
|
||||
bits 8 0x68
|
||||
bits 8 0x39
|
||||
@@ -19,21 +19,21 @@ bits 32 0x76A70995
|
||||
bits 1 0x0
|
||||
bits 24 0x000001
|
||||
|
||||
# Sections (h) ..= (j)
|
||||
# Bitslices (h) ..= (j)
|
||||
bits 16 0x0300
|
||||
bits 16 0x7000
|
||||
bits 16 0x2000
|
||||
|
||||
# Sections (k) ..= (m)
|
||||
# Bitslices (k) ..= (m)
|
||||
bits 3 0x2
|
||||
bits 15 0x0001
|
||||
bits 1 0x0
|
||||
|
||||
# Sections (n) ..= (o)
|
||||
# Bitslices (n) ..= (o)
|
||||
bits 19 0x0CD34
|
||||
bits 19 0x0CD34
|
||||
|
||||
# Section (p)
|
||||
# Bitslice (p)
|
||||
bits 3 0x6
|
||||
bits 2 0x0
|
||||
bits 2 0x1
|
||||
@@ -42,7 +42,7 @@ bits 3 0x4
|
||||
bits 2 0x1
|
||||
bits 3 0x7
|
||||
|
||||
# Sections (q) ..= (s)
|
||||
# Bitslices (q) ..= (s)
|
||||
bits 48 0x177245385090
|
||||
bits 32 0x76A70995
|
||||
bits 5 0x00
|
||||
Binary file not shown.
@@ -0,0 +1,41 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
# This modifies abraca.txt.bz2.make-artificial.txt to have 51 Huffman-coded
|
||||
# symbols (bitslice (p)) but only 1 section (bitslice (l)). At 50 symbols per
|
||||
# section, this should be invalid.
|
||||
|
||||
make bzip2
|
||||
|
||||
# Bitslices (a) ..= (g)
|
||||
bits 16 0x425A
|
||||
bits 8 0x68
|
||||
bits 8 0x39
|
||||
bits 48 0x314159265359
|
||||
bits 32 0x76A70995
|
||||
bits 1 0x0
|
||||
bits 24 0x000001
|
||||
|
||||
# Bitslices (h) ..= (j)
|
||||
bits 16 0x0300
|
||||
bits 16 0x7000
|
||||
bits 16 0x2000
|
||||
|
||||
# Bitslices (k) ..= (m)
|
||||
bits 3 0x2
|
||||
bits 15 0x0001
|
||||
bits 1 0x0
|
||||
|
||||
# Bitslices (n) ..= (o)
|
||||
bits 19 0x0CD34
|
||||
bits 19 0x0CD34
|
||||
|
||||
# Bitslice (p)
|
||||
repeat 50 [
|
||||
bits 2 0x0
|
||||
]
|
||||
bits 3 0x7
|
||||
|
||||
# Bitslices (q) ..= (s)
|
||||
bits 48 0x177245385090
|
||||
bits 32 0x76A70995
|
||||
bits 5 0x00
|
||||
Reference in new issue
Block a user