mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niklas Gustavsson <nik...@protocol7.com>
Subject MINA 2.0.5 backwards compatibility issue
Date Mon, 17 Sep 2012 12:21:58 GMT
Hey

When upgrading to MINA 2.0.5 in FtpServer, I noticed one of the
FtpServer unit tests breaking. Turns out it's due to a change
(r1374997) in MINA 2.0.5 TextLineDecoder which no longer will throw an
exception on some input which is not valid for the charset. For
example, this test will throw an exception on MINA 2.0.4, but will
pass and output a broken String on 2.0.5.

    public void testMina205() throws Exception {
        IoBuffer buffer =
IoBuffer.wrap(Hex.decodeHex("ae2e0d0a".toCharArray()));
        IoSession session = new DummySession();
        ProtocolDecoderOutput out = new AbstractProtocolDecoderOutput(){
            public void flush(NextFilter nextFilter, IoSession session) {
            }};

        TextLineDecoder tld = new TextLineDecoder(Charset.forName("UTF-8"));
            tld.decode(session, buffer, out);
    }

Here's the diff of the change which causes this:
-                        writeText(session,
buf.getString(ctx.getDecoder()), out);
+                        byte[] data = new byte[buf.limit()];
+                        buf.get(data);
+                        writeText(session, new String(data,
ctx.getDecoder().charset()), out);

I guess new String() is more lax than CharsetDecoder.decode()

I don't think the exact behavior of TextLineDecoder in this case is
specified, but outputting broken strings seems like a bad thing to me.
In the case of FtpServer, this might lead to files being created with
invalid file names, rather then requests being caught as broken (the
string in the above test is from a unit test in FtpServer that comes
from a real request that ones broke FtpServer :)

Should this be fixed?

/niklas

Mime
View raw message