Skip to content
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

[Windows 10 64bit] PSUTIL 32bit (WOW64) fails to read process name longer than 128 characters #1980

Open
PetrPospisil opened this issue Aug 16, 2021 · 3 comments

Comments

@PetrPospisil
Copy link
Contributor

PetrPospisil commented Aug 16, 2021

Summary

  • OS: { WIN10 }
  • Architecture: { 64bit }
  • Psutil version: { 5.8.0 - 32b }
  • Python version: { 32b does not matter }
  • Type: { core }

Description

PSUTIL 32b fails to read path longer than 128characters due to different behaviour of NtQuerySystemInformation when called by 32bit process (WOW64) in Windows 10 64b. When the NtQuerySystemInformation is called by 32bit process (WOW64) it does not return processIdInfo.ImageName.MaximumLength increased and returns 0x100 (original value), so your library fails on error STATUS_INFO_LENGTH_MISMATCH (24). 64b version of an app gets the processIdInfo.ImageName.MaximumLength correctly increased.

I propose to increase size of the buffer in the iterative way till the API stops sending STATUS_INFO_LENGTH_MISMATCH instead as a workaround to this issue.

See parent issue with reproduction info:
Azure/azure-cli#19193

Please fix, thx.

@giampaolo
Copy link
Owner

giampaolo commented Aug 16, 2021

If you understand the problem and have a solution for it please attach a diff, but FYI I'm cautious about making changes to that part of the code (WoW 64 process handling). Historically it has always been quite complicated and messy. We had tons of bug reports related to STATUS_INFO_LENGTH_MISMATCH and other errors, which is why I eventually gave up and turned those errors into AccessDenied.

@PetrPospisil
Copy link
Contributor Author

@giampaolo PR #1981 is ready. Do you have any timetable to review, test and finish it?

@Anton-V-K
Copy link

The issue happens with names like WindowsInternal.ComposableShell.Experiences.TextInput.InputApp.exe (~67 letters, which are probably handled as 2-byte characters) on Windows 10 64-bit with Python 3.9.7 32-bit:
2021 10 25-Task_Manager-very_long_process_name
The test script:

import psutil

try:
    for proc in psutil.process_iter(attrs=['pid', 'name']):
        print(proc.info['pid'], proc.info['name']) # list all found processes
        if proc.info['name'] is None:
            break
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
    pass

The output lists only four processes:

...>python test_s3e_2.py
0 System Idle Process
4 System
120 Registry
268 None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants