add (assumption) check

PiperOrigin-RevId: 625632989
This commit is contained in:
Evgenii Kliuchnikov 2024-04-17 04:09:20 -07:00 committed by Copybara-Service
parent c1c76e993f
commit 443af10a80
6 changed files with 18 additions and 0 deletions

View File

@ -435,6 +435,8 @@ static size_t UpdateNodes(
const CompoundDictionary* addon = &params->dictionary.compound;
size_t gap = addon->total_size;
BROTLI_DCHECK(cur_ix_masked + max_length <= ringbuffer_mask);
EvaluateNode(block_start + stream_offset, pos, max_backward_limit, gap,
starting_dist_cache, model, queue, nodes);

View File

@ -548,6 +548,8 @@ static BROTLI_INLINE void FindCompoundDictionaryMatch(
source = (const uint8_t*)BROTLI_UNALIGNED_LOAD_PTR((const uint8_t**)tail);
}
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
for (i = 0; i < 4; ++i) {
const size_t distance = (size_t)distance_cache[i];
size_t offset;
@ -657,6 +659,8 @@ static BROTLI_INLINE size_t FindAllCompoundDictionaryMatches(
source = (const uint8_t*)BROTLI_UNALIGNED_LOAD_PTR((const uint8_t**)tail);
}
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
while (item == 0) {
size_t offset;
size_t distance;

View File

@ -212,6 +212,9 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
const uint8_t tiny_hash = (uint8_t)(key);
out->len = 0;
out->len_code_delta = 0;
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
/* Try last distance first. */
for (i = 0; i < NUM_LAST_DISTANCES_TO_CHECK; ++i) {
const size_t backward = (size_t)distance_cache[i];

View File

@ -172,6 +172,9 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
size_t i;
out->len = 0;
out->len_code_delta = 0;
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
/* Try last distance first. */
for (i = 0; i < (size_t)self->num_last_distances_to_check_; ++i) {
const size_t backward = (size_t)distance_cache[i];

View File

@ -169,6 +169,9 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
score_t best_score = out->score;
size_t best_len = out->len;
size_t i;
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
out->len = 0;
out->len_code_delta = 0;
/* Try last distance first. */

View File

@ -164,6 +164,9 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
size_t best_len = best_len_in;
size_t cached_backward = (size_t)distance_cache[0];
size_t prev_ix = cur_ix - cached_backward;
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
out->len_code_delta = 0;
if (prev_ix < cur_ix) {
prev_ix &= (uint32_t)ring_buffer_mask;