[corlib] Fixed FileStream Write after Read issue
authorMarcos Henrich <marcos.henrich@xamarin.com>
Thu, 25 Feb 2016 18:39:30 +0000 (18:39 +0000)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Thu, 25 Feb 2016 18:47:09 +0000 (18:47 +0000)
FileStream was writing to the wrong position When a value longer than
the FileStream buffer was written after a read.

This was fixed by doing a seek before doing the problematic write.

Fixes #11699

mcs/class/corlib/System.IO/FileStream.cs

index 9de058fbb3a3a42800baa9f25b84bb13b948515a..42a3984b11d2261adaef4c71aff20ccb7fa47de2 100644 (file)
@@ -639,6 +639,13 @@ namespace System.IO
                                MonoIOError error;
 
                                FlushBuffer ();
+
+                               if (CanSeek && !isExposed) {
+                                       MonoIO.Seek (safeHandle, buf_start, SeekOrigin.Begin, out error);
+                                       if (error != MonoIOError.ERROR_SUCCESS)
+                                               throw MonoIO.GetException (GetSecureFileName (name), error);
+                               }
+
                                int wcount = count;
 
                                while (wcount > 0){