- Type: vulnerability
- Severity: high
- Confidence: certain
crypto/asn1/a_int.c:448crypto/asn1/a_int.c:457crypto/asn1/a_int.c:461crypto/asn1/asn1_lib.c:46crypto/asn1/asn1_lib.c:153
d2i_ASN1_UINTEGER() now casts a parsed ASN.1 content length from long to int without bounds checking, allowing oversized INTEGER lengths to truncate before allocation, copy, and stored length assignment.
This exploration and report were automatically generated by the Swival Security Scanner (https://swival.dev).
- A reachable decode path calls
d2i_ASN1_UINTEGER()on attacker-controlled or malformed ASN.1 input. - The ASN.1 INTEGER uses a definite content length greater than
INT_MAXbut still representable aslongon the target build.
crypto/asn1/asn1_lib.c:46parses ASN.1 object lengths into along, andcrypto/asn1/asn1_lib.c:139-crypto/asn1/asn1_lib.c:153accepts any definite length up toLONG_MAX.crypto/asn1/a_int.c:440-crypto/asn1/a_int.c:443reject only negative lengths. The priorINT_MAXguard present on the reference branch is absent in committedHEAD.crypto/asn1/a_int.c:448allocates withOPENSSL_malloc((int)len + 1),crypto/asn1/a_int.c:457copies withmemcpy(s, p, (int)len), andcrypto/asn1/a_int.c:461stores the truncated length withASN1_STRING_set0(ret, s, (int)len).- For any parsed
len > INT_MAX, each cast tointtruncates the true content length before memory allocation and before the decoded object records its size. - This violates the decoder invariant that the allocated buffer and stored ASN.1 string length match the parsed ASN.1 length, creating a concrete memory-safety and data-integrity failure on reachable oversized inputs.
The bug is directly visible in committed source and does not depend on speculation. The decoder explicitly accepts long lengths from the ASN.1 parser, then narrows them unsafely. The reference branch previously contained the exact missing guard, confirming this is a real regression rather than intentional behavior.
A code change is required because the current implementation mishandles valid parsed lengths that exceed INT_MAX. The decoder must reject lengths it cannot represent safely in the downstream int-based allocation and storage APIs.
The patch restores the lost INT_MAX bound check and uses size_t for allocation and copy sizes, matching the previous safe logic. It is minimal, local to the affected decoder, and preserves behavior for all representable ASN.1 INTEGER lengths.
None
Reference: audit-findings/002-asn1-uinteger-length-truncation.patch