]> granicus.if.org Git - recode/commitdiff
base64.c: fix handling of EOF and LF (fixes Debian bug #271939)
authorReuben Thomas <rrt@sc3d.org>
Wed, 17 Jan 2018 13:13:12 +0000 (13:13 +0000)
committerReuben Thomas <rrt@sc3d.org>
Tue, 23 Jan 2018 07:02:41 +0000 (07:02 +0000)
LF can occur before the end of a full line (76 characters) if it’s
immediately followed by EOF.

The last line can be any number of quadruplets long; it need not be 76
characters. (I suspect this was an attempt to deal with LF without the extra
call to get_byte and goto.)

src/base64.c

index 7afd8be9897829e35f72b104ccb0df577004ad61..e353994884c187dde77f3cb681a398ce2c66c2a3 100644 (file)
@@ -149,19 +149,20 @@ transform_base64_data (RECODE_SUBTASK subtask)
       /* Accept wrapping lines, reversibly if at each 76 characters.  */
 
       character = get_byte (subtask);
+
+    top:
       if (character == EOF)
-       {
-         if (counter != 0)
-           RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
-         SUBTASK_RETURN (subtask);
-       }
+       SUBTASK_RETURN (subtask);
 
       if (character == '\n')
        {
+          character = get_byte (subtask);
+         if (character == EOF)
+            SUBTASK_RETURN (subtask);
          if (counter != MIME_LINE_LENGTH / 4)
            RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
          counter = 0;
-         continue;
+         goto top;
        }
 
       if (character == '\r')