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
proposal: zstd: add DecodedSize function #647
Comments
I would say that unless you have a huge amount of blocks you want to discard, you are much better off just decoding. Reconstructing the sequences are about 50% of the workload. For streams the decoding is split, so sequences are reconstructed separately from executing the sequences, so this is a pretty representative time. For blocks the operations are performed at the same time, since a few blocks will not gain much benefit from this split and single blocks will be much slower. So in overall terms, it seems you might as well decompress them. |
Thanks for the thoughts. I trust your judgement on the cost of this functionality. Unless I'm missing something, a challenge I'm facing is that there's no efficient way to change the For example, an untrusted client claims a message decompresses to N number of bytes, and so I account for N number of bytes in the rate-limiter. I then decompress the message and discover that it has actually decompressed to something much larger than N, thus bypassing the rate-limiter. In this situation N changes for every message, while the |
@dsnet Correct, the max size is set per Decoder. It is mainly there for DOS protection, not as a validation. While it could be a solution, instead of adding more API, instead we could add a How does that sound? |
Technically, rate-limiting exists as a form of DOS protection 😏 . I just happen to be implementing it at a finer granularity than what the API appears to have been designed for.
That would work for my use-case. You could also call it |
Not DDOS, but DOS by "zip bombing" and causing OOM.
While that would likely be a side-effect, I don't want to promise that. |
WithDecodeAllCapLimit will limit DecodeAll to decoding cap(dst)-len(dst) bytes, or any size set in WithDecoderMaxMemory. This can be used to limit decoding to a specific maximum output size. Disabled by default. Fixes #647
* zstd: Add DecodeAllCapLimit WithDecodeAllCapLimit will limit DecodeAll to decoding cap(dst)-len(dst) bytes, or any size set in WithDecoderMaxMemory. This can be used to limit decoding to a specific maximum output size. Disabled by default. Fixes #647
I'm trying to implement proper rate-limiting and I'm finding it difficult to adequately rate-limit a server when dealing with untrusted
[]byte
inputs since I don't know how large the decompressed output will end up. I could convert the[]byte
into aio.Reader
and perform rate limiting based on the number of bytes read fromzstd.Decoder
, but that seems somewhat unfortunate.I propose the addition of:
It may or may not make sense as a method on
Decoder
.IIUC, this should only need to perform work proportional to O(len(src)). The amount of memory it will occupy is primarily what's needed to initialize the ANS tables and to read each symbol. We would then count each literal symbol and the length of each LZ77 back-reference symbol.
This API also assists in determining what sized buffers to grab for the output.
The text was updated successfully, but these errors were encountered: