Skip to content

asn1: check for missing EOC in indefinite length encoding #859

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

Merged
merged 1 commit into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ext/openssl/ossl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,12 @@ int_ossl_asn1_decode0_cons(unsigned char **pp, long max_len, long length,
*num_read += inner_read;
available_len -= inner_read;

if (indefinite &&
ossl_asn1_tag(value) == V_ASN1_EOC &&
ossl_asn1_get_tag_class(value) == sym_UNIVERSAL) {
break;
if (indefinite) {
if (ossl_asn1_tag(value) == V_ASN1_EOC &&
ossl_asn1_get_tag_class(value) == sym_UNIVERSAL)
break;
if (available_len == 0)
ossl_raise(eASN1Error, "EOC missing in indefinite length encoding");
}
rb_ary_push(ary, value);
}
Expand Down
5 changes: 5 additions & 0 deletions test/openssl/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ def test_sequence
])
expected.indefinite_length = true
encode_test B(%w{ 30 80 04 01 00 00 00 }), expected

# Missing EOC at the end of contents octets
assert_raise(OpenSSL::ASN1::ASN1Error) {
OpenSSL::ASN1.decode(B(%w{ 30 80 01 01 FF }))
}
end

def test_set
Expand Down
Loading