diff mbox

[FFmpeg-devel,2/6] lavc/avpacket: check NULL before using the pointer

Message ID 1557504354-27086-2-git-send-email-mypopydev@gmail.com
State Accepted
Commit 00555f4b8b40e52b379b24464a96f94d90432fee
Headers show

Commit Message

Jun Zhao May 10, 2019, 4:05 p.m. UTC
From: Jun Zhao <barryjzhao@tencent.com>

Need to check NULL before using the pointer

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavcodec/avpacket.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Carl Eugen Hoyos May 10, 2019, 8 p.m. UTC | #1
Am Fr., 10. Mai 2019 um 18:13 Uhr schrieb Jun Zhao <mypopydev@gmail.com>:
>
> From: Jun Zhao <barryjzhao@tencent.com>
>
> Need to check NULL before using the pointer
>
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavcodec/avpacket.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 8f0603d..2b20067 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -522,11 +522,12 @@ fail:
>
>  int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
>  {
> -    const uint8_t *end = data + size;
> +    const uint8_t *end;
>      int ret = 0;
>
>      if (!dict || !data || !size)
>          return ret;
> +    end = data + size;

Could somebody explain to me why this is necessary?

Thank you, Carl Eugen
Michael Niedermayer May 10, 2019, 11:25 p.m. UTC | #2
On Fri, May 10, 2019 at 10:00:54PM +0200, Carl Eugen Hoyos wrote:
> Am Fr., 10. Mai 2019 um 18:13 Uhr schrieb Jun Zhao <mypopydev@gmail.com>:
> >
> > From: Jun Zhao <barryjzhao@tencent.com>
> >
> > Need to check NULL before using the pointer
> >
> > Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> > ---
> >  libavcodec/avpacket.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index 8f0603d..2b20067 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -522,11 +522,12 @@ fail:
> >
> >  int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
> >  {
> > -    const uint8_t *end = data + size;
> > +    const uint8_t *end;
> >      int ret = 0;
> >
> >      if (!dict || !data || !size)
> >          return ret;
> > +    end = data + size;
> 
> Could somebody explain to me why this is necessary?

if data is NULL adding a non zero value to it would be undefined behavior
i think

thx

[...]
mypopy@gmail.com May 13, 2019, 1:34 a.m. UTC | #3
On Sat, May 11, 2019 at 8:23 AM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Fri, May 10, 2019 at 10:00:54PM +0200, Carl Eugen Hoyos wrote:
> > Am Fr., 10. Mai 2019 um 18:13 Uhr schrieb Jun Zhao <mypopydev@gmail.com>:
> > >
> > > From: Jun Zhao <barryjzhao@tencent.com>
> > >
> > > Need to check NULL before using the pointer
> > >
> > > Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> > > ---
> > >  libavcodec/avpacket.c |    3 ++-
> > >  1 files changed, 2 insertions(+), 1 deletions(-)
> > >
> > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > index 8f0603d..2b20067 100644
> > > --- a/libavcodec/avpacket.c
> > > +++ b/libavcodec/avpacket.c
> > > @@ -522,11 +522,12 @@ fail:
> > >
> > >  int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
> > >  {
> > > -    const uint8_t *end = data + size;
> > > +    const uint8_t *end;
> > >      int ret = 0;
> > >
> > >      if (!dict || !data || !size)
> > >          return ret;
> > > +    end = data + size;
> >
> > Could somebody explain to me why this is necessary?
>
> if data is NULL adding a non zero value to it would be undefined behavior
> i think
>
Yes, it's a undefined behavior to adding a non zero value if the
pointer is NULL,
this is the reason to change the code.

Applied, Thanks
diff mbox

Patch

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 8f0603d..2b20067 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -522,11 +522,12 @@  fail:
 
 int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
 {
-    const uint8_t *end = data + size;
+    const uint8_t *end;
     int ret = 0;
 
     if (!dict || !data || !size)
         return ret;
+    end = data + size;
     if (size && end[-1])
         return AVERROR_INVALIDDATA;
     while (data < end) {