-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Code Quality: Sync the jump list with Explorer #17564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
71afbb3 to
9eb7ae9
Compare
97999e5 to
806f922
Compare
278a971 to
33efe98
Compare
|
This might help with #14526 |
|
Would this fix #17659 |
|
Yes. This is one of the motivation. (I updated the PR to include this) |
a038857 to
3669604
Compare
9daefd6 to
032a523
Compare
7529df0 to
ec45efa
Compare
edbda5e to
816fcdc
Compare
c627341 to
93b5b34
Compare
src/Files.App.Storage/Windows/Helpers/WindowsStorageHelpers.System.cs
Outdated
Show resolved
Hide resolved
| using ComHeapPtr<char> pszParseablePath = default; | ||
| pszParseablePath.Allocate(PInvoke.MAX_PATH); | ||
| hr = psl.Get()->GetArguments(pszParseablePath.Get(), (int)PInvoke.MAX_PATH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: A buffer overflow occurs because memory for a character buffer is allocated in bytes (MAX_PATH), but the size is passed to a WinAPI function as a character count, effectively halving the buffer's safe capacity.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The code allocates memory for string buffers using ComHeapPtr<char>.Allocate(PInvoke.MAX_PATH), which allocates 260 bytes. Since a C# char is a 2-byte wide character, this buffer can only hold 130 characters. However, subsequent calls to Windows APIs like GetArguments and GetFolderIconLocation are told the buffer can hold MAX_PATH (260) characters. If the path or argument string returned by the API is longer than 130 characters, a buffer overflow will occur, writing past the allocated memory and likely causing a crash. This issue is present in multiple locations within JumpListManager.cs.
💡 Suggested Fix
When allocating memory for wide character strings, ensure the byte count is correctly calculated. Modify the allocation call to pszParseablePath.Allocate(PInvoke.MAX_PATH * sizeof(char)) to allocate enough space for 260 characters, not 260 bytes. Apply this fix to all similar API calls in the file.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/Files.App.Storage/Windows/Managers/JumpListManager.cs#L274-L276
Potential issue: The code allocates memory for string buffers using
`ComHeapPtr<char>.Allocate(PInvoke.MAX_PATH)`, which allocates 260 bytes. Since a C#
`char` is a 2-byte wide character, this buffer can only hold 130 characters. However,
subsequent calls to Windows APIs like `GetArguments` and `GetFolderIconLocation` are
told the buffer can hold `MAX_PATH` (260) characters. If the path or argument string
returned by the API is longer than 130 characters, a buffer overflow will occur, writing
past the allocated memory and likely causing a crash. This issue is present in multiple
locations within `JumpListManager.cs`.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7681507
| hr = pFilesICDL.Get()->EnumerateCategoryDestinations(indexOfRecentCategory, IID.IID_IObjectCollection, (void**)poc.GetAddressOf()); | ||
|
|
||
| // Get the count of items in the "Recent" category | ||
| uint countOfItems = 0U; | ||
| hr = poc.Get()->GetCount(&countOfItems); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The return value of EnumerateCategoryDestinations is not checked. If the call fails, a subsequent method call on the uninitialized poc pointer will cause a null pointer dereference.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The HRESULT returned from the COM call pFilesICDL.Get()->EnumerateCategoryDestinations(...) is not checked for failure. If this call fails, the poc ComPtr will remain uninitialized (null). The subsequent line immediately attempts to dereference this pointer by calling poc.Get()->GetCount(...), which will result in a null pointer dereference and cause an access violation crash. This type of failure can occur under various system conditions, such as resource pressure or corrupted file stores.
💡 Suggested Fix
Add an error check immediately after the call to EnumerateCategoryDestinations. If the returned HRESULT indicates a failure, the function should return the error code to prevent the application from attempting to use the uninitialized poc pointer. For example: if (FAILED(hr)) return hr;.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/Files.App.Storage/Windows/Managers/JumpListManager.cs#L256-L260
Potential issue: The `HRESULT` returned from the COM call
`pFilesICDL.Get()->EnumerateCategoryDestinations(...)` is not checked for failure. If
this call fails, the `poc` `ComPtr` will remain uninitialized (null). The subsequent
line immediately attempts to dereference this pointer by calling
`poc.Get()->GetCount(...)`, which will result in a null pointer dereference and cause an
access violation crash. This type of failure can occur under various system conditions,
such as resource pressure or corrupted file stores.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7681507
Resolved / Related Issues
TODOs
Steps used to test these changes