enum AVCodecID codec_id)
{
int consumed, ret = 0;
+ const uint8_t *next_avc = is_nalff ? buf : buf + length;
pkt->nb_nals = 0;
while (length >= 4) {
int extract_length = 0;
int skip_trailing_zeros = 1;
- if (is_nalff) {
+ if (buf >= next_avc) {
int i;
for (i = 0; i < nal_length_size; i++)
extract_length = (extract_length << 8) | buf[i];
av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size.\n");
return AVERROR_INVALIDDATA;
}
+ next_avc = buf + extract_length;
} else {
/* search start code */
while (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
av_log(logctx, AV_LOG_ERROR, "No start code is found.\n");
return AVERROR_INVALIDDATA;
}
- }
+ } else if (buf >= (next_avc - 3))
+ break;
}
buf += 3;
length -= 3;
extract_length = length;
+
+ if (buf >= next_avc) {
+ /* skip to the start of the next NAL */
+ int offset = next_avc - buf;
+ buf += offset;
+ length -= offset;
+ continue;
+ }
}
if (pkt->nals_allocated < pkt->nb_nals + 1) {
if (consumed < 0)
return consumed;
+ if (is_nalff && (extract_length != consumed) && extract_length)
+ av_log(logctx, AV_LOG_DEBUG,
+ "NALFF: Consumed only %d bytes instead of %d\n",
+ consumed, extract_length);
+
pkt->nb_nals++;
/* see commit 3566042a0 */