aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2017-02-08 21:14:01 +0100
committerGitHub <noreply@github.com>2017-02-08 21:14:01 +0100
commit9fa1ad5a91d69158e37ccff1c770f84c972a940a (patch)
tree2641db3e4d44ff382c17cf9e5c7452c9d874944c
parent0749d9ca8b8ec139db57a804fceee474643a896c (diff)
downloadbrotli-9fa1ad5a91d69158e37ccff1c770f84c972a940a.zip
brotli-9fa1ad5a91d69158e37ccff1c770f84c972a940a.tar.gz
brotli-9fa1ad5a91d69158e37ccff1c770f84c972a940a.tar.bz2
Fix "zero-distance-code", take 2 (#506)
-rw-r--r--dec/decode.c4
-rw-r--r--dec/state.h2
2 files changed, 4 insertions, 2 deletions
diff --git a/dec/decode.c b/dec/decode.c
index 1e903c8..2c2006b 100644
--- a/dec/decode.c
+++ b/dec/decode.c
@@ -1446,6 +1446,7 @@ static BROTLI_INLINE BROTLI_BOOL ReadDistanceInternal(
}
/* Convert the distance code to the actual distance by possibly */
/* looking up past distances from the s->ringbuffer. */
+ s->distance_context = 0;
if ((s->distance_code & ~0xf) == 0) {
TakeDistanceFromRingBuffer(s);
--s->block_length[2];
@@ -1706,6 +1707,7 @@ CommandPostDecodeLiterals:
s->state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS;
}
if (s->distance_code >= 0) {
+ s->distance_context = s->distance_code ? 0 : 1;
--s->dist_rb_idx;
s->distance_code = s->dist_rb[s->dist_rb_idx & 3];
goto postReadDistance; /* We already have the implicit distance */
@@ -1714,8 +1716,6 @@ CommandPostDecodeLiterals:
if (BROTLI_PREDICT_FALSE(s->block_length[2] == 0)) {
BROTLI_SAFE(DecodeDistanceBlockSwitch(s));
}
- /* Reuse distance_context variable. */
- s->distance_context = 0;
BROTLI_SAFE(ReadDistance(s, br));
postReadDistance:
BROTLI_LOG(("[ProcessCommandsInternal] pos = %d distance = %d\n",
diff --git a/dec/state.h b/dec/state.h
index de1056d..6a8f093 100644
--- a/dec/state.h
+++ b/dec/state.h
@@ -140,6 +140,8 @@ struct BrotliDecoderStateStruct {
/* This is true if the literal context map histogram type always matches the
block type. It is then not needed to keep the context (faster decoding). */
int trivial_literal_context;
+ /* Distance context is actual after command is decoded and before distance
+ is computed. After distance computation it is used as a temporary variable. */
int distance_context;
int meta_block_remaining_len;
uint32_t block_length_index;