ZeroK-RTS/Zero-K

Port BAR#3422

sprunk opened this issue · 4 comments

beyond-all-reason/Beyond-All-Reason#3422 is some bugfix to base64, could see if we can port.

FYI: Fixes are allowing to decode binary data with this lib, the decoding:

  • Wasn't correctly decoding byte values >=192
  • Was dropping all \0 bytes in the output

In BAR we will use to effectively do stuff like json_decode(zlib_decompress(base64_decode(data)))

Insanity. But sure, I guess.

The 192 comment raises two No Free Lunch questions. I suspect the answer is that base64 is just wasteful so these things will be non-issues. But that is only based on my assumption of what base64 does, I haven't looked into it deeply, so maybe it works in some way that would cause problems.

All base64 is used for in ZK is sending tables through startscripts, since there are many illegal characters for startscript keys.

  • Will encodings change such that they now use bad characters? Encodings also need to be human-manipulatable for things like tweakdefs.
  • Will existing encodings get any larger? The campaign missions script generator splits up large tables so as to not OOM lua as it tries to decode it. It would be annoying if there were new intermittent crashes around this.

Encoding output, base64_encode(data), is not changed, it's still standard Base64 URL encoding. No changes to the encoding output alphabet. The fixes are in base64 decoding implementation only. It fixes the library so that for any arbitrary data base64_decode(base64_encode(data)) == data.