-
Notifications
You must be signed in to change notification settings - Fork 60
cython_lz4: validate declared frame size against INT32_MAX, not 256 MiB #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,11 +52,14 @@ cdef extern from *: | |
| uint32_t ntohl(uint32_t netlong) nogil | ||
|
|
||
| # CQL native protocol v4 frames have a 32-bit body length, so the | ||
| # theoretical maximum is ~2 GiB. We use 256 MiB as a practical upper | ||
| # bound (matching the server's default frame size limit) to avoid | ||
| # accidentally allocating multi-GiB buffers on corrupt headers. | ||
| # theoretical maximum uncompressed size is INT32_MAX (~2 GiB). The | ||
| # previous 256 MiB cap was the server's *default* frame-size limit, not | ||
| # the protocol/LZ4 API limit, so it rejected valid frames on clusters | ||
| # configured with larger frames (see issue #1000). We validate against | ||
| # INT32_MAX so legitimate oversized frames still decompress while | ||
| # negative or >2 GiB values from corrupt headers are still rejected. | ||
| cdef enum: | ||
| MAX_DECOMPRESSED_LENGTH = 268435456 # 256 MiB | ||
| MAX_DECOMPRESSED_LENGTH = INT32_MAX # ~2 GiB | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🤖 get_repo_knowledge executed:
Length of output: 18454 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- target outline ---'
ast-grep outline cassandra/cython_lz4.pyx
printf '%s\n' '--- target implementation ---'
sed -n '1,180p' cassandra/cython_lz4.pyx
printf '%s\n' '--- direct symbols and callers ---'
rg -n -C 3 'lz4_decompress|MAX_DECOMPRESSED_LENGTH|INT32_MAX' cassandra testsRepository: scylladb/python-driver Length of output: 26767 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- decompression body ---'
sed -n '180,225p' cassandra/cython_lz4.pyx
printf '%s\n' '--- frame-size configuration and decompression dispatch ---'
rg -n -C 3 'frame_size|max_frame|body_length|decompressor|segment_codec|decode.*frame|read.*frame' cassandra tests/unit/cython/test_cython_lz4.pyRepository: scylladb/python-driver Length of output: 13969 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- frame header parsing and body buffering ---'
sed -n '1370,1460p' cassandra/connection.py
printf '%s\n' '--- frame/header length definitions ---'
sed -n '1,170p' cassandra/protocol.py
sed -n '80,155p' cassandra/segment.pyRepository: scylladb/python-driver Length of output: 12515 Denial of Service Reachability: External Restore a configured allocation limit before output allocation. The decompressor handles received response bodies and allocates the declared size before Reject declarations above the negotiated or configured frame-size limit before 🤖 Prompt for AI Agents |
||
|
|
||
| # LZ4_MAX_INPUT_SIZE from lz4.h — the LZ4 C API uses C int (32-bit | ||
| # signed) for sizes, so we must reject Python bytes objects that | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Small frames can exhaust client memory
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools