Skip to content

Commit

Permalink
Fix access to files with long file names on win32/win64
Browse files Browse the repository at this point in the history
Long path were already handled with a prefix '\\?\' thanks to ALLOC_WIN32_PATH macro defined in platforms/win32/plugins/FilePlugin/sqWin32File.h
Unfortunately, when concatenating a file path shorter than MAX_PATH with a file name making the total longer than MAX_PATH,
using the macro REALLOC_WIN32_PATH, there were no '\\?\' prepended, and the file access did fail...

This commit does fix the REALLOC_WIN32_PATH to handle the case when path become longer than limit after growth.
  • Loading branch information
nicolas-cellier-aka-nice committed Oct 29, 2017
1 parent 945819f commit 59d0365
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions platforms/win32/plugins/FilePlugin/sqWin32File.h
Expand Up @@ -48,13 +48,20 @@

// if(wcscpy_s(in_out_wide_path, in_size < sz ? in_size : sz, tmp) != 0) FAIL(); \
#define REALLOC_WIN32_PATH(in_out_wide_path, in_size) { \
#define REALLOC_WIN32_PATH(in_out_wide_path, in_out_size) { \
int sz = wcslen(in_out_wide_path); \
WCHAR *tmp = in_out_wide_path; \
in_out_wide_path = (WCHAR*)alloca((in_size+1) * sizeof(WCHAR)); \
if(in_size < sz) tmp[in_size] = 0; \
wcscpy(in_out_wide_path, tmp); \
in_out_wide_path[in_size] = 0; \
in_out_wide_path = (WCHAR*)alloca((in_out_size+1) * sizeof(WCHAR)); \
if(in_out_size < sz) tmp[in_out_size] = 0; \
if(in_out_size >= MAX_PATH-12 && sz < MAX_PATH-12) { \
in_out_wide_path[0] = L'\\'; in_out_wide_path[1] = L'\\'; \
in_out_wide_path[2] = L'?'; in_out_wide_path[3] = L'\\'; \
wcscpy(in_out_wide_path+4, tmp); \
in_out_size += 4; \
} else { \
wcscpy(in_out_wide_path, tmp); \
} \
in_out_wide_path[in_out_size] = 0; \
}

#endif /* __SQ_WIN32_FILE_H */

0 comments on commit 59d0365

Please sign in to comment.