OLD | NEW |
1 /* Copyright 2013 Google Inc. All Rights Reserved. | 1 /* Copyright 2013 Google Inc. All Rights Reserved. |
2 | 2 |
3 Licensed under the Apache License, Version 2.0 (the "License"); | 3 Licensed under the Apache License, Version 2.0 (the "License"); |
4 you may not use this file except in compliance with the License. | 4 you may not use this file except in compliance with the License. |
5 You may obtain a copy of the License at | 5 You may obtain a copy of the License at |
6 | 6 |
7 http://www.apache.org/licenses/LICENSE-2.0 | 7 http://www.apache.org/licenses/LICENSE-2.0 |
8 | 8 |
9 Unless required by applicable law or agreed to in writing, software | 9 Unless required by applicable law or agreed to in writing, software |
10 distributed under the License is distributed on an "AS IS" BASIS, | 10 distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 "len: %d bytes left: %d\n", pos, s->distance_code, i, | 1665 "len: %d bytes left: %d\n", pos, s->distance_code, i, |
1666 s->meta_block_remaining_len)); | 1666 s->meta_block_remaining_len)); |
1667 return BROTLI_FAILURE(); | 1667 return BROTLI_FAILURE(); |
1668 } | 1668 } |
1669 } else { | 1669 } else { |
1670 const uint8_t *ringbuffer_end_minus_copy_length = | 1670 const uint8_t *ringbuffer_end_minus_copy_length = |
1671 s->ringbuffer_end - i; | 1671 s->ringbuffer_end - i; |
1672 uint8_t* copy_src = &s->ringbuffer[ | 1672 uint8_t* copy_src = &s->ringbuffer[ |
1673 (pos - s->distance_code) & s->ringbuffer_mask]; | 1673 (pos - s->distance_code) & s->ringbuffer_mask]; |
1674 uint8_t* copy_dst = &s->ringbuffer[pos]; | 1674 uint8_t* copy_dst = &s->ringbuffer[pos]; |
| 1675 /* Check for possible underflow and clamp the pointer to 0. */ |
| 1676 if (PREDICT_FALSE(s->ringbuffer_end < (const uint8_t*)0 + i)) { |
| 1677 ringbuffer_end_minus_copy_length = 0; |
| 1678 } |
1675 /* update the recent distances cache */ | 1679 /* update the recent distances cache */ |
1676 s->dist_rb[s->dist_rb_idx & 3] = s->distance_code; | 1680 s->dist_rb[s->dist_rb_idx & 3] = s->distance_code; |
1677 ++s->dist_rb_idx; | 1681 ++s->dist_rb_idx; |
1678 s->meta_block_remaining_len -= i; | 1682 s->meta_block_remaining_len -= i; |
1679 if (PREDICT_FALSE(s->meta_block_remaining_len < 0)) { | 1683 if (PREDICT_FALSE(s->meta_block_remaining_len < 0)) { |
1680 BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d " | 1684 BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d " |
1681 "len: %d bytes left: %d\n", pos, s->distance_code, i, | 1685 "len: %d bytes left: %d\n", pos, s->distance_code, i, |
1682 s->meta_block_remaining_len)); | 1686 s->meta_block_remaining_len)); |
1683 return BROTLI_FAILURE(); | 1687 return BROTLI_FAILURE(); |
1684 } | 1688 } |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 void BrotliSetCustomDictionary( | 2313 void BrotliSetCustomDictionary( |
2310 size_t size, const uint8_t* dict, BrotliState* s) { | 2314 size_t size, const uint8_t* dict, BrotliState* s) { |
2311 s->custom_dict = dict; | 2315 s->custom_dict = dict; |
2312 s->custom_dict_size = (int) size; | 2316 s->custom_dict_size = (int) size; |
2313 } | 2317 } |
2314 | 2318 |
2315 | 2319 |
2316 #if defined(__cplusplus) || defined(c_plusplus) | 2320 #if defined(__cplusplus) || defined(c_plusplus) |
2317 } /* extern "C" */ | 2321 } /* extern "C" */ |
2318 #endif | 2322 #endif |
OLD | NEW |