uutils / uutils/coreutils

Handling of inner "=" in Base64 and Base32

Open
#12,204 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - base32 U - base64
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

Base64 and Base32 implementations may be not conforming to RFC 4648, Section 3.3 in handling the pad character occurred before the end of the encoded data. The RFC allows to ignore the inner "=" if it was explicitly specified. This was the behavior in uutils coreutils 0.2.2. But in uutils coreutils 0.8.0 they are not ignored, but used for padding even if not at the end of the encoded data.

$ echo -n QQ==Qg==Qw== | base64 -di | hd
00000000  41 42 43                                          |ABC|
00000003
$ echo -n QQQgQw== | base64 -di | hd
00000000  41 04 20 43                                       |A. C|
00000004

If they were ignored, you should get t6he same result in both cases.

There is a similar issue with Base32.

$ echo -n IE======II======IM======IQ======IU====== | base32 -d | hd
00000000  41 42 43 44 45                                    |ABCDE|
00000005
$ echo -n IEIIIMIQIU====== | base32 -d | hd
00000000  41 10 84 31 10 45                                 |A..1.E|
00000006

The problem is that different Base64 and Base32 decoders produce different result for the same input. This may pose a security risk. The implementation that literally follows RFC 4648 (for example Python after recent change https://github.com/python/cpython/issues/145264) will treat inner "=" as error or ignore it.

I think that Base64 and Base32 decoders should treat "=" before the end of the encoded data as error by default, and have option to ignore them as non-alphabet characters (it can be combined with -i). It may also have option for the current behavior, but it should not be default.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Base64 and Base32 command examples and compare their behavior with RFC 4648 and other decoder implementations. Trace the decoder paths used by the base64 and base32 commands, then determine how inner = should behave by default and with -i. Done means both decoders have consistent, documented handling and regression coverage for the shown inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.