[Clang] Fix out-of-bounds read when filtering dependency-file entries - #23080
Merged
uditagarwal97 merged 1 commit intoSep 2, 2026
Merged
Conversation
The dependency filter compared FD.size() bytes of a filename that may be shorter than the filter, reading past the end of the StringRef. Use StringRef::starts_with, which is what the comment above the loop already described. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
uditagarwal97
requested review from
zahiraam
and
a balanced review from Copilot
September 2, 2026 00:31
uditagarwal97
marked this pull request as ready for review
September 2, 2026 00:32
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused change preserves filtering semantics while safely handling filenames shorter than the filter.
Pull request overview
Prevents an out-of-bounds read while applying dependency-file prefix filters.
Changes:
- Replaces unsafe fixed-length comparison with bounds-aware
StringRef::starts_with.
File summaries
| File | Description |
|---|---|
clang/lib/Frontend/DependencyFile.cpp |
Safely checks dependency filter prefixes. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
tahonermann
approved these changes
Sep 2, 2026
tahonermann
left a comment
Contributor
There was a problem hiding this comment.
That's so much better! The updated code isn't just correct, it actually expresses the intent! Thanks, @uditagarwal97!
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.
DependencyFileGenerator::sawDependency()filters out dependencies whose name starts with a filter string:Filenameis aStringRef, andstd::string::compare(pos, len, const char *s, size_t n)readsnbytes fromsunconditionally. When the filename is shorter than the filter, this reads past the end of the referenced buffer.StringRefis not guaranteed to be NULL-terminated, and here it points into memory owned by aBumpPtrAllocator, so the read runs into the allocator's redzone.AddressSanitizer report, hit while compiling
sycl/test/include_deps/header_reach.cppwith-fsycl:Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com