GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Handle non-positive skip lengths in ByteBufInputStream… · netty/netty@e49c7e3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • buffer/src
    • main/java/io/netty/buffer
      • ByteBufInputStream.java
    • test/java/io/netty/buffer
      • ByteBufStreamTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎buffer/src/main/java/io/netty/buffer/ByteBufInputStream.java‎

Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/ByteBufInputStream.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ public void reset() throws IOException {
192192

193193
@Override
194194
public long skip(long n) throws IOException {
195+
if (n <= 0) {
196+
return 0;
197+
}
195198
if (n > Integer.MAX_VALUE) {
196199
return skipBytes(Integer.MAX_VALUE);
197200
} else {
@@ -310,6 +313,9 @@ public int readUnsignedShort() throws IOException {
310313

311314
@Override
312315
public int skipBytes(int n) throws IOException {
316+
if (n <= 0) {
317+
return 0;
318+
}
313319
int nBytes = Math.min(available(), n);
314320
buffer.skipBytes(nBytes);
315321
return nBytes;
Collapse file

‎buffer/src/test/java/io/netty/buffer/ByteBufStreamTest.java‎

Copy file name to clipboardExpand all lines: buffer/src/test/java/io/netty/buffer/ByteBufStreamTest.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ public void testAll() throws Exception {
188188
buf.release();
189189
}
190190

191+
@Test
192+
public void testSkipNegativeLength() throws Exception {
193+
ByteBuf buf = Unpooled.buffer();
194+
buf.writeBytes(new byte[] { 1, 2, 3 });
195+
ByteBufInputStream in = new ByteBufInputStream(buf);
196+
try {
197+
assertEquals(0, in.skip(-1));
198+
assertEquals(0, in.skipBytes(-1));
199+
assertEquals(0, buf.readerIndex());
200+
} finally {
201+
buf.release();
202+
in.close();
203+
}
204+
}
205+
191206
@Test
192207
public void testReadLine() throws Exception {
193208
Charset utf8 = StandardCharsets.UTF_8;

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.