question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Base64Decoder does not detect aligned internal padding

See original GitHub issue
var decoder = new DotNext.Buffers.Text.Base64Decoder();
decoder.DecodeFromUtf16("AA==");
decoder.DecodeFromUtf16("AA==");

Expected behavior: an exception is thrown

Actual behavior: no exception is thrown

The best solution is probably to create member bool gotPadding or similar, set it if buffer[^1] == '=', and throw exception if gotPadding is set when starting decoding. Also related, it’s possible to save some memory using forbidden states in reservedBuffer, examples:

  1. find first null byte/char instead of storing buffer size separately (null bytes are illegal in base64 input anyways)
  2. use -1 to mean gotPadding = true (end of input stream)
  3. create separate Utf8Base64Decoder and Utf16Base64Decoder structs holding 4 bytes and 8 bytes buffer

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
alxu-avptcommented, Jun 5, 2023

Thanks!

0reactions
saknocommented, Jun 7, 2023

Fixed in 4.12.2 and published.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does base64 encoding require padding if the input ...
Base64 concatenation allows encoders to process large chunks in parallel without the burden of aligning the chunk sizes to a multiple of three....
Read more >
Base64.Decoder (Java Platform SE 8 )
This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. The...
Read more >
BASE64Decoder: Error in encoded stream: Oracle Integration
Issue: The issue is because you are trying to map the stringReference to an opaque element as is without doing converting it into...
Read more >
Re: Base64 encoding applied to different unicode texts always ...
purpose by grouping symbols). In summary, padding is not required at all by all Base-N encoders/decoders, and non significant whitespace is frequently needed....
Read more >
TextView | Android Developers
android:paddingEnd, Sets the padding, in pixels, of the end edge; see ... Return the number of lines of text, or 0 if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found