Skip to content

Commit

Permalink
bootloader: replace stray MAX_PATH with PATH_MAX
Browse files Browse the repository at this point in the history
On Windows, `pyi_path_fopen()` erroneously uses `MAX_PATH` (260)
instead of `PATH_MAX` (4096) to convert the filename to wide
characters, which causes `MultiByteToWideChar()` call in
`pyi_win32_utils_from_utf8()` to fail with
```
MultiByteToWideChar: The data area passed to a system call is too
small.
```
when we try to open a file with a long filename (> 260).

Due to lack of error checking, the resulting `wfilename` array ends
up with random content, and the `_wfopen()` call either fails
(in read-only mode) or creates a randomly-named file (in write
mode).
  • Loading branch information
rokm committed Mar 8, 2021
1 parent 27d4fa7 commit 305789a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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.

0 comments on commit 305789a

Please sign in to comment.