Repository: files-community/Files
File: src/Files.App/Helpers/Win32/Win32Helper.Storage.cs (C#)

Code before:

		public static bool SetFileAttribute(string lpFileName, FileAttributes dwAttrs)
		{
			if (!Win32PInvoke.GetFileAttributesExFromApp(
				lpFileName, Win32PInvoke.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
			{
				return false;
			}
			return Win32PInvoke.SetFileAttributesFromApp(lpFileName, lpFileInfo.dwFileAttributes | dwAttrs);
		}

		public static bool UnsetFileAttribute(string lpFileName, FileAttributes dwAttrs)
		{
			if (!Win32PInvoke.GetFileAttributesExFromApp(
				lpFileName, Win32PInvoke.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
			{
				return false;
			}
			return Win32PInvoke.SetFileAttributesFromApp(lpFileName, lpFileInfo.dwFileAttributes & ~dwAttrs);
		}

		public static unsafe bool CanCompressContent(string path)
		{
			path = Path.GetPathRoot(path) ?? string.Empty;

			// MAX_PATH = 260 + 1 (null termination)
			var volumeName = new PWSTR();
			var fileSystemName = new PWSTR();

			uint serialNumber = 0;
			uint maxComponentLength = 0;
			uint fileSystemFlags = 0;

			var success = PInvoke.GetVolumeInformation(
				path,
				volumeName,
				261u,
				&serialNumber,
				&maxComponentLength,
				&fileSystemFlags,
				fileSystemName,
				261u);

			if (!success)
				return false;

			// 0x00000010 FILE_FILE_COMPRESSION
			return (fileSystemFlags & 0x00000010) != 0;
		}

		public static unsafe bool SetCompressionAttributeIoctl(string lpFileName, bool isCompressed)

Review comment (bug):
`MAX_PATH` is 260 including null termination char (`\0`), and 3 (`C:\`) + 256 (= 259) can be used as path chars.

```c
// Definition
#define MAX_PATH 260

// Usage ("" of C/C++/C# appends \0 automatically and if you use all 260, this'd stack-overflow)
char szPath[MAX_PATH] = "C:\\Windows";
```

```suggestion
			// MAX_PATH = 260 (includes null termination char)
```

Code after:
		public static bool SetFileAttribute(string lpFileName, FileAttributes dwAttrs)
		{
			if (!Win32PInvoke.GetFileAttributesExFromApp(
				lpFileName, Win32PInvoke.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
			{
				return false;
			}
			return Win32PInvoke.SetFileAttributesFromApp(lpFileName, lpFileInfo.dwFileAttributes | dwAttrs);
		}

		public static bool UnsetFileAttribute(string lpFileName, FileAttributes dwAttrs)
		{
			if (!Win32PInvoke.GetFileAttributesExFromApp(
				lpFileName, Win32PInvoke.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
			{
				return false;
			}
			return Win32PInvoke.SetFileAttributesFromApp(lpFileName, lpFileInfo.dwFileAttributes & ~dwAttrs);
		}

		public static unsafe bool CanCompressContent(string path)
		{
			path = Path.GetPathRoot(path) ?? string.Empty;
			uint dwFileSystemFlags = 0;

			var success = PInvoke.GetVolumeInformation(
				path,
				null,
				0u,
				null,
				null,
				&dwFileSystemFlags,
				null,
				0u);

			if (!success)
				return false;

			return (dwFileSystemFlags & PInvoke.FILE_FILE_COMPRESSION) != 0;
		}

		public static unsafe bool SetCompressionAttributeIoctl(string lpFileName, bool isCompressed)
		{
			// GENERIC_READ | GENERIC_WRITE flags are needed here
			// FILE_FLAG_BACKUP_SEMANTICS is used to open directories
			using var hFile = PInvoke.CreateFile(
				lpFileName,
				(uint)(FILE_ACCESS_RIGHTS.FILE_GENERIC_READ | FILE_ACCESS_RIGHTS.FILE_GENERIC_WRITE | FILE_ACCESS_RIGHTS.FILE_WRITE_ATTRIBUTES),
				FILE_SHARE_MODE.FILE_SHARE_READ | FILE_SHARE_MODE.FILE_SHARE_WRITE,
				lpSecurityAttributes: null,
				FILE_CREATION_DISPOSITION.OPEN_EXISTING,