Check copy_from_history32's distance.

This commit is contained in:
Nigel Tao committed 2017-11-09 12:53:19 +11:00
1 parent 67fb7bf1dc
commit 30b54616a8
6 files changed
+52 -17

No files matched your search

+24 -9
View File
@@ -159,17 +159,19 @@ typedef int32_t puffs_flate__status;
-1157040116 // 0xbb08f80c
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
-1157040115 // 0xbb08f80d
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
-1157040114 // 0xbb08f80e
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
-1157040114 // 0xbb08f80e
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xbb08f80f
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xbb08f810
-1157040113 // 0xbb08f80f
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xbb08f810
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xbb08f811
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
-1157040111 // 0xbb08f811
-1157040110 // 0xbb08f812
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
-1157040110 // 0xbb08f812
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040109 // 0xbb08f813
-1157040109 // 0xbb08f813
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xbb08f814
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
-1157040108 // 0xbb08f814
-1157040107 // 0xbb08f815
bool puffs_flate__status__is_error(puffs_flate__status s);
@@ -672,7 +674,7 @@ const char* puffs_flate__status__strings0[10] = {
"flate: short write",
};
const char* puffs_flate__status__strings1[21] = {
const char* puffs_flate__status__strings1[22] = {
"flate: bad Huffman code (over-subscribed)",
"flate: bad Huffman code (under-subscribed)",
"flate: bad Huffman code length count",
@@ -687,6 +689,7 @@ const char* puffs_flate__status__strings1[21] = {
"flate: inconsistent stored block length",
"flate: internal error: inconsistent Huffman decoder state",
"flate: internal error: inconsistent Huffman end_of_block",
"flate: internal error: inconsistent distance",
"flate: internal error: inconsistent n_bits",
"flate: missing end-of-block code",
"flate: no Huffman codes",
@@ -706,7 +709,7 @@ const char* puffs_flate__status__string(puffs_flate__status s) {
break;
case puffs_flate__packageid:
a = puffs_flate__status__strings1;
n = 21;
n = 22;
break;
}
uint32_t i = s & 0xff;
@@ -2267,6 +2270,18 @@ label_0_continue:;
if (v_length == 0) {
goto label_0_continue;
}
if (((uint64_t)(v_distance)) >
((uint64_t)(
((puffs_base__slice_u8){
.ptr = a_dst.private_impl.mark,
.len = a_dst.private_impl.mark
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
: 0,
})
.len))) {
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE;
goto exit;
}
}
puffs_base__writer1__copy_from_history32(
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_distance,
+9 -7
View File
@@ -159,17 +159,19 @@ typedef int32_t puffs_flate__status;
-1157040116 // 0xbb08f80c
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
-1157040115 // 0xbb08f80d
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
-1157040114 // 0xbb08f80e
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
-1157040114 // 0xbb08f80e
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xbb08f80f
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xbb08f810
-1157040113 // 0xbb08f80f
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xbb08f810
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xbb08f811
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
-1157040111 // 0xbb08f811
-1157040110 // 0xbb08f812
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
-1157040110 // 0xbb08f812
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040109 // 0xbb08f813
-1157040109 // 0xbb08f813
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xbb08f814
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
-1157040108 // 0xbb08f814
-1157040107 // 0xbb08f815
bool puffs_flate__status__is_error(puffs_flate__status s);
+4
View File
@@ -98,6 +98,10 @@ const (
FlagsGlobalIdent = Flags(0x00000100)
)
// flagsThatMatterForEq is the bitwise or of all flags that matter for the
// Expr.Eq method.
const flagsThatMatterForEq = Flags(0x0000FFFF)
// These flags are set by the bounds checker to generate optimized code.
const (
// FlagsProvenNotToSuspend notes that a method such as read_u8 or
+1 -1
View File
@@ -35,7 +35,7 @@ func (n *Expr) Eq(o *Expr) bool {
return n.constValue.Cmp(o.constValue) == 0
}
if n.flags != o.flags || n.id0 != o.id0 || n.id1 != o.id1 {
if (n.flags&flagsThatMatterForEq) != (o.flags&flagsThatMatterForEq) || n.id0 != o.id0 || n.id1 != o.id1 {
return false
}
if !n.lhs.Expr().Eq(o.lhs.Expr()) {
+1
View File
@@ -28,6 +28,7 @@ pub error "checksum mismatch"
pub error "inconsistent stored block length"
pub error "internal error: inconsistent Huffman decoder state"
pub error "internal error: inconsistent Huffman end_of_block"
pub error "internal error: inconsistent distance"
pub error "internal error: inconsistent n_bits"
pub error "missing end-of-block code"
pub error "no Huffman codes"
+13
View File
@@ -268,6 +268,7 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// its presence minimizes the diff between decode_huffman_fast and
// decode_huffman_slow.
while true,
pre in.dst.available() >= 258,
inv in.dst.is_marked(),
{
// Copy from this.history.
@@ -298,8 +299,12 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// "etc", but its presence minimizes the diff between
// decode_huffman_fast and decode_huffman_slow.
while true,
inv in.dst.available() >= 258,
inv in.dst.is_marked(),
{
// TODO: copy_from_slice32 should probably update the
// "in.dst.available() >= 258" fact. It should certainly
// invalidate any fact that was "<=" instead of ">=".
n_copied = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen)
if hlen <= n_copied {
break
@@ -313,7 +318,15 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// No need to copy from in.dst.
continue:loop
}
if (distance as u64) > in.dst.since_mark().length() {
return error "internal error: inconsistent distance"
}
}
// Once again, redundant but explicit assertions.
assert in.dst.available() >= 258
assert in.dst.is_marked()
assert (distance as u64) <= in.dst.since_mark().length()
// Copy from in.dst.
in.dst.copy_from_history32(distance:distance, length:length)