mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guillaume Nodet (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SSHD-269) Random Data corruption with Remote Port Forwarding
Date Thu, 30 Jan 2014 00:28:10 GMT

    [ https://issues.apache.org/jira/browse/SSHD-269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13886076#comment-13886076
] 

Guillaume Nodet commented on SSHD-269:
--------------------------------------

I think I've been able to reproduce the test with the following method in PortForwardingLoadTest:
{code}
    @Test
    public void testLocalForwardingPayload() throws Exception {
        final int NUM_ITERATIONS = 100;
        final String PAYLOAD_TMP = "This is significantly longer Test Data. This is significantly
"+
                "longer Test Data. This is significantly longer Test Data. This is significantly
"+
                "longer Test Data. This is significantly longer Test Data. This is significantly
"+
                "longer Test Data. This is significantly longer Test Data. This is significantly
"+
                "longer Test Data. This is significantly longer Test Data. This is significantly
"+
                "longer Test Data. ";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 1000; i++) {
            sb.append(PAYLOAD_TMP);
        }
        final String PAYLOAD = sb.toString();
        Session session = createSession();
        final ServerSocket ss = new ServerSocket(0);
        int forwardedPort = ss.getLocalPort();
        int sinkPort = getFreePort();
        session.setPortForwardingL(sinkPort, "localhost", forwardedPort);
        final AtomicInteger conCount = new AtomicInteger(0);

        new Thread() {
            public void run() {
                try {
                    for (int i = 0; i < NUM_ITERATIONS; ++i) {
                        Socket s = ss.accept();
                        conCount.incrementAndGet();
                        InputStream is = s.getInputStream();
                        OutputStream os = s.getOutputStream();
                        byte[] buf = new byte[8192];
                        int l;
                        while ((l = is.read(buf)) > 0) {
                            os.write(buf, 0, l);
                        }
                        s.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        Thread.sleep(50);

        for ( int i = 0; i < NUM_ITERATIONS; i++) {
            Socket s = null;
            try {
                s = new Socket("localhost", sinkPort);
                s.getOutputStream().write(PAYLOAD.getBytes());
                s.getOutputStream().flush();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buf = new byte[8192];
                int l;
                while (baos.size() < PAYLOAD.length() && (l = s.getInputStream().read(buf))
> 0) {
                    baos.write(buf, 0, l);
                }
                assertEquals(PAYLOAD, baos.toString());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (s != null) {
                    s.close();
                }
            }
        }
        session.delPortForwardingL(sinkPort);
    }
{code}

I'll investigate ...

> Random Data corruption with Remote Port Forwarding
> --------------------------------------------------
>
>                 Key: SSHD-269
>                 URL: https://issues.apache.org/jira/browse/SSHD-269
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 0.9.0
>         Environment: WIN7 + JDK7, Centos+OpenJDK7
>            Reporter: Abhishek Ganguly
>            Assignee: Guillaume Nodet
>            Priority: Critical
>         Attachments: Module1.vb
>
>
> A TCP connection set up over Remote Port Forwarding feature randomly garbles the data.
On further testing I found that the TCP stream from remote-to-local is unaffected whereas
the local-to-remote is bad.
> To reproduce,
> 1. setup a basic sshd. listen on port 22. call the host 'remote'.
> 2. on 'local' machine set up putty (ssh client) as follows:
> 2.1 Host name: remote
> 2.2 Port: 22
> 2.3 Connection-SSH: Dont start a shell or command at all
> 2.4 Connection-SSH-tunnels:: source-port: remote-port, destination: localhost:localport
> 2.5 Connection type: Remote [Click ADD]
> 2.6 Open connection
> this makes a tunnel from remoteserver:remoteport to localhost:localport
> 3. set up a basic TCP server on localhost:localport
> 3.1 start serving predictable byte arrays. {0000111112222....}
> 4. set up a basic TCP client. connect to remoteHost:remotePort
> 4.1 the connection automatically gets forwarded to localhost:localport where my own TCP
server is running. hence a TCP connection is setup over the tunnel.
> 5. start consuming the byte array from server.
> 5.1 match the incoming bytes to expected sequence.
> you will see that the sequence is oftentimes garbled.
> 6. let the client send a similar predictable byte stream to server.
> 6.1 from client take OutputStream from the socket and push a long but predictable byte
array in it.
> 6.2 from server get InputStream out of socket and read the bytes
> you will see that irrespective of array length, all the bytes are safely delivered.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message