[openssl-users] i2d_PKCS7_bio() very slow for large file when reading in memory

Dr. Stephen Henson steve at openssl.org
Fri Apr 29 15:23:02 UTC 2016


On Wed, Apr 27, 2016, Jan Kohnert wrote:

> Am Samstag, 23. April 2016, 03:57:55 schrieb Jan Kohnert:
> > I have question regarding i2d_PKCS7_bio() in Version 1.0.1c, 
> 1.0.2g and
> > maybe newer versions.
> 
> [code skipped]
> 
> Nobody any idea? Shall I compose a minimal compilable example 
> to make anyone able to dig this a little more? I still don't have a 
> clue what makes the function hang so long???
> 

Memory BIOs can be very inefficient when they contain a lot of data and it is
read in small chunks: each read copies the remaining data to the start of the 
memory block. If your message uses indefinite length encoding that could well
happen.

If you read the data into a block of memory and call d2i_CMS_ContentInfo() on
it you shouldn't get this problem. Alternatively if you have to use a memory
BIO you can retrieve the pointer to the contained memory block using
BIO_get_mem_data() and call d2i_CMS_ContentInfo() on the result.

A third option of to make the BIO read only and call d2i_CMS_bio() on that:
read only memory BIOs are handled more efficiently.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org


More information about the openssl-users mailing list