When decoding a LEB128 number, it might be followed by an arbitrary
amount of padding. The padding bits might require more bits than we can
actually store in the representation of the result, but this is not a problem
as long as the padding bits all correspond to a sext/zext. Previously,
the decoding was not handling this case, which caused decodeULEB128 to fail
with the error message "uleb128 too big for uint64". It didn't fail for
decodeSLEB128, but that's because decodeSLEB128 didn't check for
overflow at all, so it was probably doing something dubious in terms of
C++ language spec.
This commit fixes various issues with handling padding bits. This patch
allows numbers to have extra bits that would normally overflow the
representation, as long as those extra bits correspond to the sext/zext
of the representation. Once some bits appear that don't fit the
sext/zext, then it produes an error about the overflow.
Additionally, this patch masks the bits passed to insertLo7InPlace to try to
avoid signed overflow in its implementation.
Additionally, this patch adds tests for decoding and encoding with
8-bit, 16-bit, and 32-bit types as the representation. Implementing
these tests required the overflow issue to be solved, because otherwise
tests of decodeLEB128 into a uint8_t would fail due to an incorrectly
detected overflow.