You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR improves the fuzzing coverage and effectiveness of the Arrow C++ CSV reader, as part of the broader effort described in GH-54903. Currently, the CSV fuzz target reads every input with a fixed set of hardcoded options, and its seed corpus only covers a single dialect, so most of the reader's option space (delimiters, quoting/escaping, null handling, block sizes, dictionary encoding, timestamp parsers, ...) is explored mostly by chance.
The fuzz input is now prefixed with a packed, magic-number-prefixed header encoding a set of reader options, following the approach of the Parquet encoding fuzzer. Inputs that do not start with the expected magic are treated as legacy and read with the historical hardcoded options, so existing corpus entries keep working.
Each read strategy (single-threaded TableReader, multi-threaded TableReader, StreamingReader, and CountRowsAsync) is given a fresh input stream, since a reader consumes the stream it is passed.
When all three table reads succeed, the resulting tables are now checked for equality (differential fuzzing), aborting on inconsistency like the Parquet encoding fuzzer does.
cpp/src/arrow/csv/fuzz_header_internal.h (new): the packed FuzzCsvHeader structure (bit-field option groups with static_asserts on the layout), and its serialization and parsing/validation helpers.
cpp/src/arrow/csv/generate_fuzz_corpus.cc: generated seed files are now prefixed with the serialized fuzz header matching the dialect used for writing, and several dialect variants are generated (alternate delimiters, quote-all, headerless with autogenerated column names, N/A nulls). The batch-size variant was dropped, as it only exercised the writer's internal chunking, which is irrelevant for the reader.
cpp/build-support/fuzzing/pack_corpus.py: files with duplicate content now emit a warning and are skipped instead of failing the corpus packing (some Pandas test CSVs are exact duplicates of each other).
cpp/build-support/fuzzing/generate_corpuses.sh: removed the now-unneeded deduplication workaround; documented how dictionaries are used (they are hints to the fuzzing engine, not restrictions) - also documented in cpp/build-support/fuzzing/dicts/arrow-csv-fuzz.dict.
Are these changes tested?
Yes.
Are there any user-facing changes?
No.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Human
AI
Reviewed before submission by:
Human
AI
Not reviewed
Code and description were drafted with the help of an AI coding agent, then reviewed, revised and validated by the author before submission.
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
arthurscchan
changed the title
OSS-Fuzz: Update csv fuzzer and corpora/dict preparation
GH-54903: [OSS-Fuzz fuzzing] Update csv fuzzer and corpora/dict preparation
Oct 21, 2026
arthurscchan
changed the title
GH-54903: [OSS-Fuzz fuzzing] Update csv fuzzer and corpora/dict preparation
GH-54903: [C++][OSS-Fuzz fuzzing] Update csv fuzzer and corpora/dict preparation
Oct 22, 2026
Thanks for the comments, I will fix them and reconsider some of the approach soon. I will also handles the changes on OSS-Fuzz side.
For the PR message, I am sorry this is my first time committing to this repository and I missed the template requirements, I will fix them, together with the other two PRs when I fix and address your comments.
Honestly, this might be a great use case for libfuzzer's support for custom mutations. One could use the random seed to decide whether to mutate a subset structurally or the whole input. When the former: parse the CSV, pick some random subset of entries, un-escape them, mutate them, re-escape them, put them back. Otherwise, just use the normal mutator. Would also need to define a custom crossover, though.
(though, admittedly, this is a lot of extra work with maybe not a ton of gain 😅 CSV is already fairly unstructured)
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues are identified for the CSV fuzzing changes.
No open issues 🎉
What changed in this PR
This PR expands Arrow’s C++ CSV fuzzing coverage for GH-54903 by varying reader options, comparing reader results, and improving seed corpus and dictionary preparation.
Changes:
Adds a packed options header while preserving legacy corpus input handling.
Compares results across serial, threaded, and streaming readers and generates seeds for multiple CSV dialects.
Skips duplicate corpus content and packages CSV fuzzing dictionaries.
File
Description
cpp/src/arrow/csv/generate_fuzz_corpus.cc
Generates header-prefixed seeds for multiple CSV dialects.
cpp/src/arrow/csv/fuzz.cc
Decodes reader options and adds differential table checks.
cpp/src/arrow/csv/fuzz_header_internal.h
Defines the packed options header and serialization helpers.
cpp/build-support/fuzzing/pack_corpus.py
Warns and skips files with duplicate content.
cpp/build-support/fuzzing/generate_corpuses.sh
Copies dictionaries to the output and documents their use.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The CSV fuzz target uses an unsupported delimiter field that prevents compilation, and its table comparison can report false crashes when automatic dictionary encoding produces different representations.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Use the supported character delimiter option in the CSV fuzzer
cpp/src/arrow/csv/fuzz.cc:63
ParseOptions exposes only char delimiter (cpp/src/arrow/csv/options.h:46), not delimiter_string, so this prevents the CSV fuzz target from compiling. Assign the selected character to opts.parse.delimiter and remove or replace the unsupported "@@" candidate in kFuzzCsvDelimiters (cpp/src/arrow/csv/fuzz_header_internal.h:51–52).
Normalize or skip equality checks for automatic dictionary encoding
cpp/src/arrow/csv/fuzz.cc:166
With automatic dictionary encoding enabled (including legacy inputs), different block sizes can produce different dictionaries or dictionary-versus-string schemas for identical CSV values, causing false fuzzing crashes here. Table::Equals compares dictionary representations rather than decoded values (cpp/src/arrow/compare.cc:488–498). Skip this assertion when automatic dictionary encoding is enabled while retaining the individual reads, or normalize dictionary columns to their value types before comparing.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
The CSV fuzzing and corpus-preparation changes have no active review issues.
No open issues 🎉
Review effort: Balanced
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
This PR improves the fuzzing coverage and effectiveness of the Arrow C++ CSV reader, as part of the broader effort described in GH-54903. Currently, the CSV fuzz target reads every input with a fixed set of hardcoded options, and its seed corpus only covers a single dialect, so most of the reader's option space (delimiters, quoting/escaping, null handling, block sizes, dictionary encoding, timestamp parsers, ...) is explored mostly by chance.
This change is coordinated with the OSS-Fuzz side in google/oss-fuzz#16332.
What changes are included in this PR?
cpp/src/arrow/csv/fuzz.cc:TableReader, multi-threadedTableReader,StreamingReader, andCountRowsAsync) is given a fresh input stream, since a reader consumes the stream it is passed.cpp/src/arrow/csv/fuzz_header_internal.h(new): the packedFuzzCsvHeaderstructure (bit-field option groups withstatic_asserts on the layout), and its serialization and parsing/validation helpers.cpp/src/arrow/csv/generate_fuzz_corpus.cc: generated seed files are now prefixed with the serialized fuzz header matching the dialect used for writing, and several dialect variants are generated (alternate delimiters, quote-all, headerless with autogenerated column names,N/Anulls). The batch-size variant was dropped, as it only exercised the writer's internal chunking, which is irrelevant for the reader.cpp/build-support/fuzzing/pack_corpus.py: files with duplicate content now emit a warning and are skipped instead of failing the corpus packing (some Pandas test CSVs are exact duplicates of each other).cpp/build-support/fuzzing/generate_corpuses.sh: removed the now-unneeded deduplication workaround; documented how dictionaries are used (they are hints to the fuzzing engine, not restrictions) - also documented incpp/build-support/fuzzing/dicts/arrow-csv-fuzz.dict.Are these changes tested?
Yes.
Are there any user-facing changes?
No.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by:
Code and description were drafted with the help of an AI coding agent, then reviewed, revised and validated by the author before submission.