[FFmpeg-devel] [PATCH 11/12] avcodec/sanm: change GetByteContext member to pointer

Manuel Lauss manuel.lauss at gmail.com
Fri Mar 14 22:49:52 EET 2025


Michael

On Fri, Mar 14, 2025 at 9:31 PM Michael Niedermayer
<michael at niedermayer.cc> wrote:
>
> Hi Manuel
>
> On Thu, Mar 13, 2025 at 12:15:04PM +0100, Manuel Lauss wrote:
> > In order do properly support the ANIM STOR/FTCH system, the FTCH
> > must replay a stored FOBJ and change the SANMContext's "GetByteContext"
> > member temporarily.
> >
> > Signed-off-by: Manuel Lauss <manuel.lauss at gmail.com>
> > ---
> >  libavcodec/sanm.c | 394 +++++++++++++++++++++++-----------------------
> >  1 file changed, 198 insertions(+), 196 deletions(-)
> >
> > diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
> > index a8a3e04156..207db4a8fb 100644
> > --- a/libavcodec/sanm.c
> > +++ b/libavcodec/sanm.c
>
> [...]
>
> > @@ -2114,10 +2114,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
> >                          int *got_frame_ptr, AVPacket *pkt)
> >  {
> >      SANMVideoContext *ctx = avctx->priv_data;
> > +    GetByteContext gb;
> >      int i, ret;
> >
> >      ctx->frame = frame;
> > -    bytestream2_init(&ctx->gb, pkt->data, pkt->size);
> > +    bytestream2_init(&gb, pkt->data, pkt->size);
> > +    ctx->gb = &gb;
>
> Having a context pointer point to the local stack is fragile
> Because the context and pointer have a longer lifetime than the stack
>
> So for a long portion of the time this pointer is totally invalid

I see your point, however the GetByteContext is only ever used during
this decode_frame() function, never outside of it.
But, I'll think of something else.

Danke dir!
     Manuel


More information about the ffmpeg-devel mailing list