coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

base64: Unexpected result when decoding data with garbage

Open EmilSodergren opened this issue 5 months ago • 1 comments

Hi, I have run in to a problem when trying to base64 decode a file that contains garbage data. This is with the coreutils version 0.8.0, installed from the Ubuntu 26.04 Resolute apt repository.

Consider the following truncated content from my_base64_file.txt: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjMjQ5MmF

Yes! It contains a ., which is garbage. I know.

When decoding it with base64 (GNU coreutils) 9.4 the result is: base64 -d my_base64_file.txt --> {"alg":"RS256","typ":"JWT"}base64: invalid input base64 -di my_base64_file.txt --> {"alg":"RS256","typ":"JWT"}{"jti":"c2492abase64: invalid input

But, with base64 (core uutils 0.8.0) I get: base64 -d my_base64_file.txt --> base64: error: invalid input base64 -di my_base64_file.txt --> base64: error: invalid input

Is there something I am missing here, or is there a bug with the --ignore-garbage feature?

EmilSodergren avatar Jun 16 '26 14:06 EmilSodergren

Related note from more recent decoding checks: uutils also treated CR (\r) as ignorable whitespace the same as LF, while GNU only strips newlines and needs -i for CR. I opened that separately as #16223 (fix in #16224). Your case here is still about keeping already-decoded output when other garbage shows up mid-stream.

emirmrkaljevic avatar Nov 06 '26 09:11 emirmrkaljevic