arthurscchan commented on code in PR #54912:
URL: https://github.com/apache/arrow/pull/54912#discussion_r4629859893


##########
cpp/src/arrow/csv/fuzz.cc:
##########
@@ -29,92 +29,160 @@
 #include "arrow/util/fuzz_internal.h"
 #include "arrow/util/macros.h"
 #include "arrow/util/thread_pool.h"
+#include "arrow/util/value_parsing.h"
 
 namespace arrow::csv {
 
 using ::arrow::internal::GetCpuThreadPool;
 using ::arrow::io::InputStream;
 
-Status FuzzCsvReader(const uint8_t* data, int64_t size) {
-  // Since the Fuzz-allocated data is not owned, any task that outlives the 
TableReader
-  // may try to read memory that has been deallocated. Hence we wait for all 
pending
-  // tasks to end before leaving.
-  struct TaskGuard {
-    ~TaskGuard() { GetCpuThreadPool()->WaitForIdle(); }
-  };
+namespace {
 
-  auto io_context = arrow::io::default_io_context();
+// Packed header prefixing the fuzz payload, used 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).
+//
+// All option values are total functions of the header bytes, so every possible
+// input leads to a well-defined option set. Inputs shorter than the header are
+// read with the original hardcoded options, preserving the fuzzer's historical
+// behavior on legacy corpus entries.
+constexpr int64_t kFuzzHeaderSize = 8;
+
+struct FuzzCsvOptions {
+  ReadOptions read;
+  ParseOptions parse;
+  ConvertOptions convert;
+};
+
+FuzzCsvOptions MakeFuzzCsvOptions(const uint8_t* header) {
+  FuzzCsvOptions opts;
+
+  // --- ParseOptions ---
+  const char kDelimiters[] = {',', '\t', ';', '|', ' '};
+  opts.parse.delimiter = kDelimiters[header[0] % 5];
+  opts.parse.quoting = !(header[1] & 1);

Review Comment:
   Fixed.



##########
cpp/src/arrow/csv/fuzz.cc:
##########
@@ -29,92 +29,160 @@
 #include "arrow/util/fuzz_internal.h"
 #include "arrow/util/macros.h"
 #include "arrow/util/thread_pool.h"
+#include "arrow/util/value_parsing.h"
 
 namespace arrow::csv {
 
 using ::arrow::internal::GetCpuThreadPool;
 using ::arrow::io::InputStream;
 
-Status FuzzCsvReader(const uint8_t* data, int64_t size) {
-  // Since the Fuzz-allocated data is not owned, any task that outlives the 
TableReader
-  // may try to read memory that has been deallocated. Hence we wait for all 
pending
-  // tasks to end before leaving.
-  struct TaskGuard {
-    ~TaskGuard() { GetCpuThreadPool()->WaitForIdle(); }
-  };
+namespace {
 
-  auto io_context = arrow::io::default_io_context();
+// Packed header prefixing the fuzz payload, used 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).
+//
+// All option values are total functions of the header bytes, so every possible
+// input leads to a well-defined option set. Inputs shorter than the header are
+// read with the original hardcoded options, preserving the fuzzer's historical
+// behavior on legacy corpus entries.
+constexpr int64_t kFuzzHeaderSize = 8;
+
+struct FuzzCsvOptions {
+  ReadOptions read;
+  ParseOptions parse;
+  ConvertOptions convert;
+};
+
+FuzzCsvOptions MakeFuzzCsvOptions(const uint8_t* header) {

Review Comment:
   Fixed.



-- 
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]

Reply via email to