mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Add a flate end_of_block field.
This commit is contained in:
1 parent
4810db3994
commit
ded044da41
4 files changed
+43
-16
No files matched your search
+21
-9
@@ -156,17 +156,19 @@ typedef int32_t puffs_flate__status;
|
|||||||
-1157040117 // 0xbb08f80b
|
-1157040117 // 0xbb08f80b
|
||||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||||
-1157040116 // 0xbb08f80c
|
-1157040116 // 0xbb08f80c
|
||||||
|
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||||
|
-1157040115 // 0xbb08f80d
|
||||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||||
-1157040115 // 0xbb08f80d
|
-1157040114 // 0xbb08f80e
|
||||||
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040114 // 0xbb08f80e
|
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xbb08f80f
|
||||||
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040113 // 0xbb08f80f
|
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xbb08f810
|
||||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||||
-1157040112 // 0xbb08f810
|
-1157040111 // 0xbb08f811
|
||||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||||
-1157040111 // 0xbb08f811
|
-1157040110 // 0xbb08f812
|
||||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040110 // 0xbb08f812
|
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040109 // 0xbb08f813
|
||||||
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||||
-1157040109 // 0xbb08f813
|
-1157040108 // 0xbb08f814
|
||||||
|
|
||||||
bool puffs_flate__status__is_error(puffs_flate__status s);
|
bool puffs_flate__status__is_error(puffs_flate__status s);
|
||||||
|
|
||||||
@@ -195,6 +197,7 @@ typedef struct {
|
|||||||
uint8_t f_history[32768];
|
uint8_t f_history[32768];
|
||||||
uint32_t f_history_index;
|
uint32_t f_history_index;
|
||||||
uint8_t f_code_lengths[320];
|
uint8_t f_code_lengths[320];
|
||||||
|
bool f_end_of_block;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t coro_susp_point;
|
uint32_t coro_susp_point;
|
||||||
@@ -665,7 +668,7 @@ const char* puffs_flate__status__strings0[9] = {
|
|||||||
"flate: short write",
|
"flate: short write",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* puffs_flate__status__strings1[20] = {
|
const char* puffs_flate__status__strings1[21] = {
|
||||||
"flate: bad Huffman code (over-subscribed)",
|
"flate: bad Huffman code (over-subscribed)",
|
||||||
"flate: bad Huffman code (under-subscribed)",
|
"flate: bad Huffman code (under-subscribed)",
|
||||||
"flate: bad Huffman code length count",
|
"flate: bad Huffman code length count",
|
||||||
@@ -679,6 +682,7 @@ const char* puffs_flate__status__strings1[20] = {
|
|||||||
"flate: checksum mismatch",
|
"flate: checksum mismatch",
|
||||||
"flate: inconsistent stored block length",
|
"flate: inconsistent stored block length",
|
||||||
"flate: internal error: inconsistent Huffman decoder state",
|
"flate: internal error: inconsistent Huffman decoder state",
|
||||||
|
"flate: internal error: inconsistent Huffman end_of_block",
|
||||||
"flate: internal error: inconsistent n_bits",
|
"flate: internal error: inconsistent n_bits",
|
||||||
"flate: missing end-of-block code",
|
"flate: missing end-of-block code",
|
||||||
"flate: no Huffman codes",
|
"flate: no Huffman codes",
|
||||||
@@ -698,7 +702,7 @@ const char* puffs_flate__status__string(puffs_flate__status s) {
|
|||||||
break;
|
break;
|
||||||
case puffs_flate__packageid:
|
case puffs_flate__packageid:
|
||||||
a = puffs_flate__status__strings1;
|
a = puffs_flate__status__strings1;
|
||||||
n = 20;
|
n = 21;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint32_t i = s & 0xff;
|
uint32_t i = s & 0xff;
|
||||||
@@ -1090,6 +1094,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
|||||||
status = PUFFS_FLATE__ERROR_BAD_FLATE_BLOCK;
|
status = PUFFS_FLATE__ERROR_BAD_FLATE_BLOCK;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
self->private_impl.f_end_of_block = false;
|
||||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||||
if (a_src.buf) {
|
if (a_src.buf) {
|
||||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||||
@@ -1109,6 +1114,11 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
|||||||
if (status) {
|
if (status) {
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
if (!self->private_impl.f_end_of_block) {
|
||||||
|
status =
|
||||||
|
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goto ok;
|
goto ok;
|
||||||
@@ -2012,6 +2022,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
|||||||
goto label_0_continue;
|
goto label_0_continue;
|
||||||
} else if ((v_table_entry >> 30) != 0) {
|
} else if ((v_table_entry >> 30) != 0) {
|
||||||
} else if ((v_table_entry >> 29) != 0) {
|
} else if ((v_table_entry >> 29) != 0) {
|
||||||
|
self->private_impl.f_end_of_block = true;
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
} else if ((v_table_entry >> 28) != 0) {
|
} else if ((v_table_entry >> 28) != 0) {
|
||||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||||
@@ -2052,6 +2063,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
|||||||
goto label_0_continue;
|
goto label_0_continue;
|
||||||
} else if ((v_table_entry >> 30) != 0) {
|
} else if ((v_table_entry >> 30) != 0) {
|
||||||
} else if ((v_table_entry >> 29) != 0) {
|
} else if ((v_table_entry >> 29) != 0) {
|
||||||
|
self->private_impl.f_end_of_block = true;
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
} else if ((v_table_entry >> 28) != 0) {
|
} else if ((v_table_entry >> 28) != 0) {
|
||||||
status =
|
status =
|
||||||
|
|||||||
+10
-7
@@ -156,17 +156,19 @@ typedef int32_t puffs_flate__status;
|
|||||||
-1157040117 // 0xbb08f80b
|
-1157040117 // 0xbb08f80b
|
||||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||||
-1157040116 // 0xbb08f80c
|
-1157040116 // 0xbb08f80c
|
||||||
|
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||||
|
-1157040115 // 0xbb08f80d
|
||||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||||
-1157040115 // 0xbb08f80d
|
-1157040114 // 0xbb08f80e
|
||||||
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040114 // 0xbb08f80e
|
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xbb08f80f
|
||||||
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040113 // 0xbb08f80f
|
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xbb08f810
|
||||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||||
-1157040112 // 0xbb08f810
|
-1157040111 // 0xbb08f811
|
||||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||||
-1157040111 // 0xbb08f811
|
-1157040110 // 0xbb08f812
|
||||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040110 // 0xbb08f812
|
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040109 // 0xbb08f813
|
||||||
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||||
-1157040109 // 0xbb08f813
|
-1157040108 // 0xbb08f814
|
||||||
|
|
||||||
bool puffs_flate__status__is_error(puffs_flate__status s);
|
bool puffs_flate__status__is_error(puffs_flate__status s);
|
||||||
|
|
||||||
@@ -195,6 +197,7 @@ typedef struct {
|
|||||||
uint8_t f_history[32768];
|
uint8_t f_history[32768];
|
||||||
uint32_t f_history_index;
|
uint32_t f_history_index;
|
||||||
uint8_t f_code_lengths[320];
|
uint8_t f_code_lengths[320];
|
||||||
|
bool f_end_of_block;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t coro_susp_point;
|
uint32_t coro_susp_point;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ pub error "bad literal/length code count"
|
|||||||
pub error "checksum mismatch"
|
pub error "checksum mismatch"
|
||||||
pub error "inconsistent stored block length"
|
pub error "inconsistent stored block length"
|
||||||
pub error "internal error: inconsistent Huffman decoder state"
|
pub error "internal error: inconsistent Huffman decoder state"
|
||||||
|
pub error "internal error: inconsistent Huffman end_of_block"
|
||||||
pub error "internal error: inconsistent n_bits"
|
pub error "internal error: inconsistent n_bits"
|
||||||
pub error "missing end-of-block code"
|
pub error "missing end-of-block code"
|
||||||
pub error "no Huffman codes"
|
pub error "no Huffman codes"
|
||||||
@@ -113,6 +114,11 @@ pub struct flate_decoder?(
|
|||||||
//
|
//
|
||||||
// code_lengths[in.n_codes0 + i] holds the number of bits in the i'th code.
|
// code_lengths[in.n_codes0 + i] holds the number of bits in the i'th code.
|
||||||
code_lengths[320] u8[..15],
|
code_lengths[320] u8[..15],
|
||||||
|
|
||||||
|
// end_of_block is whether decode_huffman_xxx saw an end-of-block code.
|
||||||
|
//
|
||||||
|
// TODO: can decode_huffman_xxx signal this in band instead of out of band?
|
||||||
|
end_of_block bool,
|
||||||
)
|
)
|
||||||
|
|
||||||
pub func flate_decoder.decode?(dst writer1, src reader1)() {
|
pub func flate_decoder.decode?(dst writer1, src reader1)() {
|
||||||
@@ -193,7 +199,11 @@ pri func flate_decoder.decode_blocks?(dst writer1, src reader1)() {
|
|||||||
return error "bad flate block"
|
return error "bad flate block"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.end_of_block = false
|
||||||
this.decode_huffman_slow?(dst:in.dst, src:in.src)
|
this.decode_huffman_slow?(dst:in.dst, src:in.src)
|
||||||
|
if not this.end_of_block {
|
||||||
|
return error "internal error: inconsistent Huffman end_of_block"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
|||||||
// No-op; code continues past the if-else chain.
|
// No-op; code continues past the if-else chain.
|
||||||
} else if (table_entry >> 29) != 0 {
|
} else if (table_entry >> 29) != 0 {
|
||||||
// End of block.
|
// End of block.
|
||||||
|
this.end_of_block = true
|
||||||
break
|
break
|
||||||
} else if (table_entry >> 28) != 0 {
|
} else if (table_entry >> 28) != 0 {
|
||||||
// Redirect.
|
// Redirect.
|
||||||
@@ -72,6 +73,7 @@ pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
|||||||
// No-op; code continues past the if-else chain.
|
// No-op; code continues past the if-else chain.
|
||||||
} else if (table_entry >> 29) != 0 {
|
} else if (table_entry >> 29) != 0 {
|
||||||
// End of block.
|
// End of block.
|
||||||
|
this.end_of_block = true
|
||||||
break
|
break
|
||||||
} else if (table_entry >> 28) != 0 {
|
} else if (table_entry >> 28) != 0 {
|
||||||
return error "internal error: inconsistent Huffman decoder state"
|
return error "internal error: inconsistent Huffman decoder state"
|
||||||
|
|||||||
Reference in new issue
Block a user