*/
void ff_h2645_packet_uninit(H2645Packet *pkt);
- "Invalid nal size %d\n", nalsize);
+static inline int get_nalsize(int nal_length_size, const uint8_t *buf,
+ int buf_size, int *buf_index, void *logctx)
+{
+ int i, nalsize = 0;
+
+ if (*buf_index >= buf_size - nal_length_size) {
+ // the end of the buffer is reached, refill it
+ return AVERROR(EAGAIN);
+ }
+
+ for (i = 0; i < nal_length_size; i++)
+ nalsize = ((unsigned)nalsize << 8) | buf[(*buf_index)++];
+ if (nalsize <= 0 || nalsize > buf_size - *buf_index) {
+ av_log(logctx, AV_LOG_ERROR,
++ "Invalid NAL unit size (%d > %d).\n", nalsize, buf_size - *buf_index);
+ return AVERROR_INVALIDDATA;
+ }
+ return nalsize;
+}
+
#endif /* AVCODEC_H2645_PARSE_H */