[patch] A couple of bugfixes for base64 uudecode

Jorgen Cederlof jcz at google.com
Mon Jun 4 20:57:16 UTC 2007


Hello list,

I encountered a couple of problems with base64 uudecode. It couldn't
handle an empty file (term_count needs to be 1 at the beginning of a
line to catch the terminating line, which it was for every line but
the first) and when the output was supposed to be 3n+1 bytes it wrote
an extra junk byte at the end when it encountered the second '='. The
patch below should fix both issues.

   Jörgen


Index: coreutils/uudecode.c
===================================================================
--- coreutils/uudecode.c	(revision 18719)
+++ coreutils/uudecode.c	(working copy)
@@ -70,7 +70,7 @@
 {
 	static const char base64_table[] =
 		"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n";
-	int term_count = 0;
+	int term_count = 1;
 
 	while (1) {
 		char translated[4];
@@ -113,7 +113,9 @@
 		}
 
 		/* Merge 6 bit chars to 8 bit */
-	    fputc(translated[0] << 2 | translated[1] >> 4, dst_stream);
+		if (count > 1) {
+			fputc(translated[0] << 2 | translated[1] >> 4, dst_stream);
+		}
 		if (count > 2) {
 			fputc(translated[1] << 4 | translated[2] >> 2, dst_stream);
 		}



More information about the busybox mailing list