Fix out-of-bounds read in encoderstate

When calling encoder_state_encode_leaf with POC 0, index -1 of the GOP
array would be accessed. Fixed by skipping the code for I-frames.
This commit is contained in:
Arttu Ylä-Outinen 2017-07-19 11:59:27 +03:00
parent 8c4a3473a8
commit 07b5fb9caf

View file

@ -764,9 +764,13 @@ static void encoder_state_encode_leaf(encoder_state_t * const state)
// Select which frame dependancies should be set to.
const encoder_state_t * ref_state = NULL;
if (cfg->gop_lowdelay &&
cfg->gop_len > 0 &&
state->previous_encoder_state != state)
if (state->frame->slicetype == KVZ_SLICE_I) {
// I-frames have no references.
ref_state = NULL;
} else if (cfg->gop_lowdelay &&
cfg->gop_len > 0 &&
state->previous_encoder_state != state)
{
// For LP-gop, depend on the state of the first reference.
int ref_neg = cfg->gop[(state->frame->poc - 1) % cfg->gop_len].ref_neg[0];