[MPlayer-users] All XVID encoded videos with size 624x352 cause mplayer to segfault (current and previous svn snapshots)

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu Feb 7 21:30:19 CET 2013

On Thu, Feb 07, 2013 at 03:43:05PM +0200, Mike Gorchak wrote:
>     ptr = malloc(size + ALIGN);
>     if (!ptr)
>         return ptr;
>     diff              = ((~(long)ptr)&(ALIGN - 1)) + 1;
>     ptr               = (char *)ptr + diff;
>     ((char *)ptr)[-1] = diff;
> After malloc() there is needed a check for ptr which can be ALREADY
> aligned.

That case is handled, try calculating it through by hand.

> In this case we have not to execute this line: ((char
> *)ptr)[-1] = diff; which can cause a memory trashing. But better to
> allocate (size+2*ALIGN) bytes and then move ptr forward for ALIGN
> bytes to make sure that buffer has spare space for writting a 'diff'
> value.

In the case where it is already aligned, the pointer
will be increased by ALIGN.
In all other cases, it will be increased less.
Thus the assignment is never out of bounds and it is not
necessary to allocate more than ALIGN extra bytes.

More information about the MPlayer-users mailing list