You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/06/01 14:23:36 UTC

svn commit: r780632 - in /webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src: main/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilter.java test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java

Author: veithen
Date: Mon Jun  1 12:23:36 2009
New Revision: 780632

URL: http://svn.apache.org/viewvc?rev=780632&view=rev
Log:
Make sure that CharsetDecoderFilter throws an exception if there is malformed input. Otherwise it may enter into an endless loop.

Added:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java   (with props)
Modified:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilter.java

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilter.java?rev=780632&r1=780631&r2=780632&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilter.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilter.java Mon Jun  1 12:23:36 2009
@@ -48,6 +48,9 @@
             stream.skip(stream.read(inBuffer));
             inBuffer.flip();
             coderResult = decoder.decode(inBuffer, outBuffer, stream.isEndOfStream());
+            if (coderResult.isError()) {
+                throw new StreamException("Character set encoding error");
+            }
             outBuffer.flip();
             try {
                 writer.write(outBuffer.array(), outBuffer.position(), outBuffer.remaining());

Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java?rev=780632&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java Mon Jun  1 12:23:36 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon.core.filter;
+
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+public class CharsetDecoderFilterTest extends TestCase {
+    public void testMalformed() {
+        try {
+            TestUtil.filter(new CharsetDecoderFilter(new StringWriter(), "UTF-8"),
+                            new byte[] { (byte)255, 0 });
+            fail("Expected exception");
+        } catch (StreamException ex) {
+            // OK
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native