-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create fuzz tests for MemoryBasedReadBitBuffer
PiperOrigin-RevId: 705160522
- Loading branch information
1 parent
14d4e9e
commit d079e0c
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <sys/types.h> | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/types/span.h" | ||
#include "fuzztest/fuzztest.h" | ||
#include "iamf/common/read_bit_buffer.h" | ||
#include "iamf/obu/types.h" | ||
|
||
namespace iamf_tools { | ||
namespace { | ||
|
||
void ReadUnsignedLiteral64NoUndefinedBehavior(std::vector<uint8_t> data, | ||
int num_bits) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
uint64_t read_data; | ||
absl::Status status = rb->ReadUnsignedLiteral(num_bits, read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadUnsignedLiteral64NoUndefinedBehavior); | ||
|
||
void ReadUnsignedLiteral32NoUndefinedBehavior(std::vector<uint8_t> data, | ||
int num_bits) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
uint32_t read_data; | ||
absl::Status status = rb->ReadUnsignedLiteral(num_bits, read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadUnsignedLiteral32NoUndefinedBehavior); | ||
|
||
void ReadUnsignedLiteral16NoUndefinedBehavior(std::vector<uint8_t> data, | ||
int num_bits) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
uint16_t read_data; | ||
absl::Status status = rb->ReadUnsignedLiteral(num_bits, read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadUnsignedLiteral16NoUndefinedBehavior); | ||
|
||
void ReadUnsignedLiteral8NoUndefinedBehavior(std::vector<uint8_t> data, | ||
int num_bits) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
uint8_t read_data; | ||
absl::Status status = rb->ReadUnsignedLiteral(num_bits, read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadUnsignedLiteral8NoUndefinedBehavior); | ||
|
||
void ReadSigned16NoUndefinedBehavior(std::vector<uint8_t> data) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
int16_t read_data; | ||
absl::Status status = rb->ReadSigned16(read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadSigned16NoUndefinedBehavior); | ||
|
||
void ReadStringNoUndefinedBehavior(std::vector<uint8_t> data) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
std::string read_data; | ||
absl::Status status = rb->ReadString(read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadStringNoUndefinedBehavior); | ||
|
||
void ReadULeb128NoUndefinedBehavior(std::vector<uint8_t> data) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
DecodedUleb128 read_data; | ||
absl::Status status = rb->ReadULeb128(read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadULeb128NoUndefinedBehavior); | ||
|
||
void ReadIso14496_1ExpandedNoUndefinedBehavior(std::vector<uint8_t> data, | ||
uint32_t max_class_size) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
uint32_t read_data; | ||
absl::Status status = rb->ReadIso14496_1Expanded(max_class_size, read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadIso14496_1ExpandedNoUndefinedBehavior); | ||
|
||
void ReadUint8SpanNoUndefinedBehavior(std::vector<uint8_t> data) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
std::vector<uint8_t> read_data(data.size()); | ||
absl::Span<uint8_t> span(read_data); | ||
absl::Status status = rb->ReadUint8Span(span); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadUint8SpanNoUndefinedBehavior); | ||
|
||
void ReadBooleanNoUndefinedBehavior(std::vector<uint8_t> data) { | ||
std::unique_ptr<MemoryBasedReadBitBuffer> rb = | ||
MemoryBasedReadBitBuffer::CreateFromVector(256, data); | ||
bool read_data; | ||
absl::Status status = rb->ReadBoolean(read_data); | ||
} | ||
|
||
FUZZ_TEST(ReadBitBufferFuzzTest, ReadBooleanNoUndefinedBehavior); | ||
|
||
} // namespace | ||
} // namespace iamf_tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters