[PATCH 1 of 2] win32: allocate buffer of maximum length for GetVolumeInformation()

Yuya Nishihara yuya at tcha.org
Tue Jan 2 03:40:43 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1514862145 -32400
#      Tue Jan 02 12:02:25 2018 +0900
# Node ID 99cf3126c685bebbac8e7048f9267494d67ead50
# Parent  e01549a7bf0a6a7adbbb317a5d4bfde36c205b4d
win32: allocate buffer of maximum length for GetVolumeInformation()

It's documented that "the maximum buffer size is MAX_PATH+1", which is
slightly larger than 256.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -8,6 +8,7 @@
 from __future__ import absolute_import
 
 import ctypes
+import ctypes.wintypes as wintypes
 import errno
 import msvcrt
 import os
@@ -33,6 +34,7 @@ from . import (
 _HANDLE = ctypes.c_void_p
 _HWND = _HANDLE
 _PCCERT_CONTEXT = ctypes.c_void_p
+_MAX_PATH = wintypes.MAX_PATH
 
 _INVALID_HANDLE_VALUE = _HANDLE(-1).value
 
@@ -460,7 +462,7 @@ def getfstype(path):
                    _DRIVE_RAMDISK):
         return None
 
-    size = 256
+    size = _MAX_PATH + 1
     name = ctypes.create_string_buffer(size)
 
     if not _kernel32.GetVolumeInformationA(volume, None, 0, None, None, None,


More information about the Mercurial-devel mailing list