8000 Windows: test_os.test_stat_inaccessible_file() fails if run as an administrator · Issue #114435 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Windows: test_os.test_stat_inaccessible_file() fails if run as an administrator #114435

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

Closed
vstinner opened this issue Jan 22, 2024 · 9 comments
Closed
Labels
OS-windows tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member
vstinner commented Jan 22, 2024

When test_os is run as an administrator, like running tests in a SSH shell for example, the test fails:

FAIL: test_stat_inaccessible_file (test.test_os.Win32NtTests.test_stat_inaccessible_file)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\victor\python\main\Lib\test\test_os.py", line 3134, in test_stat_inaccessible_file
    self.assertEqual(0, stat2.st_dev)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
AssertionError: 0 != 10298252993199238233

The test was added recently by commit ed06648 of issue gh-111877.

Linked PRs

@zooba
Copy link
Member
zooba commented Jan 22, 2024

I could only repro this due to CreateJunction changing the privilege level of the process, which should be fixed now. Do you know if you're doing anything similar, or whether your admin user has been configured with extra privileges?

If not, we should bring back the test skip I tried in 6d0eac5 but use an explicit CreateFile call passing the backup semantics flag. That way at least we skip without failing.

@vstinner
Copy link
Member Author

See my comment on #114273 (comment)

@vstinner
Copy link
Member Author

I could only repro this due to CreateJunction changing the privilege level of the process, which should be fixed now.

I can still reproduce the issue on the current main branch at commit 5a1ecc8.

Do you know if you're doing anything similar, or whether your admin user has been configured with extra privileges?

I didn't create "C:\System Volume Information", I didn't touch permissions of this directory.

I don't know how to check privileges of my user.

On SSH, I get:

vstinner@WIN C:\victor\python\main>python -m test.pythoninfo
...
support_os_helper.can_chmod: True
support_os_helper.can_dac_override: False
support_os_helper.can_symlink: True
support_os_helper.can_xattr: False
...
windows.developer_mode: enabled
...
windows.is_admin: 1
...

I recently added windows.developer_mode and windows.is_admin to test.pythoninfo.

See my comment on #114273 (comment)

Sorry, it's unrelated.

@zooba
Copy link
Member
zooba commented Jan 23, 2024

Okay, I'll bring back the test skip once I'm done with the other test fixes I'm working on.

zooba added a commit to zooba/cpython that referenced this issue Jan 25, 2024
Also makes _winapi.CreateFile unconditionally use Unicode.
@aisk
Copy link
Contributor
aisk commented Jan 26, 2024

This test failed on my local machine even with a normal user:

PS C:\Users\xxxxx\Source\cpython> .\python.bat -m test test_os -m test_stat_inaccessible_file -v
Running Debug|x64 interpreter...
== CPython 3.13.0a3+ (heads/main:b69548a0f52, Jan 26 2024, 16:35:29) [MSC v.1936 64 bit (AMD64)]
== Windows-11-10.0.26020-SP0 little-endian
== Python build: debug
== cwd: C:\Users\xxxxx\Source\cpython\build\test_python_worker_13560æ
== CPU count: 16
== encodings: locale=cp936 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 2952692156
0:00:00 Run 1 test sequentially
0:00:00 [1/1] test_os
test_stat_inaccessible_file (test.test_os.Win32NtTests.test_stat_inaccessible_file) ... File: @test_13560_tmpæ
stat with access: os.stat_result(st_mode=33206, st_ino=7318349395089603, st_dev=10402348128892118190, st_nlink=1, st_uid=0, st_gid=0, st_size=9, st_atime=1706263911, st_mtime=1706263911, st_ctime=1706263911)
 without access: os.stat_result(st_mode=33206, st_ino=7318349395089603, st_dev=10402348128892118190, st_nlink=1, st_uid=0, st_gid=0, st_size=9, st_atime=1706263911, st_mtime=1706263911, st_ctime=1706263911)
FAIL

======================================================================
FAIL: test_stat_inaccessible_file (test.test_os.Win32NtTests.test_stat_inaccessible_file)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\xxxxx\Source\cpython\Lib\test\test_os.py", line 3134, in test_stat_inaccessible_file
    self.assertEqual(0, stat2.st_dev)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
AssertionError: 0 != 10402348128892118190

----------------------------------------------------------------------
Ran 1 test in 0.056s

FAILED (failures=1)
test test_os failed
test_os failed (1 failure)

== Tests result: FAILURE ==

1 test failed:
    test_os

Total duration: 1.0 sec
Total tests: run=1 (filtered) failures=1
Total test files: run=1/1 (filtered) failed=1
Result: FAILURE

I tried to create a new file xxx.txt, and running:

 icacls.exe .\xxx.txt /inheritance:r                   
已处理的文件: .\xxx.txt
已成功处理 1 个文件; 处理 0 个文件时失败

(The output means it processed 1 file successfully and 0 file failed.)

The file can't be opened in Python or notepad.exe, But the st_ino and st_dev are still non zero via os.stats:

.\python.bat -c "import os; print(os.stat('xxx.txt'))"
Running Debug|x64 interpreter...
os.stat_result(st_mode=33206, st_ino=36028797019051515, st_dev=10402348128892118190, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1706264132, st_mtime=1706264132, st_ctime=1706264113)

The only non trivial thing is that this is a Insider Preview Windows 11 with release version 26020.1000.

@zooba
Copy link
Member
zooba commented Jan 26, 2024

@aisk Is that with the skip that I added in #114571? It might apply even without admin in some cases, but it should detect this situation and skip the test.

@aisk
Copy link
Contributor
aisk commented Jan 26, 2024

@zooba No, it's using main branch's code. And with codes in #114571, the error is just the same.

@zooba
Copy link
Member
zooba commented Jan 26, 2024

I'll check, it may be due to the new API we used when it's available. If so, this test will just have to check for matching dev/ino or zero, and we won't be able to tell whether it's actually testing the right code path. But when the new API is present, we don't ever go into the old code path, so eventually it becomes irrelevant.

zooba added a commit to zooba/cpython that referenced this issue Jan 26, 2024
zooba added a commit that referenced this issue Jan 26, 2024
…ev (GH-114571)

This may occur if Windows allows reading stat information from a file even if the current user does not have access.
@zooba
Copy link
Member
zooba commented Jan 29, 2024

The test shouldn't fail anymore, provided we get one of the two possible valid values. It still tests that all the stat values are sensible in the case of file-specific ACLs, though it doesn't actually guarantee that we used the correct code path anymore.

@zooba zooba closed this as completed Jan 29, 2024
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
… ino/dev (pythonGH-114571)

This may occur if Windows allows reading stat information from a file even if the current user does not have access.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 23, 2024
… ino/dev (pythonGH-114571)

This may occur if Windows allows reading stat information from a file even if the current user does not have access.
(cherry picked from commit d91ddff)

Co-authored-by: Steve Dower <steve.dower@python.org>
zooba added a commit that referenced this issue Feb 23, 2024
…ev (GH-114571)

This may occur if Windows allows reading stat information from a file even if the current user does not have access.
(cherry picked from commit d91ddff)

Co-authored-by: Steve Dower <steve.dower@python.org>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
… ino/dev (pythonGH-114571)

This may occur if Windows allows reading stat information from a file even if the current user does not have access.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants
0