Wed 10 Oct 2012 12:43:41 PM UTC, original submission:
Concider the following application which tries to load an ans1 spec a bunch of times(loading multiple times better shows the effect of the bug):
#include <libtasn1.h>
#include <assert.h>
int main (int argc, char *argv[])
{
for(int i = 0; i < 2000000; i++)
{
ASN1_TYPE tree = ASN1_TYPE_EMPTY;
assert(asn1_parser2tree("<file containing asn1>", &tree, errorDescription) == ASN1_SUCCESS);
assert(asn1_delete_structure(&tree) == ASN1_SUCCESS);
}
return 0;
}
Run it with both of the follwing specs and watch the memory usage:
-----------------------------------------------------------
Spec {} DEFINITIONS EXPLICIT TAGS ::= BEGIN
SpecNoConstraints ::= SEQUENCE {
first-field [0] INTEGER,
second-field [1] INTEGER,
third-field [2] INTEGER,
fourth-field [3] INTEGER,
fifth-field [4] INTEGER
}
END
-----------------------------------------------------------
Spec {} DEFINITIONS EXPLICIT TAGS ::= BEGIN
SpecNoConstraints ::= SEQUENCE {
first-field INTEGER (1),
second-field INTEGER (1),
third-field INTEGER (1),
fourth-field INTEGER (1),
fifth-field INTEGER (1)
}
END
-----------------------------------------------------------
The first spec where the INTEGER fields have no constraints will behave as expected, the second one on the other hand claims loads of memory that is never returned to the OS.
My lex/yacc is no good but the parser seems to claim an extra asn_node for the constraint that is unnecessary (ASN1.y:206 in 2.14)
|