Skip to content
Snippets Groups Projects
Commit 8851a72b authored by Alexandre Janniaux's avatar Alexandre Janniaux Committed by Steve Lhomme
Browse files

mpeg4video: guarantee aspect_ratio_idc is 4bits

There was no guarantee from bs_read() that the result could not return
0xff itself, which would be like the case 0xf but with ar.sar_width and
ar.sar_height uninitialized. This tells the compiler that everything is
fine.

The alternative solution is to patch the vlc_bits.h file adding a macro
for bs_read() doing:

    #define bs_read(s, count) (bs_read(s, count) &
                               (uint32_t)(((uint64_t)1 << (uint64_t)(count+1)) - 1))

Unfortunately, using count from the macro makes is expansion-unsafe and
using this and-operation inside bs_read() is not enough for the compiler
to ensure that there is no more bits that count, despite the function
being inline.

Fixes the following warnings:

    In file included from ../../modules/packetizer/mpeg4video.c:43:
    In function ‘h26x_get_aspect_ratio’,
        inlined from ‘ParseVOL.isra’ at ../../modules/packetizer/mpeg4video.c:403:9:
    ../../modules/packetizer/h26x_nal_common.h:117:18: warning: ‘ar.sar_width’ may be used uninitialized [-Wmaybe-uninitialized]
      117 |         *num = ar->sar_width;
          |                ~~^~~~~~~~~~~
    ../../modules/packetizer/mpeg4video.c: In function ‘ParseVOL.isra’:
    ../../modules/packetizer/mpeg4video.c:364:25: note: ‘ar.sar_width’ was declared here
      364 |     h26x_aspect_ratio_t ar;
          |                         ^~
    In function ‘h26x_get_aspect_ratio’,
        inlined from ‘ParseVOL.isra’ at ../../modules/packetizer/mpeg4video.c:403:9:
    ../../modules/packetizer/h26x_nal_common.h:118:18: warning: ‘ar.sar_height’ may be used uninitialized [-Wmaybe-uninitialized]
      118 |         *den = ar->sar_height;
          |                ~~^~~~~~~~~~~~
    ../../modules/packetizer/mpeg4video.c: In function ‘ParseVOL.isra’:
    ../../modules/packetizer/mpeg4video.c:364:25: note: ‘ar.sar_height’ was declared here
      364 |     h26x_aspect_ratio_t ar;
          |                         ^~
parent 8f513763
No related branches found
No related tags found
1 merge request!5831mpeg4video: guarantee aspect_ratio_idc is 4bits
Pipeline #499350 passed with stage
in 19 minutes and 16 seconds
......@@ -390,7 +390,7 @@ static int ParseVOL( decoder_t *p_dec, es_format_t *fmt,
{
i_vo_ver_id = 1;
}
ar.aspect_ratio_idc = bs_read( &s, 4 );
ar.aspect_ratio_idc = bs_read( &s, 4 ) & 0xf;
if( ar.aspect_ratio_idc == 0xf )
{
ar.aspect_ratio_idc = 0xff; // was only coded on 4 bits in MPEG4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment