Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzer fixes #37

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions h264_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ int main(int argc, char *argv[])
{
FILE* infile;

if (argc < 2) { usage(); return EXIT_FAILURE; }

uint8_t* buf = (uint8_t*)malloc( BUFSIZE );

h264_stream_t* h = h264_new();

if (argc < 2) { usage(); return EXIT_FAILURE; }

int opt_verbose = 1;
int opt_probe = 0;

Expand Down Expand Up @@ -149,11 +149,10 @@ int main(int argc, char *argv[])
{
// print codec parameter, per RFC 6381.
int constraint_byte = h->sps->constraint_set0_flag << 7;
constraint_byte = h->sps->constraint_set1_flag << 6;
constraint_byte = h->sps->constraint_set2_flag << 5;
constraint_byte = h->sps->constraint_set3_flag << 4;
constraint_byte = h->sps->constraint_set4_flag << 3;
constraint_byte = h->sps->constraint_set4_flag << 3;
constraint_byte |= h->sps->constraint_set1_flag << 6;
constraint_byte |= h->sps->constraint_set2_flag << 5;
constraint_byte |= h->sps->constraint_set3_flag << 4;
constraint_byte |= h->sps->constraint_set4_flag << 3;

fprintf( h264_dbgfile, "codec: avc1.%02X%02X%02X\n",h->sps->profile_idc, constraint_byte, h->sps->level_idc );

Expand Down
45 changes: 21 additions & 24 deletions h264_nal.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,32 @@ int find_nal_unit(uint8_t* buf, int size, int* nal_start, int* nal_end)
*nal_end = 0;

i = 0;
while ( //( next_bits( 24 ) != 0x000001 && next_bits( 32 ) != 0x00000001 )
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) &&
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0 || buf[i+3] != 0x01)
)
{
i++; // skip leading zero
if (i+4 >= size) { return 0; } // did not find nal start
}

if (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) // ( next_bits( 24 ) != 0x000001 )
{
i++;
}
static const uint8_t bits24_0[] = { 0x0, 0x0, 0x0 };
static const uint8_t bits24_1[] = { 0x0, 0x0, 0x1 };
static const uint8_t bits32_1[] = { 0x0, 0x0, 0x0, 0x1 };

if (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) { /* error, should never happen */ return 0; }
i+= 3;
for (; i < size; ++i) { //( next_bits( 24 ) != 0x000001 && next_bits( 32 ) != 0x00000001 )
if (i + sizeof(bits24_1) <= size && 0==memcmp(buf+i, bits24_1, sizeof(bits24_1))) {
i += sizeof(bits24_1);
break;
}
if (i + sizeof(bits32_1) <= size && 0==memcmp(buf+i, bits32_1, sizeof(bits32_1))) {
i += sizeof(bits32_1);
break;
}
}
if (i >= size) { return -1; } // did not find nal start
*nal_start = i;

while ( //( next_bits( 24 ) != 0x000000 && next_bits( 24 ) != 0x000001 )
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0) &&
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01)
)
{
i++;
// FIXME the next line fails when reading a nal that ends exactly at the end of the data
if (i+3 >= size) { *nal_end = size; return -1; } // did not find nal end, stream ended first

for (++i; i < size; ++i) { //( next_bits( 24 ) != 0x000000 && next_bits( 24 ) != 0x000001 )
if (i + sizeof(bits24_0) <= size && 0==memcmp(buf+i, bits24_1, sizeof(bits24_0))) break;
if (i + sizeof(bits24_1) <= size && 0==memcmp(buf+i, bits24_1, sizeof(bits24_1))) break;
}


if (i >= size) { return -1; } // did not find nal end
*nal_end = i;

return (*nal_end - *nal_start);
}

Expand Down
Loading