[Mono-bugs] [Bug 70369][Maj] New - mix of byte and char types in SeekableStreamReader leads to parsing error in some cases

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 9 Dec 2004 07:29:11 -0500 (EST)


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 dobos_s@ibcnet.hu.

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

--- shadow/70369	2004-12-09 07:29:11.000000000 -0500
+++ shadow/70369.tmp.18924	2004-12-09 07:29:11.000000000 -0500
@@ -0,0 +1,116 @@
+Bug#: 70369
+Product: Mono: Compilers
+Version: 1.0
+OS: GNU/Linux [Other]
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: dobos_s@ibcnet.hu               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Summary: mix of byte and char types in SeekableStreamReader leads to parsing error in some cases
+
+Description of Problem:
+SeekableStreamReader class mixes bytes and chars in Position handling.
+In some cases this leads to bad parameters when calling GetByteCount 
+and a parsing error.
+
+parse() procedure handles error in bad way too: calls Report.Error 
+before writing exception to console. 
+When Report.Error exits the program the exception will be never displayed.
+
+Steps to reproduce the problem:
+Try to compile big and complex source file with a lot of one-char tokens.
+You should hit that combination, when buffer_size > buffer.Length in
+set_Position at the call of GetByteCount.
+
+Actual Results:
+You will get the following exception (after applying the cs-parser patch):
+
+System.ArgumentOutOfRangeException: ArgRange_Array
+Parameter name: count
+in <0x000ea> System.Text.UTF8Encoding:InternalGetByteCount (char
+[],int,int,uint,bool)
+in <0x0001b> System.Text.UTF8Encoding:GetByteCount (char[],int,int)
+in <0x00192> Mono.CSharp.SeekableStreamReader:set_Position (int)
+in <0x0019b> Mono.CSharp.Tokenizer:is_punct (char,bool&)
+in <0x0044c> Mono.CSharp.Tokenizer:xtoken ()
+in <0x00017> Mono.CSharp.Tokenizer:token ()
+in <0x002ba> Mono.CSharp.CSharpParser:yyparse 
+(Mono.CSharp.yyParser.yyInput)
+in <0x00079> Mono.CSharp.CSharpParser:parse ()
+
+/tmp/94450.0.cs(825) error CS8025: Parsing error
+Compilation failed: 1 error(s), 0 warnings
+
+
+Expected Results:
+Compiled binary without errors.
+
+How often does this happen? 
+Always on this kind of source (described above)
+
+
+Additional Information:
+--- mcs/support.cs.bck	2004-12-09 10:41:39.000000000 +0100
++++ mcs/support.cs	2004-12-09 12:20:06.000000000 +0100
+@@ -410,7 +410,7 @@
+ 					int byte_offset = value - 
+buffer_start;
+ 					pos = byte_offset;
+ 					// encoded characters can take 
+more than 1 byte length
+-					while 
+(reader.CurrentEncoding.GetByteCount (buffer, 0, pos) > byte_offset)
++					while ((pos > buffer.Length) || 
+(reader.CurrentEncoding.GetByteCount (buffer, 0, pos) > byte_offset)) 
+ 						pos--;
+ 					
+ 					return;
+--- mcs/cs-parser.jay.bck	2004-10-29 20:49:55.000000000 +0200
++++ mcs/cs-parser.jay	2004-12-09 12:29:28.000000000 +0100
+@@ -4350,10 +4350,9 @@
+ 		// Please do not remove this, it is used during debugging
+ 		// of the grammar
+ 		//
+-		//	Console.WriteLine (e);
+-		Report.Error (-25, lexer.Location, "Parsing error");
+ 		if (Driver.parser_verbose)
+ 			Console.WriteLine (e);
++		Report.Error (-25, lexer.Location, "Parsing error");
+ 	}
+ }
+ 
+--- gmcs/support.cs.bck	2004-06-11 12:37:01.000000000 +0200
++++ gmcs/support.cs	2004-12-09 12:39:23.000000000 +0100
+@@ -517,7 +517,7 @@
+ 					int byte_offset = value - 
+buffer_start;
+ 					pos = byte_offset;
+ 					// encoded characters can take 
+more than 1 byte length
+-					while 
+(reader.CurrentEncoding.GetByteCount (buffer, 0, pos) > byte_offset)
++					while ((pos > buffer.Length) || 
+(reader.CurrentEncoding.GetByteCount (buffer, 0, pos) > byte_offset)) 
+ 						pos--;
+ 					
+ 					return;
+--- gmcs/cs-parser.jay.bck	2004-06-18 23:07:55.000000000 +0200
++++ gmcs/cs-parser.jay	2004-12-09 12:40:23.000000000 +0100
+@@ -4576,10 +4576,9 @@
+ 		// Please do not remove this, it is used during debugging
+ 		// of the grammar
+ 		//
+-		Console.WriteLine (e);
+-		Report.Error (-25, lexer.Location, "Parsing error");
+ 		if (Driver.parser_verbose)
+ 			Console.WriteLine (e);
++		Report.Error (-25, lexer.Location, "Parsing error");
+ 	}
+ }