diff --git a/src/torchcodec/decoders/_core/FFMPEGCommon.cpp b/src/torchcodec/decoders/_core/FFMPEGCommon.cpp index 8d2c1c03..ab50414f 100644 --- a/src/torchcodec/decoders/_core/FFMPEGCommon.cpp +++ b/src/torchcodec/decoders/_core/FFMPEGCommon.cpp @@ -69,6 +69,12 @@ AVIOContext* AVIOBytesContext::getAVIO() { int AVIOBytesContext::read(void* opaque, uint8_t* buf, int buf_size) { struct AVIOBufferData* bufferData = static_cast(opaque); + TORCH_CHECK( + bufferData->current <= bufferData->size, + "Tried to read outside of the buffer: current=", + bufferData->current, + ", size=", + bufferData->size); buf_size = FFMIN(buf_size, bufferData->size - bufferData->current); TORCH_CHECK( buf_size >= 0,