fix UB when opening an empty sparse layer - #453
Open
youhangwang wants to merge 1 commit into
Open
youhangwang wants to merge 1 commit into
youhangwang wants to merge 1 commit into
Conversation
Signed-off-by: youhwsh <youhangwang@foxmail.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A small regression test covering “open empty sparse RW layer (0 mappings)” should be added/strengthened to prevent this UB from reappearing unnoticed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes undefined behavior in the sparse RW open path by avoiding &mappings[0] when the mappings vector is empty, ensuring empty sparse layers can be opened safely.
Changes:
- Replace
&mappings[0]withmappings.data()when constructing the in-memory index for sparse RW layers.
File summaries
| File | Description |
|---|---|
| src/overlaybd/lsmt/file.cpp | Avoids UB when passing an empty std::vector<SegmentMapping> to create_memory_index0() during sparse RW open. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| LOG_ERROR_RETURN(0, nullptr, "failed to create segment mappings from sparse file!"); | ||
| } | ||
| pi = create_memory_index0((const SegmentMapping *)&mappings[0], mappings.size(), | ||
| pi = create_memory_index0(mappings.data(), mappings.size(), |
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.
What this PR does / why we need it:
open_file_rw()uses&mappings[0]even whenmappingsmay be empty. An empty sparse file produces zeroSegmentMappingentries fromcreate_mappings(), making&mappings[0]undefined behavior.Use
mappings.data()instead, which is well-defined for an empty vector and allows the existing zero-length case to be handled safely.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Please check the following list: