Skip to content
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

Large zstd packets (those using multiple frames) fail to decompress #202

Open
CunningBaldrick opened this issue Oct 21, 2024 · 0 comments
Open

Comments

@CunningBaldrick
Copy link

The symptom:

.../site-packages/kafka/codec.py", line 315, in zstd_decode
return zstd.ZstdDecompressor().decompress(payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
zstd.ZstdError: could not determine content size in frame header

This issue is discussed here: mitmproxy/mitmproxy#6914

A fix inspired by that discussion that works for me:

--- a/kafka/codec.py
+++ b/kafka/codec.py
@@ -311,7 +311,4 @@ def zstd_encode(payload):
def zstd_decode(payload):
if not zstd:
raise NotImplementedError("Zstd codec is not available")

  • try:
  •    return zstd.ZstdDecompressor().decompress(payload)
    
  • except zstd.ZstdError:
  •    return zstd.ZstdDecompressor().decompress(payload, max_output_size=ZSTD_MAX_OUTPUT_SIZE)
    
  • return zstd.ZstdDecompressor().stream_reader(io.BytesIO(payload)).read()
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

No branches or pull requests

1 participant