From f061115c037684a2b9cae1f27f5a0e6462b06719 Mon Sep 17 00:00:00 2001 From: "blizzard%redhat.com" Date: Tue, 6 Nov 2001 23:05:39 +0000 Subject: [PATCH] Bug #99174. Limit the length of requests to XDrawString to 32K avoid causing X protocol errors. r=alecf, sr=brendan --- gfx/src/gtk/nsRenderingContextGTK.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gfx/src/gtk/nsRenderingContextGTK.cpp b/gfx/src/gtk/nsRenderingContextGTK.cpp index 60eb2597346a..31930f0479c7 100644 --- a/gfx/src/gtk/nsRenderingContextGTK.cpp +++ b/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -2002,15 +2002,20 @@ nsRenderingContextGTK::my_gdk_draw_text (GdkDrawable *drawable, // gdk does this... we don't need it.. // XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid); + // We clamp the sizes down to 32768 which is the maximum width of + // a window. Even if a font was 1 pixel high and started at the + // left, the maximum size of a draw request could only be 32k. + if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) { XDrawString (drawable_private->xdisplay, drawable_private->xwindow, - gc_private->xgc, x, y, text, text_length); + gc_private->xgc, x, y, text, MIN(text_length, 32768)); } else { XDrawString16 (drawable_private->xdisplay, drawable_private->xwindow, - gc_private->xgc, x, y, (XChar2b *) text, text_length / 2); + gc_private->xgc, x, y, (XChar2b *) text, + MIN((text_length / 2), 32768)); } } else if (font->type == GDK_FONT_FONTSET)