Bug 54628

Summary: there is something wrong when send binary data by websocket.
Product: Tomcat 7 Reporter: blee <b.lee>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: major CC: b.lee
Priority: P2    
Version: 7.0.37   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description blee 2013-03-02 08:37:25 UTC
there is something wrong when send binary data by websocket.

see org.apache.catalina.websocket.WsOutbound.doWriteBytes(ByteBuffer, boolean)

I think 

// Write the content
        upgradeOutbound.write(buffer.array(), 0, buffer.limit());
        upgradeOutbound.flush();

should change to :

// Write the content
        upgradeOutbound.write(buffer.array(), buffer.arrayOffset(), buffer.limit());
        upgradeOutbound.flush();


For example:
byte[] bts = new byte[]{1,2,3,4,5}
ByteBuffer bf = ByteBuffer.wrap(bts, 2, 2);
out.writeBinaryMessage(bf);

I mean write [3,4] to the client, but in fact [1,2,3,4] be sent;
Comment 1 Mark Thomas 2013-03-06 20:55:17 UTC
Thanks for the report and for the fix.

This has been fixed in trunk and 7.0.x and will be included in 7.0.38 onwards.