Skip to content

[Clang] Fix out-of-bounds read when filtering dependency-file entries - #23080

Merged
uditagarwal97 merged 1 commit into
intel:syclfrom
uditagarwal97:private/udit/clang-depfile-filter-oob
Sep 2, 2026
Merged

[Clang] Fix out-of-bounds read when filtering dependency-file entries#23080
uditagarwal97 merged 1 commit into
intel:syclfrom
uditagarwal97:private/udit/clang-depfile-filter-oob

Conversation

@uditagarwal97

Copy link
Copy Markdown
Contributor

DependencyFileGenerator::sawDependency() filters out dependencies whose name starts with a filter string:

// Remove dependencies that are prefixed by the Filter string.
for (const std::string &FD : DependencyFilter)
  if (FD.compare(0, FD.size(), Filename.data(), FD.size()) == 0)
    return false;

Filename is a StringRef, and std::string::compare(pos, len, const char *s, size_t n) reads n bytes from s unconditionally. When the filename is shorter than the filter, this reads past the end of the referenced buffer. StringRef is not guaranteed to be NULL-terminated, and here it points into memory owned by a BumpPtrAllocator, so the read runs into the allocator's redzone.

AddressSanitizer report, hit while compiling sycl/test/include_deps/header_reach.cpp with -fsycl:

ERROR: AddressSanitizer: use-after-poison on address ...
READ of size 42 at ... thread T0
    #0 ... in clang::DependencyFileGenerator::sawDependency(llvm::StringRef, bool, bool, bool, bool)
       clang/lib/Frontend/DependencyFile.cpp:290

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

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 uditagarwal97 self-assigned this Sep 2, 2026
@uditagarwal97
uditagarwal97 requested review from zahiraam and a balanced review from Copilot September 2, 2026 00:31
@uditagarwal97
uditagarwal97 marked this pull request as ready for review September 2, 2026 00:32
@uditagarwal97
uditagarwal97 requested a review from a team as a code owner September 2, 2026 00:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 tahonermann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's so much better! The updated code isn't just correct, it actually expresses the intent! Thanks, @uditagarwal97!

@uditagarwal97
uditagarwal97 merged commit 74b4879 into intel:sycl Sep 2, 2026
30 checks passed
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.

3 participants