Repository navigation
Fix use-after-free in Hive unpartitioned read path - #109164
Merged
Merged
Conversation
In `StorageHive::collectHiveFiles`, the branch for a non-partitioned Hive table declares `file_infos` inside the `else` block and schedules worker tasks that capture the range-`for` variable `file_info` by reference (`[&]`). `file_infos` is destroyed at the closing brace of the `else` block, but `pool.wait()` - which joins those tasks - runs on the next line, after the vector is already freed. A task still executing (or queued) at that point dereferences a dangling reference into the freed `std::vector<FileInfo>`, so a multi-threaded read of a non-partitioned `Hive` table can read freed memory (a data race / use-after-free). The partition branch above is not affected: `partitions` is a function-scope local that outlives `pool.wait()`, so its `[&]` capture of `partition` (a reference bound to a `partitions` element) is well-defined and is left unchanged. The fix captures `file_info` by value in the `else`-branch task (`FileInfo` is a small, copyable struct: `path`, `last_modify_time`, `size`), so the closure owns its data and no longer depends on `file_infos` outliving the tasks.
1 task
Contributor
|
Workflow [PR], commit [bb35cf5] Summary: ❌
AI ReviewSummaryThis PR fixes the immediate dangling- Tests
Final Verdict |
kssenii
approved these changes
Jul 2, 2026
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 0/6 (0.00%) · Uncovered code |
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…tioned-read-uaf Fix use-after-free in Hive unpartitioned read path
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related: #108094
Fixes a pre-existing use-after-free in
StorageHive::collectHiveFileson the read path for a non-partitionedHivetable.In that branch,
file_infos(the result oflistDirectory) is a local of theelseblock and is destroyed at the block's closing brace, butpool.wait()— which joins the worker tasks — runs on the next line, after the vector is freed. The tasks capture the range-forvariablefile_info(aconst FileInfo &intofile_infos) by reference, so a task still executing or queued when theelseblock exits dereferences a dangling reference into the freedstd::vector<FileInfo>whilepool.wait()is joining. A multi-threaded read of a non-partitionedHivetable can therefore read freed memory (a use-after-free / data race).The partition branch above is not affected:
partitionsis a function-scope local that outlivespool.wait(), so its[&]capture of the reference loop variablepartitionis well-defined and is left unchanged.The fix captures
file_infoby value in theelse-branch task (FileInfois a small, copyable struct:path,last_modify_time,size), so the closure owns its data and no longer depends onfile_infosoutliving the tasks.This was found while reviewing the AI report on #108094; it is pre-existing on
master(independent of that crash fix) and is submitted here as a separate, focused change.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a use-after-free when reading a non-partitioned
Hivetable with multiple threads.Documentation entry for user-facing changes
Version info
26.7.1.530(included in26.7and later)