Fix several out-of-bounds-accesses and a leak
There are several out-of-bounds accesses due to various reasons (incorrect bound, incorrect padding, integer overflow).
Also some data is leaked.
See individual commits for a more detailed description.
While this fixes a number of bugs, there are still multiple issues:
- likely wrong output for Mobipocket >= 5 (resulting in malformed HTML content)
- no unit tests
- unsufficient compile time checks, verification of invariants, static assertions etc.
- fairly inefficient due to copying data around
SENTRY: OKULAR-AD SENTRY: BALOO-33 SENTRY: BALOO-43Y CCBUG: 486853