Commit e708424b authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/h264: Disallow pps_id changing between slices

Such changes are forbidden in H.264 and lead to race conditions

Fixes out of array read
Fixes: signal_sigsegv_f9796a_1613_cov_3114610371_FM1_BT_B.h264
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 1a96b27e
...@@ -3509,6 +3509,12 @@ static int decode_slice_header(H264Context *h, H264Context *h0) ...@@ -3509,6 +3509,12 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
pps_id); pps_id);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (h0->au_pps_id >= 0 && pps_id != h0->au_pps_id) {
av_log(h->avctx, AV_LOG_ERROR,
"PPS change from %d to %d forbidden\n",
h0->au_pps_id, pps_id);
return AVERROR_INVALIDDATA;
}
h->pps = *h0->pps_buffers[pps_id]; h->pps = *h0->pps_buffers[pps_id];
if (!h0->sps_buffers[h->pps.sps_id]) { if (!h0->sps_buffers[h->pps.sps_id]) {
...@@ -4104,6 +4110,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0) ...@@ -4104,6 +4110,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
if (h->ref_count[0]) h->er.last_pic = &h->ref_list[0][0]; if (h->ref_count[0]) h->er.last_pic = &h->ref_list[0][0];
if (h->ref_count[1]) h->er.next_pic = &h->ref_list[1][0]; if (h->ref_count[1]) h->er.next_pic = &h->ref_list[1][0];
h->er.ref_count = h->ref_count[0]; h->er.ref_count = h->ref_count[0];
h0->au_pps_id = pps_id;
if (h->avctx->debug & FF_DEBUG_PICT_INFO) { if (h->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(h->avctx, AV_LOG_DEBUG, av_log(h->avctx, AV_LOG_DEBUG,
...@@ -4872,6 +4879,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, ...@@ -4872,6 +4879,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
continue; continue;
again: again:
if ( !(avctx->active_thread_type & FF_THREAD_FRAME)
|| nals_needed >= nal_index)
h->au_pps_id = -1;
/* Ignore per frame NAL unit type during extradata /* Ignore per frame NAL unit type during extradata
* parsing. Decoding slices is not possible in codec init * parsing. Decoding slices is not possible in codec init
* with frame-mt */ * with frame-mt */
......
...@@ -390,6 +390,8 @@ typedef struct H264Context { ...@@ -390,6 +390,8 @@ typedef struct H264Context {
*/ */
PPS pps; // FIXME move to Picture perhaps? (->no) do we need that? PPS pps; // FIXME move to Picture perhaps? (->no) do we need that?
int au_pps_id; ///< pps_id of current access unit
uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16]; // FIXME should these be moved down? uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16]; // FIXME should these be moved down?
uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64]; uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
uint32_t(*dequant4_coeff[6])[16]; uint32_t(*dequant4_coeff[6])[16];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment