-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fix out-of-memory errors with mdat boxes and remove size-based checks #152
Conversation
Thank you for PR! I have only one question about this change. |
22a1d29
to
2c7a537
Compare
i edited the patch and merged the comment, thanks |
Sorry, I didn't make it clear enough. |
If that's the case, i would discard the idea of imposing a fixed cap on the array size, since it limits the use cases of this library without solving the issue, that is preventing specially-crafted strings to crash applications. It's also impossible to know in advance the overall bit size of a field and use it to check whether there are enough bits, since some fields have a dynamic length that depends on some other fields, and it would require decoding the struct. In my opinion the only way to solve the issue consists in replacing the static preallocation of the slice with a dynamic allocation, replacing the |
I've edited the patch in order to remove the slice preallocation. Adding appends() was not necessary since they are already there. |
While patch abema#150 is able to prevent RAM exhaustion with the majority of small, specially-crafted strings, it isn'effective against strings that contain mdat boxes. A short string is able to cause RAM exhaustion by setting the mdat box size to a big number. This PR fixes the issue by replacing size-based checks with checks on the effective size of the underlying buffer, that are performed by using Seek(). In this way, an attacker may cause DoS errors if and only if he is able to upload an amount of data equal to the size of the RAM of the machine, and if there are no size checks before passing the buffer to ReadBoxStructure() or Unmarshal(). Size-based checks are performed only in case of non-uint8 slices, since it's not possible to know in advance the overall size of a generic slice.
@sunfish-shogi
While patch #150 is able to prevent RAM exhaustion with the majority of small, specially-crafted strings, it isn'effective against strings that contain mdat boxes. A short string is able to cause RAM exhaustion by setting the mdat box size to a big number.
This PR fixes the issue by replacing size-based checks with checks on the effective size of the underlying buffer, that are performed by using Seek(). In this way, an attacker may cause DoS errors if and only if he is able to upload an amount of data equal to the size of the RAM of the machine, and if there are no size checks before passing the buffer to ReadBoxStructure() or Unmarshal().
Size-based checks are performed only in case of non-uint8 slices, since it's not possible to know in advance the overall size of a generic slice.