[#1060] Fix bug in CompositeByteBuf which let the buffer expand in a incorrect way and so result in corrupted data

This commit is contained in:
Norman Maurer 2013-02-19 09:43:31 +01:00
parent 891cf343ca
commit 4ed5b07e4e
2 changed files with 13 additions and 1 deletions

View File

@ -451,7 +451,7 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf
if (nComponents < maxNumComponents) {
padding = allocBuffer(paddingLength);
padding.setIndex(0, paddingLength);
addComponent0(0, padding);
addComponent0(components.size(), padding);
} else {
padding = allocBuffer(paddingLength);
padding.setIndex(0, paddingLength);

View File

@ -418,4 +418,16 @@ public abstract class AbstractCompositeByteBufTest extends
b.readBytes(new byte[4]);
b.readBytes(new byte[0]);
}
// Test for https://github.com/netty/netty/issues/1060
@Test
public void testReadWithEmptyCompositeBuffer() {
ByteBuf buf = compositeBuffer();
int n = 65;
for (int i=0; i<n; ++i) {
buf.writeByte(1);
assertEquals(1, buf.readByte());
}
}
}