peass-ng/PEASS-ng · error · PathTooLongException

Path is greater than {0} characters: {1}

Error message

Path is greater than {0} characters: {1}

What it means

Thrown by the AlphaFS NativeMethods error mapper when the Win32 GetCurrentDirectory call reports a buffer/length failure: the returned working directory path exceeds the maximum character limit (MaxPathUnicode) the buffer was sized for. It fires when the process current directory is a very long path, typically on systems without long-path support enabled.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.GetCurrentDirectory.cs:62

      /// <returns>The path of the current working directory without a trailing directory separator.</returns>
      [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate"), SecurityCritical]
      public static string GetCurrentDirectory()
      {
         var nameBuffer = new StringBuilder(NativeMethods.MaxPathUnicode);

         // GetCurrentDirectory()
         // 2016-09-29: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
         // 2017-05-30: MSDN confirms LongPath usage: Starting with Windows 10, version 1607
         // 2018-01-15: MSDN confirmation is gone?

         var folderNameLength = NativeMethods.GetCurrentDirectory((uint) nameBuffer.Capacity, nameBuffer);
         var lastError = Marshal.GetLastWin32Error();

         if (folderNameLength == 0)
            NativeError.ThrowException(lastError);

         if (folderNameLength > NativeMethods.MaxPathUnicode)
            throw new PathTooLongException(string.Format(CultureInfo.InvariantCulture, "Path is greater than {0} characters: {1}", NativeMethods.MaxPathUnicode, folderNameLength));

         return nameBuffer.ToString();
      }
   }
}

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Shorten or relocate the current directory so the full path stays under the Unicode max path limit
  2. Enable Windows 10 long-path support (group policy / manifest longPathAware) so >260 char paths are accepted
  3. Use absolute paths from a shorter anchor directory instead of relying on a very long current directory
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.GetCurrentDirectory.cs:62 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/8c3e418df3aaccc4. Report an issue: GitHub.