MCPcopy Create free account
hub / github.com/apache/arrow / Parse

Method Parse

cpp/src/parquet/arrow/fuzz_encoding_internal.cc:116–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116::arrow::Result<FuzzEncodingHeader::ParseResult> FuzzEncodingHeader::Parse(
117 std::span<const uint8_t> payload) {
118 auto invalid_payload = []() {
119 return Status::Invalid("Invalid fuzz encoding payload");
120 };
121
122 if (payload.size() < kPackedEncodingHeaderSize) {
123 return invalid_payload();
124 }
125 PackedEncodingHeader packed;
126 std::memcpy(&packed, payload.data(), kPackedEncodingHeaderSize);
127 // We are strict in what we accept because we don't want the fuzzer to go
128 // explore pointless variations.
129 if (packed.reserved !=
130 PackedEncodingHeader::Reserved{}) { // reserved bytes should be zero
131 return invalid_payload();
132 }
133 const auto& ph = packed.header;
134 if (ph.source_encoding_id >= static_cast<uint8_t>(Encoding::UNDEFINED) ||
135 ph.roundtrip_encoding_id >= static_cast<uint8_t>(Encoding::UNDEFINED) ||
136 ph.type_id >= static_cast<uint8_t>(Type::UNDEFINED)) {
137 return invalid_payload();
138 }
139 FuzzEncodingHeader header(static_cast<Encoding::type>(ph.source_encoding_id),
140 static_cast<Encoding::type>(ph.roundtrip_encoding_id),
141 static_cast<Type::type>(ph.type_id), ph.type_length,
142 ph.num_values);
143 if ((header.type == Type::FIXED_LEN_BYTE_ARRAY) ? (header.type_length <= 0)
144 : (header.type_length != -1)) {
145 return invalid_payload();
146 }
147 if (header.num_values < 0) {
148 return invalid_payload();
149 }
150 return ParseResult{header, payload.subspan(kPackedEncodingHeaderSize)};
151}
152
153namespace {
154

Callers

nothing calls this directly

Calls 3

InvalidFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected