Ticket 49441 - Import crashes with large indexed binary
Bug Description: Importing an ldif file that contains entries with large
binary attributes that are indexed crashes the server.
The crash occurs when "encoding" the binary value to a
string for debug logging, where we "underflow" the buffer
space index which then allows the string buffer to overflow.
Fix Description: While filling the string buffer with the encoded binary
value we need to make sure if the buffer space is greater
than zero before decrementing it.
Also check if trace logging is being used before we actually
call the logging function which calls the "encoded" function
first. This way we avoid this costly "encoding" on every
index call we make.
Reviewed by: firstyear(Thanks!)
(cherry picked from commit b4497c4f28501b188797e12909983853642af967)