Repository navigation
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughPyMySQL now supports MySQL protocol compression with zlib and optional zstd. The connection negotiates compression during authentication and uses compressed framing for later traffic. The change adds codec and connection tests, an optional zstd dependency, and installation and changelog documentation. ChangesMySQL protocol compression
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant Connection
participant MySQLServer
participant CompressedStream
Connection->>MySQLServer: Negotiate zlib or zstd capability
Connection->>MySQLServer: Complete authentication with normal framing
Connection->>CompressedStream: Create stream after authentication
Connection->>CompressedStream: Pass subsequent writes for framing
CompressedStream->>MySQLServer: Send compressed protocol frames
MySQLServer->>CompressedStream: Return compressed protocol frames
CompressedStream->>Connection: Provide decoded packet bytes
Merge Risk: ⚪ Minimal · up to No concrete merge-blocking issue was identified. Compression support appears ready to merge subject to normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Compression preserves the inspected authentication and TLS ordering and rejects malformed streams with bounded output. The main remaining concern is connection reuse after an unexpected interruption during compressed decoding. Exposure is limited to connections using compression; no credential bypass or broader privilege gain was established. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
||
|
|
||
| def _pack_int24(value): | ||
| return struct.pack("<I", value)[:3] |
There was a problem hiding this comment.
value.to_bytes(3, "little") の方が速いしoverflow errorになって安全だからそっちにして。
| header = ( | ||
| _pack_int24(len(payload)) | ||
| + bytes([self.sequence]) | ||
| + _pack_int24(original_length) | ||
| ) | ||
| write_bytes(header + payload) |
There was a problem hiding this comment.
header の一時オブジェクトが無駄だから一気に header + payload まで全部作って write_bytes して。
PyMySQL currently rejects
compress=True. This change enables MySQL protocol compression with zlib and zstd, including zstd on Python 3.9–3.13 through the optionalPyMySQL[zstd]extra.compress=Trueprefers zstd when available and supported by the server, then falls back to zlib or an uncompressed connection.compress="zlib"andcompress="zstd"require the selected algorithm. Outgoing payloads below 400 bytes, or those that do not shrink, remain uncompressed within the compressed protocol.The framing follows the MySQL protocol and the approach used by go-sql-driver/mysql: compression starts after authentication, supports packets split across frames and sequence wraparound, and handles large requests and responses. Decompression is bounded by the declared length and rejects corrupt or incomplete streams. Python 3.14+ uses
compression.zstd; earlier versions usebackports.zstd>=1.3.0, installed only whenpython_version < "3.14". CI installs the extra, and the README and changelog document the API.Compressed-frame lengths use
int.to_bytes(3, "little")so overflow is rejected, and the complete header and payload are assembled in one join. Decoder contexts remain independent per frame: the supported stateful decoder APIs stop at EOF and provide no reset operation. Sharing one global decoder would therefore fail on later frames even if calls were serialized. The standard-library one-shot zstd helper also constructs a new decoder internally and does not provide the bounded-output check used here. The code documents this constraint and the concurrent-stream tests verify isolation.Validation:
git diff --checkpassed.Summary by CodeRabbit