coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

base32/base64/basenc: -d accepts CR where GNU rejects it

Open emirmrkaljevic opened this issue 4 weeks ago • 2 comments

base32/base64/basenc -d treats carriage return (\r) as ignorable whitespace, the same as newline. GNU only strips newlines; a CR is invalid input unless -i/--ignore-garbage is set.

$ printf 'NBSW\rY3DP\r' | base32 -d; echo "exit $?"   # GNU coreutils 9.12
he
base32: invalid input
exit 1

$ printf 'NBSW\rY3DP\r' | ./target/debug/coreutils base32 -d; echo "exit $?"   # uutils main
hello
exit 0

Same for base64:

$ printf 'aGVs\rbG8=\r' | base64 -d; echo "exit $?"   # GNU
hel
base64: invalid input
exit 1

$ printf 'aGVs\rbG8=\r' | ./target/debug/coreutils base64 -d; echo "exit $?"   # uutils
hello
exit 0

With -i, both GNU and uutils accept the CR and decode successfully.

In base_common::fast_decode_*, both \n and \r are skipped before the alphabet check. Only \n should be skipped unconditionally; \r should go through the garbage path.

Found with behave, recording GNU coreutils 9.12 base32 (examples/base32) and replaying against uutils.

emirmrkaljevic avatar Nov 06 '26 09:11 emirmrkaljevic

Hi! I'd be interested in working on this issue.

I understand that the problem is caused by \r being skipped unconditionally alongside \n in base_common::fast_decode_*. The expected behaviour is to ignore \n unconditionally while treating \r as invalid input unless -i (--ignore-garbage) is specified.

I'd like to investigate the existing decoding logic, implement the necessary changes, and add regression tests covering base32, base64, and basenc.

I noticed that PR #16224 is already linked to this issue. Is there any additional work needed, or would it be possible for me to contribute by reviewing the implementation, expanding test coverage, or addressing any remaining edge cases?

I'd appreciate the opportunity to contribute. Thank you!

nidhishkk avatar Nov 13 '26 06:11 nidhishkk

Thanks! #16224 already has the fix and tests for base32, base64 and basenc, and is waiting for review, so a review or extra edge cases on that PR would help the most.

emirmrkaljevic avatar Nov 13 '26 08:11 emirmrkaljevic