fix for issue #275: don't compare to out-of-bound pointers

the original change triggered several internal API modifs.
This is to ensure that we're never computing pointer that can
possibly wrap around, or differences between pointers that can
overflow.

no observed speed difference

Change-Id: I9c94dda38d94fecc010305e4ad12f13b8fda5380
This commit is contained in:
Pascal Massimino
2015-11-20 09:12:48 +00:00
committed by James Zern
parent 21735e06f7
commit b37b0179c5
5 changed files with 40 additions and 21 deletions

View File

@ -20,17 +20,26 @@
//------------------------------------------------------------------------------
// VP8BitReader
void VP8BitReaderSetBuffer(VP8BitReader* const br,
const uint8_t* const start,
size_t size) {
br->buf_ = start;
br->buf_end_ = start + size;
br->buf_max_ =
(size >= sizeof(lbit_t)) ? start + size - sizeof(lbit_t) + 1
: start;
}
void VP8InitBitReader(VP8BitReader* const br,
const uint8_t* const start, const uint8_t* const end) {
const uint8_t* const start, size_t size) {
assert(br != NULL);
assert(start != NULL);
assert(start <= end);
assert(size < (1u << 31)); // limit ensured by format and upstream checks
br->range_ = 255 - 1;
br->buf_ = start;
br->buf_end_ = end;
br->value_ = 0;
br->bits_ = -8; // to load the very first 8bits
br->eof_ = 0;
VP8BitReaderSetBuffer(br, start, size);
VP8LoadNewBytes(br);
}
@ -38,6 +47,7 @@ void VP8RemapBitReader(VP8BitReader* const br, ptrdiff_t offset) {
if (br->buf_ != NULL) {
br->buf_ += offset;
br->buf_end_ += offset;
br->buf_max_ += offset;
}
}