From 0d5437fc329d30271e5da18bc512cb7481a92523 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20Matos?= Date: Tue, 16 Jun 2015 19:26:16 +0100 Subject: [PATCH] [WindowsBase] Fixed string buffer overflow when handling Zip entries. Fixes NuGet package handling, see https://bugzilla.xamarin.com/show_bug.cgi?id=26205. --- mcs/class/WindowsBase/ZipSharp/NativeUnzip.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mcs/class/WindowsBase/ZipSharp/NativeUnzip.cs b/mcs/class/WindowsBase/ZipSharp/NativeUnzip.cs index 47e277bdbfb..79a9dc62aec 100644 --- a/mcs/class/WindowsBase/ZipSharp/NativeUnzip.cs +++ b/mcs/class/WindowsBase/ZipSharp/NativeUnzip.cs @@ -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; -- 2.25.1