Skip to content

Commit 23ce76f

Browse files
jzernGerrit Code Review
authored andcommitted
Merge "VP8BitReaderSetBuffer: move NULL check to call site" into main
2 parents f6b87e0 + bbf3cbb commit 23ce76f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/dec/idec_dec.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,14 @@ static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
141141
}
142142
{
143143
const uint8_t* const last_start = dec->parts[last_part].buf;
144-
VP8BitReaderSetBuffer(&dec->parts[last_part], last_start,
145-
mem->buf + mem->end - last_start);
144+
// 'last_start' will be NULL when 'idec->state' is < STATE_VP8_PARTS0
145+
// and through a portion of that state (when there isn't enough data to
146+
// parse the partitions). The bitreader is only used meaningfully when
147+
// there is enough data to begin parsing partition 0.
148+
if (last_start != NULL) {
149+
VP8BitReaderSetBuffer(&dec->parts[last_part], last_start,
150+
mem->buf + mem->end - last_start);
151+
}
146152
}
147153
if (NeedCompressedAlpha(idec)) {
148154
ALPHDecoder* const alph_dec = dec->alph_dec;

src/utils/bit_reader_utils.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
void VP8BitReaderSetBuffer(VP8BitReader* const br,
3232
const uint8_t* const start,
3333
size_t size) {
34-
if (start != NULL) {
35-
br->buf = start;
36-
br->buf_end = start + size;
37-
br->buf_max =
38-
(size >= sizeof(lbit_t)) ? start + size - sizeof(lbit_t) + 1 : start;
39-
}
34+
assert(start != NULL);
35+
br->buf = start;
36+
br->buf_end = start + size;
37+
br->buf_max =
38+
(size >= sizeof(lbit_t)) ? start + size - sizeof(lbit_t) + 1 : start;
4039
}
4140

4241
void VP8InitBitReader(VP8BitReader* const br,

0 commit comments

Comments
 (0)