Skip to content

Commit

Permalink
rtpenc: fix overflow checking in avc_mp4_find_startcode()
Browse files Browse the repository at this point in the history
The check `start + res < start' is broken since pointer overflow is
undefined behavior in C.  Many compilers such as gcc/clang optimize
away this check.

Use `res > end - start' instead.  Also change `res' to unsigned int
to avoid signed left-shift overflow.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information
xiw authored and michaelni committed Jan 23, 2013
1 parent 713dea5 commit 2f01456
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libavformat/rtpenc_h264.c
Expand Up @@ -31,14 +31,14 @@

static const uint8_t *avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end, int nal_length_size)
{
int res = 0;
unsigned int res = 0;

if (end - start < nal_length_size)
return NULL;
while (nal_length_size--)
res = (res << 8) | *start++;

if (start + res > end || res < 0 || start + res < start)
if (res > end - start)
return NULL;

return start + res;
Expand Down

0 comments on commit 2f01456

Please sign in to comment.