From 32723ea0f97141dcc859af08906a52c7ddcc7278 Mon Sep 17 00:00:00 2001 From: David Daney Date: Wed, 21 May 2008 03:49:03 +0000 Subject: [PATCH] re PR libgcj/36252 (OutOfMemoryError on simple text conversion.) 2008-05-20 David Daney PR libgcj/36252 * java/lang/natString.ccn: Add #include . (init (byte[], int, int, String)): Catch and ignore CharConversionException. Break out of conversion loop on incomplete input. * testsuite/libjava.lang/PR36252.java: New test. * testsuite/libjava.lang/PR36252.out: New file, its expected output. * testsuite/libjava.lang/PR36252.jar: New file, its pre-compiled jar file. From-SVN: r135705 --- libjava/ChangeLog | 13 ++++++++++ libjava/java/lang/natString.cc | 25 ++++++++++++++++++-- libjava/testsuite/libjava.lang/PR36252.jar | Bin 0 -> 959 bytes libjava/testsuite/libjava.lang/PR36252.java | 16 +++++++++++++ libjava/testsuite/libjava.lang/PR36252.out | 1 + 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 libjava/testsuite/libjava.lang/PR36252.jar create mode 100644 libjava/testsuite/libjava.lang/PR36252.java create mode 100644 libjava/testsuite/libjava.lang/PR36252.out diff --git a/libjava/ChangeLog b/libjava/ChangeLog index c639181c878..e8cd46e8947 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,16 @@ +2008-05-20 David Daney + + PR libgcj/36252 + * java/lang/natString.ccn: Add + #include . + (init (byte[], int, int, String)): Catch and ignore + CharConversionException. Break out of conversion loop + on incomplete input. + * testsuite/libjava.lang/PR36252.java: New test. + * testsuite/libjava.lang/PR36252.out: New file, its expected output. + * testsuite/libjava.lang/PR36252.jar: New file, its pre-compiled + jar file. + 2008-04-19 Tom Tromey PR libgcj/35979: diff --git a/libjava/java/lang/natString.cc b/libjava/java/lang/natString.cc index f177c23ccc4..75006a7c9a7 100644 --- a/libjava/java/lang/natString.cc +++ b/libjava/java/lang/natString.cc @@ -1,6 +1,7 @@ // natString.cc - Implementation of java.lang.String native methods. -/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008 Free Software Foundation This file is part of libgcj. @@ -23,6 +24,7 @@ details. */ #include #include #include +#include #include #include #include @@ -493,9 +495,28 @@ java::lang::String::init (jbyteArray bytes, jint offset, jint count, converter->setInput(bytes, offset, offset+count); while (converter->inpos < converter->inlength) { - int done = converter->read(array, outpos, avail); + int done; + try + { + done = converter->read(array, outpos, avail); + } + catch (::java::io::CharConversionException *e) + { + // Ignore it and silently throw away the offending data. + break; + } if (done == 0) { + // done is zero if either there is no space available in the + // output *or* the input is incomplete. We assume that if + // there are 20 characters available in the output, the + // input must be incomplete and there is no more work to do. + // This means we may skip several bytes of input, but that + // is OK as the behavior is explicitly unspecified in this + // case. + if (avail - outpos > 20) + break; + jint new_size = 2 * (outpos + avail); jcharArray new_array = JvNewCharArray (new_size); memcpy (elements (new_array), elements (array), diff --git a/libjava/testsuite/libjava.lang/PR36252.jar b/libjava/testsuite/libjava.lang/PR36252.jar new file mode 100644 index 0000000000000000000000000000000000000000..2c0d2c0e906cc37b54003b03713c2e2f0e326c80 GIT binary patch literal 959 zcmWIWW@Zs#U|`^2INY(tLaE~6*V~K?3>TOf7#<;ucf22WgbEYq(xkwUC0=Y=NkOiW zmghousBTm~?)a4dhw!yjM^%S651D^(?PD}7>j_v|VVM4I=JA=5|Nne`YTdxTW4U9} z1-^Jwc~dzv6Ahkg8~>jxcdN4~iTl=HIl*AXZY7bE!fZF!l}k)nez8G%LZC@t!>J8V zx+d(O(fixx+n;|O##8QUd~lbw7kg=~KJ`iO3?q@dG3#8f+z?lEKKpLx|J2)_I)@Th z-@CY>CU0J)gL~`34}1RZxM`5Ea28)+a>T~!YIgSSTOx(5;ihZmy#HD^>%+#*>>Ym9 zuEtTDt@Onv7JE$Pyjom;=ThNh$F6%)J9@39!X&l0FZrxVoU3Q)xl(X#$X4@R;G7Q!>m*#5Pu;ZV{GlQ!SQ_xB!sGcW9SdIHIdd)?3Ciz3nBl(J;=y^B zs$}E+Z~ty#TfM+%$$S^NzuKFm_R2W9MclA!uA9}$yD7`{C(B5_u|Vrrfp!;dO%1$IG@I@-zE=cYgpdX>b9P z1_L;0fEiGN6PPr7T|*poJ^kGDu_g