From: Eric Biggers Date: Wed, 27 Aug 2014 01:41:06 +0000 (-0500) Subject: win32_apply.c: set_short_name(): Increase minimum buffer size X-Git-Tag: v1.7.2~51 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=ca5539953d4927c61c7a45f719eab2d6e139cb5b win32_apply.c: set_short_name(): Increase minimum buffer size --- diff --git a/src/win32_apply.c b/src/win32_apply.c index 1f68b69f..a6b37c4a 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -851,8 +851,20 @@ set_short_name(HANDLE h, const struct wim_dentry *dentry, if (!ctx->common.supported_features.short_names) return 0; + /* + * Note: The size of the FILE_NAME_INFORMATION buffer must be such that + * FileName contains at least 2 wide characters (4 bytes). Otherwise, + * NtSetInformationFile() will return STATUS_INFO_LENGTH_MISMATCH. This + * is despite the fact that FileNameLength can validly be 0 or 2 bytes, + * with the former case being removing the existing short name if + * present, rather than setting one. + * + * FileName seemingly does not, however, need to be null-terminated in + * any case. + */ + size_t bufsize = offsetof(FILE_NAME_INFORMATION, FileName) + - dentry->short_name_nbytes; + max(dentry->short_name_nbytes, 2 * sizeof(wchar_t)); u8 buf[bufsize] _aligned_attribute(8); FILE_NAME_INFORMATION *info = (FILE_NAME_INFORMATION *)buf; NTSTATUS status;