Previously it would have silently assumed 512 for any larger values.
[bug introduced in coreutils-9.6]
+ 'base32' and 'base64' when decoding will again diagnose partially
+ padded data that ends with a newline.
+ [bug introduced in coreutils-9.5]
+
'basenc -d -i' will now strip '=' characters from the input
in encodings where padding characters are not valid.
[bug introduced with the basenc program in coreutils-8.31]
finish_and_exit (in, infile);
}
+/* Returns TRUE if BUF of length LEN
+ ends with a '=' character.
+ Trailing '\n' characters are ignored. */
+ATTRIBUTE_PURE
+static bool
+has_padding (char const *buf, size_t len)
+{
+ while (len--)
+ {
+ if (buf[len] == '\n')
+ continue;
+ return buf[len] == '=';
+ }
+ return false;
+}
+
static _Noreturn void
do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
{
/* auto pad input (at eof). */
idx_t auto_padding = REQUIRED_PADDING (ctx.i);
- if (auto_padding && (sum == 0 || inbuf[sum - 1] != '='))
+ if (auto_padding && ! has_padding (inbuf, sum))
{
affirm (auto_padding <= sizeof (padbuf));
IF_LINT (free (inbuf));
if ($prog eq "base64")
{
push @Tests, (
+ ['paddec1', '--decode', {IN=>'aQ'}, {OUT=>"i"}],
+ ['paddec2', '--decode', {IN=>'Zzw'}, {OUT=>"g<"}],
+ ['paddec3', '--decode', {IN=>'MTIzNA==MTIzNA'}, {OUT=>"12341234"}],
+ ['paddec4', '--decode', {IN=>"MTIzNA==\nMTIzNA"}, {OUT=>"12341234"}],
['baddecode', '--decode', {IN=>'a'}, {OUT=>""},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
- ['paddecode2', '--decode', {IN=>'aQ'}, {OUT=>"i"}],
- ['paddecode3', '--decode', {IN=>'Zzw'}, {OUT=>"g<"}],
['baddecode4', '--decode', {IN=>'Zz='}, {OUT=>"g"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['baddecode5', '--decode', {IN=>'Z==='}, {OUT=>""},
['baddecode6', '--decode', {IN=>'SB=='}, {OUT=>"H"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['baddecode7', '--decode', {IN=>'SGVsbG9='}, {OUT=>"Hello"},
+ {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
+ ['baddecode8', '--decode', {IN=>'MTIzNA='}, {OUT=>"1234"},
+ {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
+ ['baddecode9', '--decode', {IN=>"MTIzNA=\n"}, {OUT=>"1234"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}]
);
}