Free space check code in mingw-w64 ftruncate64 function is broken.
For example when the volume is not found, it calls GetDiskFreeSpaceExW()
with NULL first argument which always fails. This code seems to be
unreliable and probably is wrong as the POSIX ftruncate function can
create a file with holes which means that reported file size can be larger
then the underlying disk size. So disable free space check and let followup
WinAPI calls to fail if there are size restriction issues.
---
 mingw-w64-crt/stdio/mingw_ftruncate64.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mingw-w64-crt/stdio/mingw_ftruncate64.c 
b/mingw-w64-crt/stdio/mingw_ftruncate64.c
index 57a6b8476261..c8892f2afb9b 100644
--- a/mingw-w64-crt/stdio/mingw_ftruncate64.c
+++ b/mingw-w64-crt/stdio/mingw_ftruncate64.c
@@ -12,6 +12,7 @@
 #include <windows.h>
 #include <psapi.h>
 
+#if 0
 /* Mutually exclusive methods
   We check disk space as truncating more than the allowed space results
   in file getting mysteriously deleted
@@ -238,6 +239,7 @@ checkfreespace (const HANDLE f, const ULONGLONG 
requiredspace)
   } /* We have enough space to truncate/expand */
   return 0;
 }
+#endif
 
 int __cdecl __mingw_ftruncate64(int __fd, _off64_t __length) {
   HANDLE f;
@@ -268,11 +270,13 @@ int __cdecl __mingw_ftruncate64(int __fd, _off64_t 
__length) {
     goto errorout;
   }
 
+#if 0
   /* Check available space */
   check = checkfreespace(f,__length);
   if (check != 0) {
     return -1; /* Error, errno already set */
   }
+#endif
 
   quad.QuadPart = __length;
   check = SetFilePointer(f, (LONG)quad.LowPart, &(quad.HighPart), FILE_BEGIN);
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to