[Mono-bugs] [Bug 76154][Blo] New - Bytes of integers written into stream in wrong order.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Sep 19 20:00:01 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by nev at delap.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76154

--- shadow/76154	2005-09-19 20:00:01.000000000 -0400
+++ shadow/76154.tmp.12917	2005-09-19 20:00:01.000000000 -0400
@@ -0,0 +1,59 @@
+Bug#: 76154
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: Darwin-8.2.0-Power_Macintosh-powerpc-32bit
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: Nev at Delap.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Bytes of integers written into stream in wrong order.
+
+The following seems broken to me, but I've read posts suggesting that 
+BitConverter.IsLittleEndian be used to detect the endianness and manually 
+fiddle things about, though that would seem to defeat the purpose of 
+NetworkOrder, so I defer to your greater wisdom...
+
+In Windows and Linux...
+ - the HostToNetworkOrder is doing the right thing
+   because it's making the little endian integer a
+   big endian... 1 -> 16777216
+ - Writing them both out the stream contains... 1 0 0 0 0 0 0 1
+
+In Darwin... (Mac OS X 10.4.2)
+ - the HostToNetworkOrder is doing the right thing
+   because it's leaving the big endian integer as
+   big endian... 1 -> 1
+ - in the stream it's all little endian, writing
+   them both out... 1 0 0 0 1 0 0 0
+ - it should have written out... 0 0 0 1 0 0 0 1 (I think?)
+
+So a Windows machine writing a stream with stream.Write
+(IPAddress.HostToNetworkOrder(1)) then read by a Darwin machine with 
+IPAddress.NetworkToHostOrder(stream.ReadInt32()) will read 16777216.
+
+So the stream has the bug in it. (I think?)
+
+            byte[] bytes = new byte[16];
+            bytes[0] = 0;
+            bytes[1] = 0;
+            bytes[2] = 0;
+            bytes[3] = 1;
+            MemoryStream memoryStream = new MemoryStream(bytes);
+            BinaryReader binaryReader = new BinaryReader(memoryStream);
+            int i = binaryReader.ReadInt32();
+            Assert.AreEqual(1, i); // On Windows, Linux
+                                   // it's all good, on
+                                   // Darwin this fails.
+                                   //   expected:1
+                                   //   but was: 16777216
+#else
+            Assert.Fail("You're running a platform not tested here.");
+#endif


More information about the mono-bugs mailing list