[Libav-user] Array bounds error while reading from ffmpeg data array using Purify

Navin nkipe at tatapowersed.com
Wed Dec 26 06:52:14 CET 2012


Okay, so basically this is how the code goes. It's from the ffmpeg 
tutorials itself. Could the code be wrong because I used sws_getContext?
g_metadata is a struct I constructed, for holding some properties of the 
video.

AVFormatContext*   g_pFormatCtx = NULL;
AVCodecContext*    g_g_pCodecCtx = NULL;
int                g_videoStream;
int                g_numBytes;
AVCodec*           g_pCodec = NULL;
AVFrame*           g_pFrame = NULL;
AVFrame*           g_pFrameRGB = NULL;
AVDictionary*      g_optionsDict = NULL;
struct SwsContext* g_sws_ctx = NULL;


         av_register_all();
         if (avformat_open_input(&g_pFormatCtx, 
g_metadata->videoLocation.c_str(), NULL, NULL) != 0)    { 
freeVideoData(); return false; }
         if (avformat_find_stream_info(g_pFormatCtx, NULL) < 0)  { 
freeVideoData(); return false; }

         g_videoStream = -1;
         for(unsigned int i = 0; i < g_pFormatCtx->nb_streams; i++)
         {
             if (g_pFormatCtx->streams[i]->codec->codec_type == 
AVMEDIA_TYPE_VIDEO)
             {
                 g_videoStream=i;
                 break; //breaks out of for loop
             }
         }//for
         if (g_videoStream == -1) return false;

         g_memoryBuffer->size = unsigned int(g_metadata->WIDTH * 
g_metadata->HEIGHT * sizeof(RGBPixel));//encapsulating the calculation 
of memory size

         g_pCodec = avcodec_find_decoder(g_g_pCodecCtx->codec_id);
         if (NULL == g_pCodec) return false;
         if (avcodec_open2(g_g_pCodecCtx, g_pCodec, &g_optionsDict) < 0) 
return false;
         g_pFrame = avcodec_alloc_frame();
         if (NULL == g_pFrame) return false;

         g_pFrameRGB = avcodec_alloc_frame();
         if (NULL == g_pFrameRGB)  return false;

         uint8_t* pbuffer = NULL;
         g_numBytes = avpicture_get_size(PIX_FMT_RGB24, 
g_metadata->WIDTH, g_metadata->HEIGHT);
         pbuffer = (uint8_t *) av_malloc(g_numBytes * 
sizeof(uint8_t));//TODO: exception handling may be required for allocs

         g_sws_ctx = sws_getContext(g_metadata->WIDTH, 
g_metadata->HEIGHT, g_g_pCodecCtx->pix_fmt, \
                                         g_metadata->WIDTH, 
g_metadata->HEIGHT, PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL );

         avpicture_fill((AVPicture *) g_pFrameRGB, pbuffer, 
PIX_FMT_RGB24, g_metadata->WIDTH, g_metadata->HEIGHT);
         av_free(pbuffer);


Navin

On 12/24/2012 4:05 PM, Alex Cohn wrote:
> On Mon, Dec 24, 2012 at 7:26 AM, Navin<nkipe at tatapowersed.com>  wrote:
>> Actually I'm giving avipicture_fill a value. I didn't show that bit of the code.
>>
>> g_pFrameRGB = avcodec_alloc_frame_proc();
> Yes, this should be correct.
>
>> But it's strange that purify is showing an error while reading from data[0][0].
> Actually, after your call to avpicture_fill_proc(), data[0] is
> pointing to pbuffer[0]. You didn't disclose how you initialized
> pbuffer, so it's impossible to tell why Purify is unhappy with this
> address.
>
> By the way, I don't understand the rationale of allocating another
> chunk of memory, pAreaInMemory. Whatever you do with these bytes, why
> don't you use pbuffer directly?
>
> BR,
> Alex
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>


More information about the Libav-user mailing list