Log in

View Full Version : Bug in array_non_zero_int


Mutant_Fruit
14th March 2008, 02:23
static inline int array_non_zero_int( void *v, int i_count )
{
int i;
- uint32_t *x = v;
- i_count /= sizeof(uint32_t);
+ uint64_t *x = v;
+ i_count /= sizeof(uint64_t);
for( i = 0; i < i_count; i++ )
if( x[i] ) return 1;
return 0;


If i_count represents the number of bytes in the array, then there's an issue with that change. Suppose there are 12 bytes in it (3x uint32_t), by performing i_count /= sizeof(uint64_t), you will only actually check the first 8 bytes to see if they are non-zero. The remaining 4 bytes won't be checked.

A check should be performed to ensure that i_count % sizeof(uint64_t) == 0.

Dark Shikari
14th March 2008, 02:31
But its only called on arrays of size 16w and 64w, or 32 bytes and 128 bytes, respectively.

fibbingbear
14th March 2008, 04:29
Why not represent that constraint with an assert?

Seriously, I'm curious, as a programmer. :)

Dark Shikari
14th March 2008, 04:30
Why not represent that constraint with an assert?

Seriously, I'm curious, as a programmer. :)Dunno, laziness.

There's no reason in x264 that the function would ever be used for any other size array though, I'd think.

Mutant_Fruit
14th March 2008, 13:20
But its only called on arrays of size 16w and 64w, or 32 bytes and 128 bytes, respectively.
Then there's no issue ;) I just noticed that behaviour had changed which could result in a non-obvious bug so i thought i'd point it out now *just in case* it was actually an issue. If there's no assert, another dev could use that function on an array which is not a multiple of sizeof (uint64_t) in length.