diff mbox series

[FFmpeg-devel] avcodec/h264_slice: Remove dead sps check

Message ID 20240506012307.807589-1-michael@niedermayer.cc
State Accepted
Commit a68aa951b21b8b7db0a5200bcfebc0a077a5f094
Headers show
Series [FFmpeg-devel] avcodec/h264_slice: Remove dead sps check | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer May 6, 2024, 1:23 a.m. UTC
Fixes: CID1439574 Dereference after null check

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/h264_slice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Niedermayer May 13, 2024, 1:31 a.m. UTC | #1
On Mon, May 06, 2024 at 03:23:07AM +0200, Michael Niedermayer wrote:
> Fixes: CID1439574 Dereference after null check
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/h264_slice.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

[...]
Kieran Kunhya May 13, 2024, 5:15 a.m. UTC | #2
On Mon, 13 May 2024, 02:32 Michael Niedermayer, <michael@niedermayer.cc>
wrote:

> On Mon, May 06, 2024 at 03:23:07AM +0200, Michael Niedermayer wrote:
> > Fixes: CID1439574 Dereference after null check
> >
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/h264_slice.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
>
> will apply
>

I don't understand what this fixes

>
Rémi Denis-Courmont May 13, 2024, 6:04 a.m. UTC | #3
Le 6 mai 2024 04:23:07 GMT+03:00, Michael Niedermayer <michael@niedermayer.cc> a écrit :
>Fixes: CID1439574 Dereference after null check

If SPS is guaranteed to be non-NULL, there should probably be an assertion to document it, and it should be *before* that alleged dereference (which is not visible in the patch context).

>
>Sponsored-by: Sovereign Tech Fund
>Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>---
> libavcodec/h264_slice.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
>index 90d37f60848..ce2c4caca1b 100644
>--- a/libavcodec/h264_slice.c
>+++ b/libavcodec/h264_slice.c
>@@ -1396,7 +1396,7 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl,
> 
>     sps = h->ps.sps;
> 
>-    if (sps && sps->bitstream_restriction_flag &&
>+    if (sps->bitstream_restriction_flag &&
>         h->avctx->has_b_frames < sps->num_reorder_frames) {
>         h->avctx->has_b_frames = sps->num_reorder_frames;
>     }
Michael Niedermayer May 13, 2024, 8:09 p.m. UTC | #4
On Mon, May 13, 2024 at 09:04:34AM +0300, Rémi Denis-Courmont wrote:
> 
> 
> Le 6 mai 2024 04:23:07 GMT+03:00, Michael Niedermayer <michael@niedermayer.cc> a écrit :
> >Fixes: CID1439574 Dereference after null check
> 
> If SPS is guaranteed to be non-NULL, there should probably be an assertion to document it, and it should be *before* that alleged dereference (which is not visible in the patch context).

why ?

I mean why would sps require an assert*(sps) but the overwhelming majority
of pointers, we just dereference without assert before them ?

thx

[...]
Michael Niedermayer May 13, 2024, 10:49 p.m. UTC | #5
On Mon, May 13, 2024 at 06:15:16AM +0100, Kieran Kunhya wrote:
> On Mon, 13 May 2024, 02:32 Michael Niedermayer, <michael@niedermayer.cc>
> wrote:
> 
> > On Mon, May 06, 2024 at 03:23:07AM +0200, Michael Niedermayer wrote:
> > > Fixes: CID1439574 Dereference after null check
> > >
> > > Sponsored-by: Sovereign Tech Fund
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/h264_slice.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > will apply
> >
> 
> I don't understand what this fixes

it is not possible for sps to be NULL in this function (see line 1424)

thanks

[...]
James Almer May 13, 2024, 11:08 p.m. UTC | #6
On 5/13/2024 7:49 PM, Michael Niedermayer wrote:
> On Mon, May 13, 2024 at 06:15:16AM +0100, Kieran Kunhya wrote:
>> On Mon, 13 May 2024, 02:32 Michael Niedermayer, <michael@niedermayer.cc>
>> wrote:
>>
>>> On Mon, May 06, 2024 at 03:23:07AM +0200, Michael Niedermayer wrote:
>>>> Fixes: CID1439574 Dereference after null check
>>>>
>>>> Sponsored-by: Sovereign Tech Fund
>>>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>>>> ---
>>>>   libavcodec/h264_slice.c | 2 +-
>>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> will apply
>>>
>>
>> I don't understand what this fixes
> 
> it is not possible for sps to be NULL in this function (see line 1424)

It's also passed to ff_h264_init_poc(), which expects it to not be NULL.

In any case, when the coverity issues are about something that's not a 
bug but just noise like superfluous checks, might as well use something 
like "closes" rather than "fixes".
diff mbox series

Patch

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 90d37f60848..ce2c4caca1b 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1396,7 +1396,7 @@  static int h264_field_start(H264Context *h, const H264SliceContext *sl,
 
     sps = h->ps.sps;
 
-    if (sps && sps->bitstream_restriction_flag &&
+    if (sps->bitstream_restriction_flag &&
         h->avctx->has_b_frames < sps->num_reorder_frames) {
         h->avctx->has_b_frames = sps->num_reorder_frames;
     }