<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<p class="details" style="font-style: italic; color: #777;">
<a href="https://gitlab.com/carblue">carblue</a> created an issue:
</p>
<div></div>
<h2 dir="auto">
<a id="user-content-description-of-problem" class="anchor" href="#description-of-problem" aria-hidden="true"></a>Description of problem:</h2>
<p dir="auto">function "asn1_der_decoding" causes infinite memory allocation when structure and input DER data are incongruent. I'm referring here to PKCS#15 TokenInfo from ASN.1 module e.g. at <a href="https://github.com/carblue/tasn1/blob/master/PKCS15.asn" rel="nofollow noreferrer noopener" target="_blank">https://github.com/carblue/tasn1/blob/master/PKCS15.asn</a>. Excerpt:
TokenInfo ::= SEQUENCE {
version INTEGER { v1(0), v2(1) }, -- (v1,...),
serialNumber OCTET STRING,
manufacturerID Label OPTIONAL,
label [0] Label OPTIONAL,
tokenflags TokenFlags,
...more fields</p>
<p dir="auto">It happened, that my smart card's PKCS#15 EF.TokenInfo file 0x5032 got corrupted (i.e. not PKCS#15 compliant content any more: "tokenflags" were misplaced before "manufacturerID" instead correctly behind "label"), thus forming incrongruent input DER data.</p>
<h2 dir="auto">
<a id="user-content-version-of-libtasn1-used" class="anchor" href="#version-of-libtasn1-used" aria-hidden="true"></a>Version of libtasn1 used:</h2>
<p dir="auto">4.13</p>
<h2 dir="auto">
<a id="user-content-distributor-of-libtasn1-eg-ubuntu-fedora-rhel" class="anchor" href="#distributor-of-libtasn1-eg-ubuntu-fedora-rhel" aria-hidden="true"></a>Distributor of libtasn1 (e.g., Ubuntu, Fedora, RHEL)</h2>
<p dir="auto">Ubuntu (package libtasn1-6, installs Version 4.13-2)</p>
<h2 dir="auto">
<a id="user-content-how-reproducible" class="anchor" href="#how-reproducible" aria-hidden="true"></a>How reproducible:</h2>
<p dir="auto">Steps to Reproduce: (the following is D language code, slightly different from C; there is no problem referring to D code as such, it works well with the "congruent buf DER input data"):</p>
<p dir="auto">asn1_node PKCS15;
string errorDescription;
ubyte[] buf = new ubyte[length_of_input_data_in_bytes; 65 for my example DER input data];</p>
<ul dir="auto">
<li>
<ol>
<li>asn1_parser2tree ("PKCS15.asn", &PKCS15, errorDescription);</li>
</ol>
</li>
<li>
<ol start="2">
<li>asn1_create_element(PKCS15, "PKCS15.TokenInfoChoice", &structure);</li>
</ol>
</li>
<li>
<ol start="3">
<li>asn1_der_decoding(&structure, buf, errorDescription);</li>
</ol>
</li>
</ul>
<p dir="auto">Example for congruent buf DER input data: 303F0201010406C0C6406881C70C1A416476616E63656420436172642053797374656D73204C74642E801243544D36345F43304336343036383831433703020420</p>
<p dir="auto">Example for incongruent buf DER input data:
3032020101040400000000030204200C1A416476616E63656420436172642053797374656D73204C74642EA0070C05626162616E36343036383831433703020420</p>
<h2 dir="auto">
<a id="user-content-actual-results" class="anchor" href="#actual-results" aria-hidden="true"></a>Actual results:</h2>
<p dir="auto">Memory allocation failed, because I "jailed" memory usage with ulimit -d -m -v : 5000000; otherwise it would crash my OS system by infinitely allocating memory !</p>
<h2 dir="auto">
<a id="user-content-expected-results" class="anchor" href="#expected-results" aria-hidden="true"></a>Expected results:</h2>
<p dir="auto">Successful DER data decoding into structure based on the provided .asn module file</p>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #777;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/libtasn1/issues/24">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/sent_notifications/94d8e040612767e024e6a2915ec14f0c/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.com/gnutls/libtasn1/issues/24"}}</script>
</p>
</div>
</body>
</html>