Skip to content

fix: use lzo1x_decompress_safe to prevent stack buffer overflow (CAN-2026-2035137) - #1245

Merged
lucaderi merged 1 commit into
ntop:devfrom
akoul:fix/lzo-safe-decompress
Aug 5, 2026
Merged

fix: use lzo1x_decompress_safe to prevent stack buffer overflow (CAN-2026-2035137)#1245
lucaderi merged 1 commit into
ntop:devfrom
akoul:fix/lzo-safe-decompress

Conversation

@akoul

@akoul akoul commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace lzo1x_decompress() with lzo1x_decompress_safe() in transop_decode_lzo() to prevent a stack buffer overflow.

Problem

The unsafe lzo1x_decompress() does not enforce an output buffer size limit. A crafted LZO-compressed payload that decompresses to more than N2N_PKT_BUF_SIZE (2048) bytes overflows the stack buffer deflate_buf in handle_PACKET() (edge_utils.c:1718).

The post-decompression size check (if(deflated_len > N2N_PKT_BUF_SIZE)) was ineffective because the overflow already occurred during decompression.

Fix

Use lzo1x_decompress_safe() which validates output bounds during decompression. This function is already bundled in src/minilzo.c but was not being used.

Reference

CAN-2026-2035137

Replace lzo1x_decompress() with lzo1x_decompress_safe() in
transop_decode_lzo(). The unsafe variant does not enforce the output
buffer size limit, allowing a crafted compressed payload to overflow
the N2N_PKT_BUF_SIZE (2048 byte) stack buffer in handle_PACKET().

The safe variant (already bundled in src/minilzo.c) validates output
bounds during decompression, preventing the overflow.

The post-decompression size check was ineffective because the overflow
had already occurred before the check executed.

CAN-2026-2035137
@lucaderi
lucaderi merged commit 4831375 into ntop:dev Aug 5, 2026
8 of 19 checks passed
hamishcoleman added a commit to hamishcoleman/n3n that referenced this pull request Aug 7, 2026
This commit was based on the n2n commit 4831375d6ec7.  That commit was
proposed as ntop/n2n#1245

This change has a 1% performance regression due to the extra checks
added in the lzo1x_decompress_safe() compared to lzo1x_decompress()

(On my system, benchmark showed that using lzo1x_decompress was 166
cycles but lzo1x_decompress_safe is 172 cycles)

The n2n commit mentions some opaque "CAN" reference, but at the time of
committing, there is no matches anywhere on the internet for that
reference - suggesting that some or all of the n2n contribution was
hallucinated by an LLM.  Based on the original committer email address,
this reference could also be an Amazon internal reference, but the total
lack of clarity or referenceability makes that probably less useful than
a hallucination.

The actual source code for the vendored copy of the minilzo library has
been examined to confirm the expected changes in the two functions and
the test suite continues to pass after this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants