mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-1101. java: bytebuffer length calculation in TBinaryProtocol writeBinary
This patch fixes a bug in Binary and Compact protocol that incorrectly calculates the length of the bytes to be written when the byte buffer being written has a nonzero array offset (such as after a slice() call). git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1083890 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d3fceb02d4
commit
177b52ab58
@ -191,7 +191,7 @@ public class TBinaryProtocol extends TProtocol {
|
||||
}
|
||||
|
||||
public void writeBinary(ByteBuffer bin) throws TException {
|
||||
int length = bin.limit() - bin.position() - bin.arrayOffset();
|
||||
int length = bin.limit() - bin.position();
|
||||
writeI32(length);
|
||||
trans_.write(bin.array(), bin.position() + bin.arrayOffset(), length);
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ public final class TCompactProtocol extends TProtocol {
|
||||
* Write a byte array, using a varint for the size.
|
||||
*/
|
||||
public void writeBinary(ByteBuffer bin) throws TException {
|
||||
int length = bin.limit() - bin.position() - bin.arrayOffset();
|
||||
int length = bin.limit() - bin.position();
|
||||
writeBinary(bin.array(), bin.position() + bin.arrayOffset(), length);
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,17 @@ public abstract class ProtocolTestBase extends TestCase {
|
||||
}
|
||||
internalTestBinaryField(b);
|
||||
}
|
||||
|
||||
if (canBeUsedNaked()) {
|
||||
byte[] data = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
TMemoryBuffer buf = new TMemoryBuffer(0);
|
||||
TProtocol proto = getFactory().getProtocol(buf);
|
||||
ByteBuffer bb = ByteBuffer.wrap(data);
|
||||
bb.get();
|
||||
proto.writeBinary(bb.slice());
|
||||
assertEquals(ByteBuffer.wrap(data, 1, 5), proto.readBinary());
|
||||
}
|
||||
}
|
||||
|
||||
public void testString() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user