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 — FastLz: Guard decompression against truncated input (#17000) · netty/netty@775ad71

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-compression/src
    • main/java/io/netty/handler/codec/compression
      • FastLz.java
    • test/java/io/netty/handler/codec/compression
      • FastLzFrameDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java‎

Copy file name to clipboardExpand all lines: codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ static int compress(final ByteBuf input, final int inOffset, final int inLength,
408408
*/
409409
static int decompress(final ByteBuf input, final int inOffset, final int inLength,
410410
final ByteBuf output, final int outOffset, final int outLength) {
411+
if (inLength == 0) {
412+
return 0;
413+
}
414+
411415
//int level = ((*(const flzuint8*)input) >> 5) + 1;
412416
final int level = (input.getByte(inOffset) >> 5) + 1;
413417
if (level != LEVEL_1 && level != LEVEL_2) {
@@ -440,26 +444,41 @@ static int decompress(final ByteBuf input, final int inOffset, final int inLengt
440444
int code;
441445
if (len == 6) {
442446
if (level == LEVEL_1) {
447+
if (ip >= inLength) {
448+
return 0;
449+
}
443450
// len += *ip++;
444451
len += input.getUnsignedByte(inOffset + ip++);
445452
} else {
446453
do {
454+
if (ip >= inLength) {
455+
return 0;
456+
}
447457
code = input.getUnsignedByte(inOffset + ip++);
448458
len += code;
449459
} while (code == 255);
450460
}
451461
}
452462
if (level == LEVEL_1) {
463+
if (ip >= inLength) {
464+
return 0;
465+
}
453466
// ref -= *ip++;
454467
ref -= input.getUnsignedByte(inOffset + ip++);
455468
} else {
469+
if (ip >= inLength) {
470+
return 0;
471+
}
456472
code = input.getUnsignedByte(inOffset + ip++);
457473
ref -= code;
458474

459475
/* match from 16-bit distance */
460476
// if(FASTLZ_UNEXPECT_CONDITIONAL(code==255))
461477
// if(FASTLZ_EXPECT_CONDITIONAL(ofs==(31 << 8)))
462478
if (code == 255 && ofs == 31 << 8) {
479+
if (ip + 2 > inLength) {
480+
return 0;
481+
}
463482
ofs = input.getUnsignedByte(inOffset + ip++) << 8;
464483
ofs += input.getUnsignedByte(inOffset + ip++);
465484

Collapse file

‎codec-compression/src/test/java/io/netty/handler/codec/compression/FastLzFrameDecoderTest.java‎

Copy file name to clipboard
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.handler.codec.compression;
17+
18+
import io.netty.buffer.Unpooled;
19+
import io.netty.channel.embedded.EmbeddedChannel;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
24+
public class FastLzFrameDecoderTest {
25+
26+
@Test
27+
public void testCompressedBlockWithEmptyPayload() {
28+
assertDecompressionException(new byte[] {
29+
'F', 'L', 'Z',
30+
0x01,
31+
0x00, 0x00,
32+
0x00, 0x01
33+
});
34+
}
35+
36+
@Test
37+
public void testCompressedBlockWithTruncatedMatch() {
38+
assertDecompressionException(new byte[] {
39+
'F', 'L', 'Z',
40+
0x01,
41+
0x00, 0x03,
42+
0x00, 0x04,
43+
0x00, 'A', 0x20
44+
});
45+
}
46+
47+
private static void assertDecompressionException(byte[] input) {
48+
EmbeddedChannel channel = new EmbeddedChannel(new FastLzFrameDecoder());
49+
try {
50+
assertThrows(DecompressionException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(input)));
51+
} finally {
52+
channel.finishAndReleaseAll();
53+
}
54+
}
55+
}

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.