From 3c2c129cadcbc26ab70ee770cd35c71b75ae751f Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Wed, 6 Nov 2024 12:44:11 -0500 Subject: [PATCH] Account for current pointer being outside of the buffer Differential Revision: D65118896 Pull Request resolved: https://github.com/pytorch/torchcodec/pull/316 --- src/torchcodec/decoders/_core/FFMPEGCommon.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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,