mirror of
https://github.com/google/brotli.git
synced 2024-11-21 19:20:09 +00:00
Don't check cur_ix_masked
against ring_buffer_mask
.
`cur_ix_masked` isn't changing from iteration to iteration, and `max_length` ensures we never find a match long enough to walk off the ring buffer. PiperOrigin-RevId: 624701948
This commit is contained in:
parent
709c4672d4
commit
c1c76e993f
@ -557,7 +557,6 @@ static BROTLI_INLINE void FindCompoundDictionaryMatch(
|
|||||||
offset = distance_offset - distance;
|
offset = distance_offset - distance;
|
||||||
limit = source_size - offset;
|
limit = source_size - offset;
|
||||||
limit = limit > max_length ? max_length : limit;
|
limit = limit > max_length ? max_length : limit;
|
||||||
BROTLI_DCHECK(cur_ix_masked + limit <= ring_buffer_mask);
|
|
||||||
len = FindMatchLengthWithLimit(&source[offset], &data[cur_ix_masked],
|
len = FindMatchLengthWithLimit(&source[offset], &data[cur_ix_masked],
|
||||||
limit);
|
limit);
|
||||||
if (len >= 2) {
|
if (len >= 2) {
|
||||||
@ -592,7 +591,7 @@ static BROTLI_INLINE void FindCompoundDictionaryMatch(
|
|||||||
limit = source_size - offset;
|
limit = source_size - offset;
|
||||||
limit = (limit > max_length) ? max_length : limit;
|
limit = (limit > max_length) ? max_length : limit;
|
||||||
if (distance > max_distance) continue;
|
if (distance > max_distance) continue;
|
||||||
if (best_len >= limit ||
|
if (cur_ix_masked + best_len > ring_buffer_mask || best_len >= limit ||
|
||||||
/* compare 4 bytes ending at best_len + 1 */
|
/* compare 4 bytes ending at best_len + 1 */
|
||||||
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
||||||
BrotliUnalignedRead32(&source[offset + best_len - 3])) {
|
BrotliUnalignedRead32(&source[offset + best_len - 3])) {
|
||||||
@ -671,7 +670,8 @@ static BROTLI_INLINE size_t FindAllCompoundDictionaryMatches(
|
|||||||
limit = source_size - offset;
|
limit = source_size - offset;
|
||||||
limit = (limit > max_length) ? max_length : limit;
|
limit = (limit > max_length) ? max_length : limit;
|
||||||
if (distance > max_distance) continue;
|
if (distance > max_distance) continue;
|
||||||
if (best_len >= limit ||
|
if (cur_ix_masked + best_len > ring_buffer_mask ||
|
||||||
|
best_len >= limit ||
|
||||||
data[cur_ix_masked + best_len] != source[offset + best_len]) {
|
data[cur_ix_masked + best_len] != source[offset + best_len]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,6 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
score_t best_score = out->score;
|
score_t best_score = out->score;
|
||||||
size_t best_len = out->len;
|
size_t best_len = out->len;
|
||||||
size_t i;
|
size_t i;
|
||||||
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
|
|
||||||
const size_t key = FN(HashBytes)(&data[cur_ix_masked]);
|
const size_t key = FN(HashBytes)(&data[cur_ix_masked]);
|
||||||
const uint8_t tiny_hash = (uint8_t)(key);
|
const uint8_t tiny_hash = (uint8_t)(key);
|
||||||
out->len = 0;
|
out->len = 0;
|
||||||
@ -261,7 +260,8 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
prev_ix = (cur_ix - backward) & ring_buffer_mask;
|
prev_ix = (cur_ix - backward) & ring_buffer_mask;
|
||||||
slot = banks[bank].slots[last].next;
|
slot = banks[bank].slots[last].next;
|
||||||
delta = banks[bank].slots[last].delta;
|
delta = banks[bank].slots[last].delta;
|
||||||
if (prev_ix + best_len > ring_buffer_mask ||
|
if (cur_ix_masked + best_len > ring_buffer_mask ||
|
||||||
|
prev_ix + best_len > ring_buffer_mask ||
|
||||||
/* compare 4 bytes ending at best_len + 1 */
|
/* compare 4 bytes ending at best_len + 1 */
|
||||||
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
||||||
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
|
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
|
||||||
|
@ -170,7 +170,6 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
score_t best_score = out->score;
|
score_t best_score = out->score;
|
||||||
size_t best_len = out->len;
|
size_t best_len = out->len;
|
||||||
size_t i;
|
size_t i;
|
||||||
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
|
|
||||||
out->len = 0;
|
out->len = 0;
|
||||||
out->len_code_delta = 0;
|
out->len_code_delta = 0;
|
||||||
/* Try last distance first. */
|
/* Try last distance first. */
|
||||||
@ -185,7 +184,8 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
}
|
}
|
||||||
prev_ix &= ring_buffer_mask;
|
prev_ix &= ring_buffer_mask;
|
||||||
|
|
||||||
if (prev_ix + best_len > ring_buffer_mask ||
|
if (cur_ix_masked + best_len > ring_buffer_mask ||
|
||||||
|
prev_ix + best_len > ring_buffer_mask ||
|
||||||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
|
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -233,7 +233,8 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev_ix &= ring_buffer_mask;
|
prev_ix &= ring_buffer_mask;
|
||||||
if (prev_ix + best_len > ring_buffer_mask ||
|
if (cur_ix_masked + best_len > ring_buffer_mask ||
|
||||||
|
prev_ix + best_len > ring_buffer_mask ||
|
||||||
/* compare 4 bytes ending at best_len + 1 */
|
/* compare 4 bytes ending at best_len + 1 */
|
||||||
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
||||||
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
|
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
|
||||||
|
@ -169,7 +169,6 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
score_t best_score = out->score;
|
score_t best_score = out->score;
|
||||||
size_t best_len = out->len;
|
size_t best_len = out->len;
|
||||||
size_t i;
|
size_t i;
|
||||||
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
|
|
||||||
out->len = 0;
|
out->len = 0;
|
||||||
out->len_code_delta = 0;
|
out->len_code_delta = 0;
|
||||||
/* Try last distance first. */
|
/* Try last distance first. */
|
||||||
@ -184,7 +183,8 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
}
|
}
|
||||||
prev_ix &= ring_buffer_mask;
|
prev_ix &= ring_buffer_mask;
|
||||||
|
|
||||||
if (prev_ix + best_len > ring_buffer_mask ||
|
if (cur_ix_masked + best_len > ring_buffer_mask ||
|
||||||
|
prev_ix + best_len > ring_buffer_mask ||
|
||||||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
|
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -228,7 +228,8 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev_ix &= ring_buffer_mask;
|
prev_ix &= ring_buffer_mask;
|
||||||
if (prev_ix + best_len > ring_buffer_mask ||
|
if (cur_ix_masked + best_len > ring_buffer_mask ||
|
||||||
|
prev_ix + best_len > ring_buffer_mask ||
|
||||||
/* compare 4 bytes ending at best_len + 1 */
|
/* compare 4 bytes ending at best_len + 1 */
|
||||||
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
|
||||||
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
|
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user