microsoft / microsoft/Windows-classic-samples
AMGetWideString is bugged
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 5.7k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
AMGetWideString in Samples/Win7Samples/multimedia/directshow/baseclasses/wxutil.cpp is bugged:
// Return a wide string - allocating memory for it
// Returns:
// S_OK - no error
// E_POINTER - ppszReturn == NULL
// E_OUTOFMEMORY - can't allocate memory for returned string
STDAPI AMGetWideString(LPCWSTR psz, __deref_out LPWSTR *ppszReturn)
{
CheckPointer(ppszReturn, E_POINTER);
ValidateReadWritePtr(ppszReturn, sizeof(LPWSTR));
*ppszReturn = NULL;
ASSERT(psz);
const size_t nameLen = wcslen(psz);
*ppszReturn = (LPWSTR)CoTaskMemAlloc(nameLen + sizeof(WCHAR));
if (*ppszReturn == NULL) {
return E_OUTOFMEMORY;
}
CopyMemory(*ppszReturn, psz, nameLen + sizeof(WCHAR));
return NOERROR;
}
There's two lines that are problematic:
*ppszReturn = (LPWSTR)CoTaskMemAlloc(nameLen + sizeof(WCHAR));
...
CopyMemory(*ppszReturn, psz, nameLen + sizeof(WCHAR));
These should be * sizeof(WCHAR), not + sizeof(WCHAR). As a result this function won't copy the full string over, rather it will copy a small section of it and won't null-terminate it correctly.
This function is used in CBasePropertyPage::GetPageInfo in DirectShow, causing any property pages by custom DirectShow filters to have their titles render incorrectly.
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
Open Samples/Win7Samples/multimedia/directshow/baseclasses/wxutil.cpp and inspect AMGetWideString, then review its use from CBasePropertyPage::GetPageInfo. Verify that allocation and copying account for the full wide-character string and its terminator, and confirm that custom DirectShow property-page titles render correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100