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

bootloader: replace stray MAX_PATH with PATH_MAX #5617

Merged
merged 3 commits into from Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions appveyor.yml
Expand Up @@ -124,6 +124,12 @@ cache:


install:
# Enable long paths (needs reboot)
- ps: Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1
- ps: Start-Sleep -s 10
- ps: Restart-Computer -Force
- ps: Start-Sleep -s 10

- C:\cygwin\bin\du -hs "%LOCALAPPDATA%\pip\Cache"
# Prepend newly installed Python to the PATH of this build (this cannot be
# done from inside the powershell script as it would require to restart
Expand Down
4 changes: 2 additions & 2 deletions bootloader/src/pyi_path.c
Expand Up @@ -376,10 +376,10 @@ pyi_path_archivefile(char *archivefile, const char *thisfile)
FILE*
pyi_path_fopen(const char* filename, const char* mode)
{
wchar_t wfilename[MAX_PATH];
wchar_t wfilename[PATH_MAX];
wchar_t wmode[10];

pyi_win32_utils_from_utf8(wfilename, filename, MAX_PATH);
pyi_win32_utils_from_utf8(wfilename, filename, PATH_MAX);
pyi_win32_utils_from_utf8(wmode, mode, 10);
return _wfopen(wfilename, wmode);
}
Expand Down
2 changes: 2 additions & 0 deletions news/5617.bugfix.rst
@@ -0,0 +1,2 @@
Fix ``onefile`` builds failing to extract files when the full target
path exceeds 260 characters.
39 changes: 39 additions & 0 deletions tests/functional/test_basic.py
Expand Up @@ -606,3 +606,42 @@ def test_pe_checksum(pyi_builder):
ctypes.byref(checksum)) == 0

assert header_sum.value == checksum.value


def test_onefile_longpath(pyi_builder, tmpdir):
"""
Verify that files with paths longer than 260 characters are correctly
extracted from the onefile build. See issue #5615."
"""
# The test is relevant only for onefile builds
if pyi_builder._mode != 'onefile':
pytest.skip('The test is relevant only to onefile builds.')
# Create data file with secret
_SECRET = 'LongDataPath'
src_filename = tmpdir / 'data.txt'
with open(src_filename, 'w') as fp:
fp.write(_SECRET)
# Generate long target filename/path; eight equivalents of SHA256
# strings plus data.txt should push just the _MEIPASS-relative path
# beyond 260 characters...
dst_filename = os.path.join(
*[32*chr(c) for c in range(ord('A'), ord('A')+8)], 'data.txt')
assert len(dst_filename) >= 260
# Name for --add-data
if is_win:
add_data_name = src_filename + ';' + os.path.dirname(dst_filename)
else:
add_data_name = src_filename + ':' + os.path.dirname(dst_filename)

pyi_builder.test_source(
"""
import sys
import os

data_file = os.path.join(sys._MEIPASS, r'{data_file}')
print("Reading secret from %r" % (data_file))
with open(data_file, 'r') as fp:
secret = fp.read()
assert secret == r'{secret}'
""".format(data_file=dst_filename, secret=_SECRET),
['--add-data', str(add_data_name)])