bcgit/bc-csharp — pull request #10 by OscarAyoy (2013-10-23 14:44:09+00:00)
Title: Feature/fix enum decoding

This is a quick fix for a DerEnumerated parsing problem. Basically, the Asn1InputStream class has special handling when parsing the DerBoolean, DerEnumerated and DerObjectIdentifier classes in that it uses a number of shared temporary buffers, tmpBuffers, instead of dynamically allocating new buffers on the fly.

For DerBoolean and DerObjectIdentifier this is ok, since they copy their input data during construction, but DerEnumerated only stores a reference to the input byte array on construction. If another DerBoolean, DerEnumerated or DerObjectIdentifier of the same size is read later in the same stream the shared temporary buffer is reused, meaning the value of the previously parsed DerEnumerated is overwritten.

I've supplied some trivial failing unit tests that demonstrate this bug, and also a simple fix to the appropriate DerEnumerated constructor that clones the input array, making the tests pass.