From 5caaa2a92b59e6076987cf229216e9bc1339f8b9 Mon Sep 17 00:00:00 2001 From: Niklas Therning Date: Tue, 7 Jun 2005 11:36:37 +0000 Subject: [PATCH] =?utf8?q?Fixed=20bug=20causing=20OutOfMemoryError=20when?= =?utf8?q?=20decoding=20strings=20which=20contain=20=3D=3F=20but=20are=20n?= =?utf8?q?ot=20encoded=20words.?= git-svn-id: https://svn.eu.apache.org/repos/asf/james/mime4j/trunk@188748 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/mime4j/decoder/DecoderUtil.java | 16 ++++++++-------- src/test/org/mime4j/decoder/DecoderUtilTest.java | 9 +++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/java/org/mime4j/decoder/DecoderUtil.java b/src/java/org/mime4j/decoder/DecoderUtil.java index 6c1dc1c..f585f11 100644 --- a/src/java/org/mime4j/decoder/DecoderUtil.java +++ b/src/java/org/mime4j/decoder/DecoderUtil.java @@ -193,7 +193,7 @@ public class DecoderUtil { */ p2 = t2 != -1 ? body.indexOf("?=", t2 + 1) : -1; if (p2 == -1) { - if (body.charAt(t2 + 1) == '=') { + if (t2 != -1 && body.charAt(t2 + 1) == '=') { /* * The text "=?charset?enc?=" appears to be valid for * empty strings. @@ -239,13 +239,13 @@ public class DecoderUtil { +"corresponding Java charset"); } } else if (!CharsetUtil.isDecodingSupported(charset)) { - decodedWord = body.substring(p1, p2 + 2); - if (log.isWarnEnabled()) { - log.warn("Current JDK doesn't support decoding " - + "of charset '" + charset - + "' (MIME charset '" - + mimeCharset + "')"); - } + decodedWord = body.substring(p1, p2 + 2); + if (log.isWarnEnabled()) { + log.warn("Current JDK doesn't support decoding " + + "of charset '" + charset + + "' (MIME charset '" + + mimeCharset + "')"); + } } else { if (enc.equalsIgnoreCase("Q")) { decodedWord = DecoderUtil.decodeQ(encodedWord, charset); diff --git a/src/test/org/mime4j/decoder/DecoderUtilTest.java b/src/test/org/mime4j/decoder/DecoderUtilTest.java index 10b5c5d..529758d 100644 --- a/src/test/org/mime4j/decoder/DecoderUtilTest.java +++ b/src/test/org/mime4j/decoder/DecoderUtilTest.java @@ -20,7 +20,6 @@ import java.io.UnsupportedEncodingException; import junit.framework.TestCase; import org.apache.log4j.BasicConfigurator; -import org.mime4j.util.CharsetUtil; /** * @@ -59,7 +58,7 @@ public class DecoderUtilTest extends TestCase { assertEquals("á â\tã ä ", s); } - public void testDecodeBody() { + public void testDecodeEncodedWords() { assertEquals("", DecoderUtil.decodeEncodedWords("")); assertEquals("Yada yada", DecoderUtil.decodeEncodedWords("Yada yada")); assertEquals(" áâã\tä", @@ -75,5 +74,11 @@ public class DecoderUtilTest extends TestCase { DecoderUtil.decodeEncodedWords("=?US-ASCII?b?QSBzaG9ydCB0ZXh0IGFnYWluIQ==?=")); assertEquals("", DecoderUtil.decodeEncodedWords("=?iso8859-1?Q?=")); assertEquals("", DecoderUtil.decodeEncodedWords("=?iso8859-1?b?=")); + + /* + * Bug detected on June 7, 2005. Decoding the following string caused + * OutOfMemoryError. + */ + assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!")); } } -- 2.11.4.GIT