Two issues I see with this:

* It overwrites the last byte of the BIO output (but IIRC that's a zero byte anyway?)
* Underflows when ptr->length == 0.  I'm not sure whether that's actually possible but defense in depth.