Skip to content

Cherry pick #112839 to 26.3: Fix segfault and silent data corruption when appending a non-appendable format to a file - #112923

Merged
PedroTadim merged 4 commits into
backport/26.3/112839from
cherrypick/26.3/112839
Aug 2, 2026
Merged

PedroTadim merged 4 commits into
backport/26.3/112839from
cherrypick/26.3/112839

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #112839

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 3 commits July 31, 2026 21:25
…geFileSink

A format that registers markFormatHasNoAppendSupport cannot be appended to, and
StorageFile::write enforces that. The check lives inside if (!paths.empty()), so
two routes into StorageFileSink never reach it: a write through a file descriptor
never populates paths, and a partitioned write returns its sink before the check.
Both then let StorageFileSink::initialize suppress the format prefix for a target
that already has bytes.

With rows that appends a second Avro header after the existing data, so the query
succeeds with no diagnostic and the resulting file no longer reads back. With zero
rows nothing calls DataFileWriterBase::syncIfNeeded, which is the only thing that
binds the encoder to a stream; DataFileWriterBase::sync then flushes the encoder as
its first statement and binds the stream one line later, so StreamWriter::out_ is
still the default nullptr and the server dies with SIGSEGV. The second one is the
failure reported on #111164.

Ask the format's own append-support checker in StorageFileSink::initialize, where
the authoritative per-sink size is computed and one statement before the prefix is
suppressed. That covers both symptoms and both uncovered routes, and it also closes
the window between the query-start stat in StorageFile::write and the per-sink
fstat. Adding syncIfNeeded to AvroRowOutputFormat::finalizeImpl was tried first and
rejected on measurement: it stops the fault but still writes an unreadable file, so
it trades a loud failure for silent corruption.

On these two routes an INSERT into a non-empty file now fails for Arrow,
ArrowStream, JSON, Npy, ORC and Parquet where it previously returned success.
Measuring all thirteen always-non-appendable formats there shows none of them ever
appended: five read back only the original row and silently discard the appended
one, Parquet fails a column read, and the rest already errored. The File engine
documentation is qualified accordingly in the same commit.
…ed checker

Review round 1 on the StorageFileSink no-append guard.

The documentation sentence added with the guard advised the
`engine_file_truncate_on_insert` and `engine_file_allow_create_multiple_files`
settings unconditionally, but neither setting applies on the file-descriptor
route: `StorageFileSink::initialize` builds a `WriteBufferFromFileDescriptor`
without consulting `flags`, and the multiple-files branch rewrites `paths`,
which is empty there. The guard's own error message already omits that advice
for this reason, so the two artifacts contradicted each other about the
behaviour this change introduces. The sentence is now scoped to a plain file
path and states why the descriptor route is different.

The settings-dependent-checker test cell only drove the checker's appendable
branch, where a guard keyed on a hardcoded format list and no guard at all both
succeed, so the cell could not distinguish them; removing the guard left it
green. It now also asserts the non-appendable configuration is rejected, which
fails under both bypasses and proves the per-statement setting reaches the
checker through `getFormatSettings`.

The test number moved from 04660 to 04668: 04660 was free on master when the
test was written but is now claimed by other unpublished work and by an open
pull request.

Co-Authored-By: Claude Fable 5 <[email protected]>
Fix segfault and silent data corruption when appending a non-appendable format to a file
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants