05nelsonm / encoding

A Kotlin Multiplatform library for configurable, streamable, efficient and extensible Encoding/Decoding with support for base16/32/64.
Apache License 2.0
33 stars 5 forks source link

Fix encode/decode out calculations #48

Closed 05nelsonm closed 1 year ago

05nelsonm commented 1 year ago
  1. The EncoderDecoder.Config methods for pre-calculating the encoded and decoded out size should accept a Long instead of Int, and return a Long
  2. decodeOutMaxSizeOrFail should accept null for input to be usable with streams.
    1. A stream won't have access to the entirety of what is being decoded and thus, cannot send DecoderInput.
  3. DecoderInput should check for a negative return value of decodeOutMaxSizeOrFail and throw EncodingException
  4. DecoderInput should check if the returned Long is greater than Int.MAX_VALUE and throw EncodingException

There's a possibility of the EncoderDecoder.Config implementation having an overflow issue, that should be checked for in the base abstraction and throw such that we can guarantee a positive value is always returned.

05nelsonm commented 1 year ago

The encodeOutSize and decodeOutMaxSizeOrFail methods should throw some sort of overflow exception if the number is greater than Long.MAX_VALUE. Think a new exception here that inherits from EncodingException would be best, in order to be specific.