Skip to content

fix uninitialized pointer entries from StringTable::parse - #9499

Open
Nashit-h wants to merge 6 commits into
halide:mainfrom
Nashit-h:string-table-parse-empty-tokens
Open

Nashit-h wants to merge 6 commits into
halide:mainfrom
Nashit-h:string-table-parse-empty-tokens

Conversation

@Nashit-h

@Nashit-h Nashit-h commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

StringTable::parse sizes and reports its result from count_tokens(), which counts every empty segment, but the fill loop skips empty tokens, so a string with consecutive, leading, or trailing delimiters leaves the trailing PointerTable slots unassigned; PointerTable allocates without zeroing, so size()/data()/operator[] then hand back uninitialized pointers. These reach the Vulkan driver through vk_create_instance (requested_layers.data() as ppEnabledLayerNames from HL_VK_LAYERS / VK_INSTANCE_LAYERS) and atoi() in the HL_VK_ALLOC_CONFIG path, where each is dereferenced. The fix releases the skipped trailing storage and shrinks the table to the number of tokens actually stored, returning that count, so no unassigned entry is ever exposed.

Verified with a poisoning allocator: before, parse("a::b", ":") returns 3 and entry [2] is 0xaaaa... (dereferencing it segfaults); after, it returns 2 with entries "a" and "b". Added a regression case to test/runtime/string_table.cpp covering leading/consecutive/trailing delimiters and an all-delimiter string.

AI tooling was used to help prepare this change.

Comment thread src/runtime/internal/string_table.h Outdated
Comment on lines +188 to +193

// Empty tokens (e.g. from consecutive, leading, or trailing delimiters) are
// skipped above but were still counted by count_tokens, so fewer entries get
// stored than slots were reserved for. Release the trailing unused storage
// and shrink to the number actually assigned, so size()/data()/operator[]
// never expose an uninitialized pointer entry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the right patch would be to fix count_tokens, then. Or to fix the code here to allocate the right amount up front. We have to do two passes over the string regardless.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Went with fixing count_tokens. It now skips empty tokens, so parse() reserves exactly the number of entries it stores and can return entry_count directly without any post-shrink. The second pass is unchanged, so no extra work over the string. Dropped the destroy/resize block from parse().

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.91%. Comparing base (197abe1) to head (0fdbe36).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9499      +/-   ##
==========================================
- Coverage   71.11%   70.91%   -0.21%     
==========================================
  Files         261      261              
  Lines       80229    80229              
  Branches    19551    19551              
==========================================
- Hits        57058    56897     -161     
- Misses      17374    17404      +30     
- Partials     5797     5928     +131     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@abadams

abadams commented Nov 2, 2026

Copy link
Copy Markdown
Member

Note that the clang-tidy thing is a false positive, because is_empty returns true for nullptr.

Comment thread src/runtime/internal/string_storage.h Resolved
@Nashit-h

Nashit-h commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@abadams agreed, is_empty already handles nullptr. I kept the explicit ptr && from Alex's suggestion since it's harmless and quiets clang-tidy, but happy to drop it if you'd rather add a NOLINT instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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