Eager allocation of byte buffer can cause `java.lang.OutOfMemoryError` exception (CVE-2020-28491)
See original GitHub issueCBORParser.java _finishBytes() accepts an unchecked field string length value discovered during parsing, and is used to allocated a buffer. A malicious payload can be fabricated to exploit this and (at least) cause a java.lang.OutOfMemoryError exception.
@SuppressWarnings("resource")
protected byte[] _finishBytes(int len) throws IOException
{
// First, simple: non-chunked
if (len >= 0) {
if (len == 0) {
return NO_BYTES;
}
byte[] b = new byte[len]; <-- OutOfMemoryError here if len is large
I am not sure how serious this is in java. With an unmanaged runtime this would be critical security vulnerability.
For example, the following CBOR data (discovered by a fuzzer) leads to len = 2147483647 and triggers this exception on my laptop.
d9d9f7a35a7ffffffff7d9f7f759f7f7f7
This can probably be addressed by simple sanity checking of the len value (non-negative, some max limit).
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
CVE-2020-28491
Unchecked allocation of byte buffer can cause a java.lang.OutOfMemoryError exception. CVE-2020-28491 has been assigned by URL Logo ...
Read more >Bountysource
Eager allocation of byte buffer can cause `java.lang.OutOfMemoryError` exception (CVE-2020-28491)
Read more >How to Fix java.lang.OufOfMemoryError: Direct Buffer Memory
Since they are garbage collected using a phantom reference and a reference queue, you can still hold the memory allocated to the direct...
Read more >CVE-2020-28491 - Vulners
Unchecked allocation of byte buffer can cause a java.lang.OutOfMemoryError exception.\n", "published": "2021-06-18T10:50:29", ...
Read more >Direct Buffer Memory (Doc ID 1465171.1) - My Oracle Support
lang.OutOfMemoryError: Direct buffer memory error. Changes. Coherence does use byte buffers. In this case coherence member was Out Of JVM Heap Space ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What I mean is that with this problem, an attacker can use a very small payload to cause this big allocation, possibly causing denial of service with little effort. If the buffer were to grow incrementally while reading, the attacker would need to follow up the length header they sent with actual data to make an impact on memory consumption.
Another possibility would be not pre-allocating the buffer for large sizes and instead using a ByteArrayOutputStream-like growing scheme. It’s slightly less efficient if the full data does come in, but an attacker would have to actually send the data she is claiming to cause a DoS, which makes an attack more difficult.