Bug 23040 - jamvm crash after Invalid UTF8 string passed to pango_layout_set_text()
jamvm crash after Invalid UTF8 string passed to pango_layout_set_text()
Status: RESOLVED INVALID
Product: classpath
Classification: Unclassified
Component: classpath
unspecified
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-07-14 14:02 UTC by from-classpath
Modified: 2007-03-30 19:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-08-19 18:31:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description from-classpath 2005-07-14 14:02:26 UTC
Steps to reproduce:
1. Compile and run the attached testcase. I used jamvm 1.3.0 and classpath with --enable-gtk-cairo with cairo 0.5.0 and gtk+ 2.40 that comes with fedora core 3. I did not specify -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D

Expected results:
1. A window with all ASCII characters in a textarea shows up.

Actual results:
1. jamvm crashes with
** (:3318): WARNING **: Invalid UTF8 string passed to pango_layout_set_text()
*** glibc detected *** free(): invalid next size (fast): 0x096888a0 ***
Aborted (core dumped)

Testcase:
import javax.swing.*;
import java.awt.*;
public class testcase extends JFrame {
        public static void main(String[] args) {
                (new testcase()).show();
        }
        public testcase() {
                JTextArea a = new JTextArea();
                setContentPane(a);
                for (int i=0; i<256; i++)
                        a.append("" + (char)i);

                this.setSize(new Dimension(600, 400));
        }
}


