Implement support for maximum sizes in leb128_decode()

This allows the caller to specify the maximum number of bytes to be
taken into consideration. This is useful to avoid parsing huge amounts
of data for erroneous (or malicious) input.