[WindowsBase] Fixed string buffer overflow when handling Zip entries.
authorJoão Matos <joao@tritao.eu>
Tue, 16 Jun 2015 18:26:16 +0000 (19:26 +0100)
committerJoão Matos <joao@tritao.eu>
Tue, 16 Jun 2015 18:28:21 +0000 (19:28 +0100)
Fixes NuGet package handling, see https://bugzilla.xamarin.com/show_bug.cgi?id=26205.

mcs/class/WindowsBase/ZipSharp/NativeUnzip.cs

index 47e277bdbfb05bbd356e31e95698256b54e15ca6..79a9dc62aec102d7098eedd9de86bc50edfde457 100644 (file)
@@ -80,8 +80,13 @@ namespace zipsharp
                static string GetCurrentFileName (UnzipHandle handle)
                {
                        UnzipFileInfo info;
-                       StringBuilder sbName = new StringBuilder (128);
-                       int result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);
+                       int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);
+
+                       if (result != 0)
+                               return null;
+                       
+                       StringBuilder sbName = new StringBuilder ((int)info.SizeFilename+1); // +1 to account for extra \0 at the end
+                       result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);
                        
                        if (result != 0)
                                return null;