Technology1 min read

Another failed attempt to get the icon for the icon for the .. parent folder

By · Published by Everything Blog

In short

The shell namespace treats entries like double dots as literal child names rather than backward traversal instructions, triggering failures when no such item exists. Because different shell folders support alternate syntax like web URIs, the system does not automatically normalize paths with backslashes. To avoid these retrieval breakdowns, developers should sanitize input paths using functions such as GetFullPathName or PathAllocCombine.

Key points

  • Moving upward in the shell hierarchy requires deleting the final component from an item I…: Moving upward in the shell hierarchy requires deleting the final component from an item ID list instead of appending traversal commands.
  • The shell parser searches for literal child items named double dots because the architect…: The shell parser searches for literal child items named double dots because the architecture cannot interpret them as step-back instructions.
  • Developers must use GetFullPathName or PathAllocCombine to resolve relative path elements…: Developers must use GetFullPathName or PathAllocCombine to resolve relative path elements before querying the shell.

Sources checked by our analysis pipeline: 1

Last time, we looked at why asking SHGetFileInfo

for the icon of .. (the parent folder) produces inconsistent results. One of the things the customer tried was concatenating the .. to the current directory:

SHGetFileInfo(L"C:\\dir\\..", 0, &info, sizeof(info), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_SYSICONINDEX);

This in fact made it worse: The function failed!

What’s going on?

As I noted last time, if the thing you pass in looks like a relative path, it will be resolved against the current directory. But in this case, the string we passed doesn’t look like a relative path, so no such resolution occurs. The string C:\dir\.. is then sent through the namespace parser.

The shell namespace is structured as a tree of “folders”, and each folder knows how to parse its immediate children (some of which which might be folders). Parsing starts at the root folder (the Desktop), which parses enough to identify what the immediate child item is, and if that child item is a folder, it passes the unparsed portion of the string to that child folder, and the process continues until the…

Technology