Skip to content

Commit

Permalink
add (assumption) check
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 625617382
  • Loading branch information
eustas authored and copybara-github committed Apr 17, 2024
1 parent c1c76e9 commit f675143
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions c/enc/backward_references_hq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions c/enc/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions c/enc/hash_forgetful_chain_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 3 additions & 0 deletions c/enc/hash_longest_match64_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 3 additions & 0 deletions c/enc/hash_longest_match_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
3 changes: 3 additions & 0 deletions c/enc/hash_longest_match_quickly_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f675143

Please sign in to comment.