[PATCH] Mp4: fixed setting wrong mdat atom size in very rarecases.

Valentin V. Bartenev vbart at nginx.com
Mon Nov 21 20:37:29 UTC 2016


On Monday 21 November 2016 23:10:25 胡聪 wrote:
> Hi,
> 
> On Mon, Nov 21, 2016 at 10:26 PM +0300, Maxim Dounin wrote:
> 
> >Ah, ok, I see the problem now.  Please clarify things in the 
> >commit log as well.
> >
> >It also make sense to use sizeof() explicitly, instead of 
> >introducing a magic number, e.g.:
> 
> Thanks!There is the new patch.
> 
> # HG changeset patch
> # User hucongcong <hucong.c at foxmail.com>
> # Date 1479740605 -28800
> #      Mon Nov 21 23:03:25 2016 +0800
> # Node ID 7a1a6f7b989d4c44523333293265d58663ac7ff4
> # Parent  2c7a2d75938a31044552b0a6cd6edaebdaf0bd69
> Mp4: fixed setting wrong mdat atom size in very rare cases.
> 
> Atom size is the sum of atom header size and atom data size. The
> specification says that the first 4 bytes are set to one when
> the atom size is greater than the maximum unsigned 32-bit value.
> Which means atom header size should be considered when the
> comparison takes place between atom data size and 0xffffffff.
> 
> diff -r 2c7a2d75938a -r 7a1a6f7b989d src/http/modules/ngx_http_mp4_module.c
> --- a/src/http/modules/ngx_http_mp4_module.c	Mon Nov 21 16:49:19 2016 +0300
> +++ b/src/http/modules/ngx_http_mp4_module.c	Mon Nov 21 23:03:25 2016 +0800
> @@ -1229,7 +1229,9 @@ ngx_http_mp4_update_mdat_atom(ngx_http_m
>  
>      atom_header = mp4->mdat_atom_header;
>  
> -    if ((uint64_t) atom_data_size > (uint64_t) 0xffffffff) {
> +    if ((uint64_t) atom_data_size + sizeof(ngx_mp4_atom_header_t)
> +            > (uint64_t) 0xffffffff)
> +    {
>          atom_size = 1;
>          atom_header_size = sizeof(ngx_mp4_atom_header64_t);
>          ngx_mp4_set_64value(atom_header + sizeof(ngx_mp4_atom_header_t),

Maxim wrote the expression the way that almost all compilers should optimize
it to comparison with one static constant.  I'm not sure about your case.

  wbr, Valentin V. Bartenev




More information about the nginx-devel mailing list