arthurscchan commented on code in PR #54912: URL: https://github.com/apache/arrow/pull/54912#discussion_r4678810494
########## cpp/src/arrow/csv/fuzz_header_internal.h: ########## @@ -0,0 +1,172 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <array> +#include <cstdint> +#include <cstring> +#include <span> +#include <string> + +#include "arrow/result.h" +#include "arrow/status.h" +#include "arrow/util/macros.h" + +namespace arrow::csv::internal { + +// The CSV fuzz target prepends a packed header to the fuzz payload to explore +// the CSV reader's option space (see +// https://github.com/google/oss-fuzz/issues/14437 for why fuzz target +// parameters have to be encoded inside the payload itself). +// +// The header starts with a magic number so that the fuzz target can detect +// whether an input was generated with this scheme. If the magic number +// matches, the header is parsed and the rest of the payload is read with the +// corresponding options. Otherwise (e.g. for legacy corpus entries), the +// whole input is read with the fuzzer's historical hardcoded options. + +constexpr auto kFuzzCsvHeaderSize = 16; + +inline constexpr std::array<char, 8> kFuzzCsvMagic = {'A', 'R', 'R', 'O', + 'W', 'C', 'S', 'V'}; + +// Candidate values for the options encoded in FuzzCsvHeader below. The +// corresponding option fields store an index in these arrays (modulo the +// array length, so that all header values lead to a well-defined option set). +inline constexpr std::array<char, 5> kFuzzCsvDelimiters = {',', '\t', ';', '|', ' '}; Review Comment: Changed from char to string_view. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
