You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The readTensorInfoMap method in the SafeTensorSupport class uses Ints.checkedCast(headerLength) to validate the length when allocating a byte array. However, this validation is flawed, allowing maliciously crafted data to trigger a java.lang.OutOfMemoryError or java.lang.NegativeArraySizeException.
The readWeights method in the same class invokes readTensorInfoMap, making it vulnerable to similar issues when handling malicious data. This behavior could result in a Denial of Service (DoS).
2. Proof of Concept (PoC)
A PoC can be easily generated based on the test class TestParser (found at TestParser.java). All PoC code matches the source code from GitHub, except for the string passed to BaseEncoding.base16().decode.
1. Description
The
readTensorInfoMap
method in theSafeTensorSupport
class usesInts.checkedCast(headerLength)
to validate the length when allocating a byte array. However, this validation is flawed, allowing maliciously crafted data to trigger ajava.lang.OutOfMemoryError
orjava.lang.NegativeArraySizeException
.The
readWeights
method in the same class invokesreadTensorInfoMap
, making it vulnerable to similar issues when handling malicious data. This behavior could result in a Denial of Service (DoS).2. Proof of Concept (PoC)
A PoC can be easily generated based on the test class TestParser (found at TestParser.java). All PoC code matches the source code from GitHub, except for the string passed to
BaseEncoding.base16().decode
.PoC 1: java.lang.NegativeArraySizeException
PoC 2: java.lang.OutOfMemoryError
3. Root Cause Analysis
The root cause lies in the implementation of the
readTensorInfoMap
method in theSafeTensorSupport
class:The vulnerability arises from insufficient validation in
Ints.checkedCast(headerLength)
before usingheaderLength
to allocate the byte array.4. Mitigation
The
readTensorInfoMap
method in theSafeTensorSupport
class should include additional validation:By validating headerLength, the risk of OutOfMemoryError or NegativeArraySizeException can be mitigated.
The text was updated successfully, but these errors were encountered: