]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
basenc: fix stripping of '=' chars in some encodings
authorPádraig Brady <P@draigBrady.com>
Thu, 7 Aug 2025 19:39:24 +0000 (20:39 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 9 Aug 2025 08:59:00 +0000 (09:59 +0100)
* src/basenc.c (do_decode): With -i ensure we strip '=' chars
if there is no padding for the chosen encoding.
* tests/basenc/basenc.pl: Add a test case.
* NEWS: Mention the bug fix.

NEWS
src/basenc.c
tests/basenc/basenc.pl

diff --git a/NEWS b/NEWS
index 473c7a798dc5a116ca86e0824e7efe590e0bedd9..f97c7e4a19398c9cd672044f7eba523e52984113 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  '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]
+
   cksum was not compilable by Apple LLVM 10.0.0 x86-64, which
   lacks support for checking for the VPCLMULQDQ instruction.
   [bug introduced in coreutils-9.6]
index c445e6f41a36f6ae56fa12d65b200fbdb22d8493..4993c002539cbc689763ca336b35041385258562 100644 (file)
@@ -1159,7 +1159,8 @@ do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
             {
               for (idx_t i = 0; n > 0 && i < n;)
                 {
-                  if (isubase (inbuf[sum + i]) || inbuf[sum + i] == '=')
+                  if (isubase (inbuf[sum + i])
+                      || (REQUIRED_PADDING (1) && inbuf[sum + i] == '='))
                     i++;
                   else
                     memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
index c598d29e5bd87b30535c6adbc295f8c3f512d9c7..94f6c2b326d3de67489fe6d1065a9dc632b53432 100755 (executable)
@@ -168,6 +168,7 @@ my @Tests =
  ['b2m_2', '--base2m -d',     {IN=>'11000001'},   {OUT=>"\xC1"}],
  ['b2m_3', '--base2m -d',     {IN=>"110\n00001"}, {OUT=>"\xC1"}],
  ['b2m_4', '--base2m -di',    {IN=>"110x00001"},  {OUT=>"\xC1"}],
+ ['b2m_4p', '--base2m -di',   {IN=>"=11000001="}, {OUT=>"\xC1"}],
  ['b2m_5', '--base2m -d',     {IN=>"110x00001"},  {EXIT=>1},
   {ERR=>"$prog: invalid input\n"}],
  ['b2m_6', '--base2m -d',     {IN=>"11000001x"},  {OUT=>"\xC1"}, {EXIT=>1},