Backtrace:
Core was generated by `/home/lindi/opt/jamvm/bin/jamvm -cp :.:/home/lindi/cp/2005-07-14T110617+0000/sh'.
Program terminated with signal 6, Aborted.
Reading symbols from /lib/tls/libpthread.so.0...done.
Loaded symbols for /lib/tls/libpthread.so.0
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/tls/libm.so.6...done.
Loaded symbols for /lib/tls/libm.so.6
Reading symbols from /usr/lib/libz.so.1...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /home/lindi/cp/2005-07-14T110617+0000/lib/classpath/libjavanio.so...done.
Loaded symbols for /home/lindi/cp/2005-07-14T110617+0000/lib/classpath//libjavanio.so
Reading symbols from /home/lindi/cp/2005-07-14T110617+0000/lib/classpath/libjavaio.so...done.
Loaded symbols for /home/lindi/cp/2005-07-14T110617+0000/lib/classpath//libjavaio.so
Reading symbols from /home/lindi/cp/2005-07-14T110617+0000/lib/classpath/libjavalang.so...done.
Loaded symbols for /home/lindi/cp/2005-07-14T110617+0000/lib/classpath//libjavalang.so
Reading symbols from /home/lindi/cp/2005-07-14T110617+0000/lib/classpath/libgtkpeer.so...done.
Loaded symbols for /home/lindi/cp/2005-07-14T110617+0000/lib/classpath//libgtkpeer.so
Reading symbols from /usr/lib/libgtk-x11-2.0.so.0...done.
Loaded symbols for /usr/lib/libgtk-x11-2.0.so.0
Reading symbols from /usr/lib/libgdk-x11-2.0.so.0...done.
Loaded symbols for /usr/lib/libgdk-x11-2.0.so.0
Reading symbols from /usr/lib/libatk-1.0.so.0...done.
Loaded symbols for /usr/lib/libatk-1.0.so.0
Reading symbols from /usr/lib/libpangoxft-1.0.so.0...done.
Loaded symbols for /usr/lib/libpangoxft-1.0.so.0
Reading symbols from /usr/lib/libpangox-1.0.so.0...done.
Loaded symbols for /usr/lib/libpangox-1.0.so.0
Reading symbols from /usr/lib/libgthread-2.0.so.0...done.
Loaded symbols for /usr/lib/libgthread-2.0.so.0
Reading symbols from /usr/lib/libgdk_pixbuf-2.0.so.0...done.
Loaded symbols for /usr/lib/libgdk_pixbuf-2.0.so.0
Reading symbols from /usr/lib/libfreetype.so.6...done.
Loaded symbols for /usr/lib/libfreetype.so.6
Reading symbols from /home/lindi/installdir-2005-06-14/cairo/lib/libcairo.so.1...done.
Loaded symbols for /home/lindi/installdir-2005-06-14/cairo/lib/libcairo.so.1
Reading symbols from /usr/lib/libfontconfig.so.1...done.
Loaded symbols for /usr/lib/libfontconfig.so.1
Reading symbols from /home/lindi/installdir-2005-06-14/cairo/lib/libpixman.so.1...done.
Loaded symbols for /home/lindi/installdir-2005-06-14/cairo/lib/libpixman.so.1
Reading symbols from /usr/X11R6/lib/libXrender.so.1...done.
Loaded symbols for /usr/X11R6/lib/libXrender.so.1
Reading symbols from /usr/X11R6/lib/libX11.so.6...done.
Loaded symbols for /usr/X11R6/lib/libX11.so.6
Reading symbols from /usr/X11R6/lib/libXext.so.6...done.
Loaded symbols for /usr/X11R6/lib/libXext.so.6
Reading symbols from /usr/lib/libpng12.so.0...done.
Loaded symbols for /usr/lib/libpng12.so.0
Reading symbols from /usr/lib/libpangoft2-1.0.so.0...done.
Loaded symbols for /usr/lib/libpangoft2-1.0.so.0
Reading symbols from /usr/lib/libpango-1.0.so.0...done.
Loaded symbols for /usr/lib/libpango-1.0.so.0
Reading symbols from /usr/lib/libgobject-2.0.so.0...done.
Loaded symbols for /usr/lib/libgobject-2.0.so.0
Reading symbols from /usr/lib/libgmodule-2.0.so.0...done.
Loaded symbols for /usr/lib/libgmodule-2.0.so.0
Reading symbols from /usr/lib/libglib-2.0.so.0...done.
Loaded symbols for /usr/lib/libglib-2.0.so.0
Reading symbols from /usr/X11R6/lib/libXtst.so.6...done.
Loaded symbols for /usr/X11R6/lib/libXtst.so.6
Reading symbols from /usr/X11R6/lib/libXrandr.so.2...done.
Loaded symbols for /usr/X11R6/lib/libXrandr.so.2
Reading symbols from /usr/X11R6/lib/libXi.so.6...done.
Loaded symbols for /usr/X11R6/lib/libXi.so.6
Reading symbols from /usr/X11R6/lib/libXinerama.so.1...done.
Loaded symbols for /usr/X11R6/lib/libXinerama.so.1
Reading symbols from /usr/X11R6/lib/libXft.so.2...done.
Loaded symbols for /usr/X11R6/lib/libXft.so.2
Reading symbols from /usr/X11R6/lib/libXcursor.so.1...done.
Loaded symbols for /usr/X11R6/lib/libXcursor.so.1
Reading symbols from /usr/lib/libexpat.so.0...done.
Loaded symbols for /usr/lib/libexpat.so.0
Reading symbols from /usr/X11R6/lib/X11/locale/lib/common/xlcDef.so.2...done.
Loaded symbols for /usr/X11R6/lib/X11/locale/lib/common/xlcDef.so.2
Reading symbols from /lib/libnss_files.so.2...done.
Loaded symbols for /lib/libnss_files.so.2
Reading symbols from /usr/lib/gconv/ISO8859-1.so...done.
Loaded symbols for /usr/lib/gconv/ISO8859-1.so
Reading symbols from /usr/lib/gtk-2.0/2.4.0/engines/libbluecurve.so...done.
Loaded symbols for /usr/lib/gtk-2.0/2.4.0/engines/libbluecurve.so
Reading symbols from /home/lindi/cp/2005-07-14T110617+0000/lib/classpath/libjavalangreflect.so...done.
Loaded symbols for /home/lindi/cp/2005-07-14T110617+0000/lib/classpath//libjavalangreflect.so
Reading symbols from /usr/lib/pango/1.4.0/modules/pango-basic-fc.so...done.
Loaded symbols for /usr/lib/pango/1.4.0/modules/pango-basic-fc.so
#0  0x0012a7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
(gdb) bt
#0  0x0012a7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0x0016b7d5 in raise () from /lib/tls/libc.so.6
#2  0x0016d149 in abort () from /lib/tls/libc.so.6
#3  0x0019f27a in __libc_message () from /lib/tls/libc.so.6
#4  0x001a5abf in _int_free () from /lib/tls/libc.so.6
#5  0x001a5e3a in free () from /lib/tls/libc.so.6
#6  0x00de7e2a in Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics (env=0x805e974, java_font=0xb01c70e8, str=0xb0202e68, java_metrics=0xb0202eb0)
    at gnu_java_awt_peer_gtk_GdkFontPeer.c:302
#7  0x0805a891 in callJNIMethod (env=0x805e974, class=0x0, sig=0x958b5f8 "(Ljava/lang/String;[D)V", ret_type=3318, ostack=0x940c49c, f=0xde7da0 "U211åWVS203ì,è",
    args=3) at dll_md.c:64
#8  0x0804dbc5 in callJNIWrapper (class=0xb00947a8, mb=0x958d32c, ostack=0x940c49c) at dll.c:330
#9  0x080511ef in executeJava () at interp.c:2240
#10 0x0804e6c0 in executeMethodVaList (ob=0x0, class=0xb008de10, mb=0x94cbb50, jargs=0xbff9d160 "") at execute.c:68
#11 0x0804e740 in executeMethodArgs (ob=0x0, class=0xb008de10, mb=0x94cbb50) at execute.c:39
#12 0x080520fb in main (argc=6, argv=0xbff9d214) at jam.c:327

Feel free to ask for more info if you can't reproduce this.
Comment 1 Tom Tromey 2005-08-19 18:31:50 UTC
FWIW this also fails with cvs head gij. (Though I don't see the 'free' problem)

You can work around this by by starting the loop at 1 instead of 0.

The problem here is that Java "utf-8" has a special representation for \0.
It represents this as a 2-byte sequence instead of as the 1-byte \0 sequence.
This is done to make it possible to manipulate Java strings containing \0
in C; otherwise the \0 byte would terminate the C string.

I can think of two possible fixes.

The first idea is to change our Gtk peers to work around this.
For instance we could replace the 2-byte sequence in C strings with some
substitution character (not sure what though).  Or, we could implement
our own utf16 -> utf8 conversion (which may be slightly more efficient).
This would ensure that we don't send Pango something that it does not understand.

The second idea would be to change Pango to understand the java convention.
This is not completely unreasonable IMO as (1) the java convention is in
fairly wide use, and (2) the java convention is obviously useful.
Comment 2 Francis Kung 2007-03-30 19:11:31 UTC
closing this, as the font stuff has been completely reworked since this bug was filed