Bug: Undefined behavior in param::hstring(std::wstring_view
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- backend-api-design
Research direction
Start at the param::hstring constructor taking std::wstring_view and follow its call into impl::create_hstring_on_stack(), where the out-of-bounds access is shown. Reproduce the fixed-size-buffer case described in the issue, then verify that the constructor no longer reads beyond the view and add regression coverage for the non-null-terminated input.
Written by the indexing model from the issue text.
Description
Version
v2.0.250303.1
Summary
The param::hstring constructor that takes a std::wstring_view involves undefined behavior.
A std::wstring_view is not guaranteed to be null-terminated. If it's constructed from a fixed-size buffer, the code from impl::create_hstring_on_stack() will result in UB due to out-of-bounds access:
if (value[length] != 0)
{
abort();
}
In most cases, value[length] will cause a segmentation fault, without reaching the abort() call.
Reproducible example
Expected behavior
No response
Actual behavior
No response
Additional comments
No response
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 281
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/cppwinrt
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 20/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
All issues in microsoft/cppwinrt
Similar issues
-
AuTest Bug Tests
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/trafficserver#13714 ·
-
bug build
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
facebookincubator/velox#19143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tenstorrent/tt-metal#57393 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/eo-graphs#74 ·