Skip to content

[SPARK-58946][SQL] Reject invalid CSV file extensions - #58226

Open
subhramit wants to merge 3 commits into
apache:masterfrom
subhramit:SPARK-58946
Open

[SPARK-58946][SQL] Reject invalid CSV file extensions#58226
subhramit wants to merge 3 commits into
apache:masterfrom
subhramit:SPARK-58946

Conversation

@subhramit

Copy link
Copy Markdown

Follow-up to #58225
Closes SPARK-58946

What changes were proposed in this pull request?

Changes && to || in the extension option validation in CSVOptions.scala:127.

Depends on SPARK-58945. Until that merges this path surfaces INTERNAL_ERROR rather than the intended error, so the new test will not pass on its own.

Why are the changes needed?

The error message states the extension is limited to exactly three letters, which requires rejecting anything not both three characters and all letters. && rejects only values failing both clauses, so these are accepted today:

value why it should be rejected
abcd four letters
ab1 three characters, not all letters
a one letter
a/b three characters, contains a path separator

The value flows into the output filename (CSVWrite.scala:61, CSVFileFormat.scala:91), so a/b places a path separator inside a filename component.

Does this PR introduce any user-facing change?

Yes. Writes that previously succeeded with an out-of-contract extension now fail with INVALID_PARAMETER_VALUE.EXTENSION. The option was documented as three letters only, so affected jobs were relying on validation that did not match its stated contract. Valid three-letter extensions are unaffected, and the only extension used in existing tests (tsv) remains valid.

How was this patch tested?

New case in CSVSuite covering abcd, ab1, and a. The existing SPARK-50616 tsv test continues to pass.

TODO: full suites:

build/sbt "sql/testOnly *CSVv1Suite"
build/sbt "sql/testOnly *CSVv2Suite"
build/sbt "sql/testOnly *CSVLegacyTimeParserSuite"

should pass once #58225 is merged and synced here.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5

…ree letters

Signed-off-by: subhramit <subhramit.bb@live.in>
@subhramit

subhramit commented Aug 23, 2026

Copy link
Copy Markdown
Author

Just to highlight - sql - other tests and sql - extended tests will not be green here until #58225 is merged, as CSVv1Suite, CSVLegacyTimeParserSuite and CSVv2Suite (which include the newly added test) will fail till then.

cc @uros-b @gengliangwang
/ @LuciferYang @szehon-ho if there is a possibility to expedite the merge.

}

test("SPARK-58946: reject file extensions that are not exactly three letters") {
Seq("abcd", "ab1", "a").foreach { ext =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test checks "abcd", "ab1", and "a" but omits "a/b", the path-separator case that the PR description explicitly singles out as a security concern (it would place a directory separator inside a filename component). Since the PR description treats this as a distinct risk, a test case for it would concretely validate the fix for that input and is worth adding alongside the others.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the test checks "reject file extensions that are not exactly three letters", I'll add a separate one below with the path separator case.

Signed-off-by: Subhramit Basu <subhramit.bb@live.in>
Signed-off-by: Subhramit Basu <subhramit.bb@live.in>
@subhramit
subhramit requested a review from uros-b August 24, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants