-
Notifications
You must be signed in to change notification settings - Fork 139
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
der: request to increase MAX_LENGTH for DER Length #1613
Comments
It's a sanity limit to prevent DoS attacks using extremely large documents. Perhaps it could apply only to DER documents instead of BER documents. Or we could add an "unchecked" API which doesn't have a limit. |
This is something that I find useful as well for my Image4 format parser (https://gitlab.com/turbocooler/image4-rs). These files can be larger than 256 MiB. |
After thinking about this more I wonder if this limit is something that would help to protect crate users against DoS attacks. In my experience at least DoS attacks happen due to a large number of objects rather than the size of the input buffer, and you can fit a lot of DER-ecnoded objects into a 256 MiB buffer. I can see how these 256 MiB will turn into tens of gigabytes of RAM with a creatively constructed X.509 certificate. I think the size limit should be defined by the application and not the library or at least not by the Removing this limit (an hopefully making |
The main concern driving the limitation is trying to cap the amount of memory that can be allocated by parsing an input message. The number of objects is less of a concern.
|
I understand these concerns so I took some time to make a certificate that is a bit smaller than 256 MiB to demonstrate the effects of what I mean. The small test program consumes 2,5-3 GiB of memory while parsing this certificate. It could be optimized to account for vector allocation specifics and have more OIDs inside to increase memory usage. Code: https://gist.github.com/turbocool3r/0b93b46ab57d66e71ff25c1deb4129a2. ![]() |
I am running into an
Overflow
error when parsing CMS messages with content larger than 256MiB in DER format. OpenSSL produces and parses messages of this size without problems, and for my application it's crucial to handle files larger than this limit.The value of
MAX_LENGTH
that results in this overflow is specified here:formats/der/src/length.rs
Lines 10 to 11 in 057aa1f
Some years ago this commit bumped the max size from 1MiB to 256MiB. Mentioning that it would be possible to bump this value again if needed in the future. Since the value is parsed from up to 4 octets I don't see an obvious reason to limit this to less than 4GiB.
Would it be possible to increase this value to at least 1 GiB?
The text was updated successfully, but these errors were encountered: