Skip to content

Commit

Permalink
Improve extension generator buffer too small test.
Browse files Browse the repository at this point in the history
Test multiple buffer lengths and ensure we do not write past the
 end of the provided buffer.
  • Loading branch information
Timothy B. Terriberry committed Jul 30, 2024
1 parent 2ad8669 commit 5854a9f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test_opus_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,24 @@ void test_extensions_generate_fail(void)
unsigned char packet[100];

/* buffer too small */
result = opus_packet_extensions_generate(packet, 4, ext, 4, 1);
expect_true(result == OPUS_BUFFER_TOO_SMALL, "expected OPUS_BUFFER_TOO_SMALL");
{
opus_int32 len;
/* this failure can occur at lots of points, so iterate to check as many
as possible */
for (len=0;len<23;len++)
{
size_t i;
for (i=len;i<sizeof(packet);i++) packet[i] = 0xFE;
result = opus_packet_extensions_generate(packet, len, ext, 4, 1);
expect_true(result == OPUS_BUFFER_TOO_SMALL,
"expected OPUS_BUFFER_TOO_SMALL");
for (i=len;i<sizeof(packet);i++)
{
expect_true(packet[i] == 0xFE,
"expected 0xFE padding to be undisturbed");
}
}
}

/* invalid id */
{
Expand Down

0 comments on commit 5854a9f

Please sign in to comment.