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 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 "len: %d bytes left: %d\n", pos, s->distance_code, i, | 1693 "len: %d bytes left: %d\n", pos, s->distance_code, i, |
1694 s->meta_block_remaining_len)); | 1694 s->meta_block_remaining_len)); |
1695 return BROTLI_FAILURE(); | 1695 return BROTLI_FAILURE(); |
1696 } | 1696 } |
1697 } else { | 1697 } else { |
1698 const uint8_t *ringbuffer_end_minus_copy_length = | 1698 const uint8_t *ringbuffer_end_minus_copy_length = |
1699 s->ringbuffer_end - i; | 1699 s->ringbuffer_end - i; |
1700 uint8_t* copy_src = &s->ringbuffer[ | 1700 uint8_t* copy_src = &s->ringbuffer[ |
1701 (pos - s->distance_code) & s->ringbuffer_mask]; | 1701 (pos - s->distance_code) & s->ringbuffer_mask]; |
1702 uint8_t* copy_dst = &s->ringbuffer[pos]; | 1702 uint8_t* copy_dst = &s->ringbuffer[pos]; |
| 1703 /* Check for possible underflow and clamp the pointer to 0. */ |
| 1704 if (PREDICT_FALSE(s->ringbuffer_end < (const uint8_t*)0 + i)) { |
| 1705 ringbuffer_end_minus_copy_length = 0; |
| 1706 } |
1703 /* update the recent distances cache */ | 1707 /* update the recent distances cache */ |
1704 s->dist_rb[s->dist_rb_idx & 3] = s->distance_code; | 1708 s->dist_rb[s->dist_rb_idx & 3] = s->distance_code; |
1705 ++s->dist_rb_idx; | 1709 ++s->dist_rb_idx; |
1706 s->meta_block_remaining_len -= i; | 1710 s->meta_block_remaining_len -= i; |
1707 if (PREDICT_FALSE(s->meta_block_remaining_len < 0)) { | 1711 if (PREDICT_FALSE(s->meta_block_remaining_len < 0)) { |
1708 BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d " | 1712 BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d " |
1709 "len: %d bytes left: %d\n", pos, s->distance_code, i, | 1713 "len: %d bytes left: %d\n", pos, s->distance_code, i, |
1710 s->meta_block_remaining_len)); | 1714 s->meta_block_remaining_len)); |
1711 return BROTLI_FAILURE(); | 1715 return BROTLI_FAILURE(); |
1712 } | 1716 } |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 void BrotliSetCustomDictionary( | 2342 void BrotliSetCustomDictionary( |
2339 size_t size, const uint8_t* dict, BrotliState* s) { | 2343 size_t size, const uint8_t* dict, BrotliState* s) { |
2340 s->custom_dict = dict; | 2344 s->custom_dict = dict; |
2341 s->custom_dict_size = (int) size; | 2345 s->custom_dict_size = (int) size; |
2342 } | 2346 } |
2343 | 2347 |
2344 | 2348 |
2345 #if defined(__cplusplus) || defined(c_plusplus) | 2349 #if defined(__cplusplus) || defined(c_plusplus) |
2346 } /* extern "C" */ | 2350 } /* extern "C" */ |
2347 #endif | 2351 #endif |
OLD | NEW |