Skip to content

fix(streaming): reject oversized ZSTD frames instead of fatal() - #22830

Merged
stelfrag merged 3 commits into
netdata:masterfrom
stelfrag:fix-zstd-decompress-bomb-fatal
Jun 29, 2026
Merged

fix(streaming): reject oversized ZSTD frames instead of fatal()#22830
stelfrag merged 3 commits into
netdata:masterfrom
stelfrag:fix-zstd-decompress-bomb-fatal

Conversation

@stelfrag

@stelfrag stelfrag commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator
Summary
  • Add regression test for ZSTD decompression-bomb guard to verify grace…ful failure handling
  • Handle oversized ZSTD frames gracefully by logging an error and failing the connection instead of crashing.

Summary by cubic

Reject oversized ZSTD frames by logging and cleanly failing the stream instead of fatal()-ing the agent. Adds a regression test and improves ZSTD error handling.

  • Bug Fixes
    • In stream_decompress_zstd, if compressed bytes remain after filling the output buffer, log with netdata_log_error and return 0 to drop the connection.
    • Handle ZSTD compression/decompression errors by logging and returning failure instead of crashing.
    • Add unittest_stream_decompress_bomb_zstd() and wire it into unittest_stream_compressions() (behind ENABLE_ZSTD) to verify rejection and a normal-frame round trip; fix comment to reference COMPRESSION_MAX_MSG_SIZE.

Written for commit 25154f8. Summary will update on new commits.

Review in cubic

…ful failure handling

Handle oversized ZSTD frames gracefully by logging an error and failing the connection instead of crashing.
Comment thread src/streaming/stream-compression/zstd.c Fixed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Peer as Remote Peer (compressed data)
    participant Decomp as stream_decompress_zstd()
    participant Buffer as Output Buffer (COMPRESSION_MAX_CHUNK)
    participant Logger as netdata_log_error
    participant Conn as Stream Connection Manager
    participant Test as unittest_stream_decompress_bomb_zstd()
    participant ZSTD_Comp as ZSTD_compress()

    Note over Peer,Conn: Production Flow — ZSTD Frame Handling

    Peer->>Decomp: compressed data (may be bomb)
    Decomp->>Buffer: decompress into fixed-size buffer
    alt InBuffer still has leftover bytes after buffer full
        Decomp->>Decomp: detect oversized frame
        Note over Decomp,Logger: NEW: graceful handling instead of fatal()
        Decomp->>Logger: netdata_log_error("…failing the connection")
        Decomp-->>Conn: return 0 (error)
        Conn->>Conn: tear down connection / fail stream
    else No leftover (normal frame)
        Decomp-->>Conn: decompressed_size
        Conn->>Conn: continue streaming
    end

    Note over Test,Conn: Regression Test (unittest_stream_decompress_bomb_zstd())

    Test->>ZSTD_Comp: compress 2MB zeros -> bomb frame
    ZSTD_Comp-->>Test: compressed bomb (small)
    Test->>Decomp: stream_decompress(bomb)
    Decomp->>Buffer: decompress, buffer fills, data left
    Decomp->>Logger: netdata_log_error (graceful)
    Decomp-->>Test: return 0
    Test->>Test: assert return == 0 (no crash)

    Test->>ZSTD_Comp: compress "the quick brown fox..." -> normal frame
    ZSTD_Comp-->>Test: compressed normal
    Test->>Decomp: stream_decompress(normal)
    Decomp->>Buffer: decompress, fully consumed
    Decomp-->>Test: return original length
    Test->>Test: assert data matches original
Loading

Re-trigger cubic

@stelfrag
stelfrag marked this pull request as ready for review June 23, 2026 07:13
@stelfrag
stelfrag requested a review from thiagoftsm as a code owner June 23, 2026 07:13

@thiagoftsm thiagoftsm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replication and streaming are working as expected. LGTM!

@stelfrag
stelfrag merged commit 30f67b8 into netdata:master Jun 29, 2026
156 checks passed
@stelfrag
stelfrag deleted the fix-zstd-decompress-bomb-fatal branch June 29, 2026 06:05
@sonarqubecloud

Copy link
Copy Markdown

stelfrag added a commit to stelfrag/netdata that referenced this pull request Jul 12, 2026
…ata#22830)

* Add regression test for ZSTD decompression-bomb guard to verify graceful failure handling
Handle oversized ZSTD frames gracefully by logging an error and failing the connection instead of crashing.

* Fix comment to use correct constant name (COMPRESSION_MAX_MSG_SIZE) in ZSTD stream handling

* Handle ZSTD compression errors by logging and returning failure gracefully
@stelfrag stelfrag mentioned this pull request Jul 12, 2026
Ferroin pushed a commit that referenced this pull request Jul 15, 2026
* Add regression test for ZSTD decompression-bomb guard to verify graceful failure handling
Handle oversized ZSTD frames gracefully by logging an error and failing the connection instead of crashing.

* Fix comment to use correct constant name (COMPRESSION_MAX_MSG_SIZE) in ZSTD stream handling

* Handle ZSTD compression errors by logging and returning failure gracefully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants