[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

text handling patch




Hi,

I've found and fixed another bug in rdesktop.

The symptoms of this bug are that following a large amount of whitespace
in a peice of text, the first character of the text may appear as a
different character, or you may get the following style of errors:

ERROR: get font x:yyy

where x and yyy are numeric.

The text may also be misaligned, usually too far to the left.

We found we could reproduce this problem easily and consistently with the
telnet program we were using, TeraTerm, and also when viewing text files
in netscape (the common factor being their use of mono-spaced fonts)
simply by having two or more tab characters in a row.

Some investigation of the data being sent revealed the cause:  text data
is normally sent as pairs of numbers: an index into the font cache
followed by an x offset to apply.  However, rdesktop asumes that the
offset will be expressed by a single byte.  Instead (like many other
length encodings in the protocol) only offsets < 0x80 are apparently
encoded as a single byte.  Offsets of 0x80 and above are actually encoded
as 0x80 followed by a two byte length field (little endian).  Rdesktop was
reading this as an x offset of 0x80 prior to the first character (hence
the misalignment) followed by an arbitrary glyph with offset zero (hence
overwriting the first character).

The tiny patch I've attached fixes this problem.

Ben.

/   Ben McKeegan, I.T. Manager                                         \
\   Fitzwilliam College, University of Cambridge, UK.                  /


Common subdirectories: rdesktop-1.0.0.orig/crypto and rdesktop-1.0.0/crypto
diff -u rdesktop-1.0.0.orig/xwin.c rdesktop-1.0.0/xwin.c
--- rdesktop-1.0.0.orig/xwin.c	Mon Oct 16 09:44:48 2000
+++ rdesktop-1.0.0/xwin.c	Tue Nov 21 11:07:18 2000
@@ -500,7 +500,7 @@
 			int bgcolour, int fgcolour, uint8 *text, uint8 length)
 {
 	FONTGLYPH *glyph;
-	int i;
+	int i,xoffset;
 
 	if (boxcx > 1)
 	{
@@ -517,7 +517,13 @@
 		glyph = cache_get_font(font, text[i]);
 
 		if (!(flags & TEXT2_IMPLICIT_X))
-			x += text[++i];
+                {
+			xoffset = text[++i];
+                        if (xoffset & 0x80)
+                                x += text[++i] | (text[++i] << 8);
+                        else
+                                x += xoffset;
+		}
 
 		if (glyph != NULL)
 		{