Skip to content

Commit 6b78a0d

Browse files
ffacsdongjoon-hyun
authored andcommitted
ORC-1879: [C++] Fix Heap Buffer Overflow in LZO Decompression
### What changes were proposed in this pull request? Fix Heap Buffer Overflow Vulnerability in LZO Decompression ### Why are the changes needed? This vulnerability has several security implications ### How was this patch tested? UT passed ### Was this patch authored or co-authored using generative AI tooling? NO Closes #2191 from ffacs/main. Authored-by: ffacs <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 529f0ba commit 6b78a0d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

c++/src/LzoDecompressor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ namespace orc {
342342
char* literalOutputLimit = output + literalLength;
343343
if (literalOutputLimit > fastOutputLimit ||
344344
input + literalLength > inputLimit - SIZE_OF_LONG) {
345-
if (literalOutputLimit > outputLimit) {
345+
if (literalOutputLimit > outputLimit || input + literalLength > inputLimit) {
346346
throw MalformedInputException(input - inputAddress);
347347
}
348348

c++/test/TestDecompression.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,26 @@ namespace orc {
395395
ASSERT_TRUE(!result->Next(&ptr, &length));
396396
}
397397

398+
TEST_F(TestDecompression, testLzoOverflow) {
399+
const unsigned char bad_lzo_data[] = {// Header: compressedSize = 12, original = false
400+
0x18, 0x00, 0x00,
401+
402+
// LZO body: token and literal length extension
403+
0x00, // token: extended literal length
404+
0xFF, // extension byte 1
405+
406+
// Literal data: only 10 bytes far less than 273
407+
'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'};
408+
409+
std::unique_ptr<SeekableInputStream> result = createDecompressor(
410+
CompressionKind_LZO,
411+
std::make_unique<SeekableArrayInputStream>(bad_lzo_data, ARRAY_SIZE(bad_lzo_data)),
412+
128 * 1024, *getDefaultPool(), getDefaultReaderMetrics());
413+
const void* ptr;
414+
int length;
415+
EXPECT_THROW(result->Next(&ptr, &length), ParseError);
416+
}
417+
398418
TEST_F(TestDecompression, testLz4Empty) {
399419
const unsigned char buffer[] = {0};
400420
std::unique_ptr<SeekableInputStream> result = createDecompressor(

0 commit comments

Comments
 (0)