summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2020-03-28 16:33:50 (GMT)
committerdgp <dgp@users.sourceforge.net>2020-03-28 16:33:50 (GMT)
commitf5621cf8539eb6b5c64826e06254cbf2121a52bd (patch)
treec25863768baad5a43b4feb82e47ee9c62265040c
parenta30671934a6bd8c3448cb1a57634210fa24edbb0 (diff)
parentc619f65f15cd0877658ae9a0c0e3748b8fc0896b (diff)
downloadtcl-f5621cf8539eb6b5c64826e06254cbf2121a52bd.zip
tcl-f5621cf8539eb6b5c64826e06254cbf2121a52bd.tar.gz
tcl-f5621cf8539eb6b5c64826e06254cbf2121a52bd.tar.bz2
merge 8.6
-rw-r--r--doc/binary.n11
-rw-r--r--generic/tclBinary.c29
-rw-r--r--tests/binary.test5
3 files changed, 28 insertions, 17 deletions
diff --git a/doc/binary.n b/doc/binary.n
index 00b29d4..00919f3 100644
--- a/doc/binary.n
+++ b/doc/binary.n
@@ -73,7 +73,9 @@ During decoding, the following options are supported:
.TP
\fB\-strict\fR
.
-Instructs the decoder to throw an error if it encounters whitespace characters. Otherwise it ignores them.
+Instructs the decoder to throw an error if it encounters any characters
+that are not strictly part of the encoding itself. Otherwise it ignores them.
+RFC 2045 calls for base64 decoders to be non-strict.
.RE
.TP
\fBhex\fR
@@ -87,7 +89,8 @@ options are supported:
.TP
\fB\-strict\fR
.
-Instructs the decoder to throw an error if it encounters whitespace characters. Otherwise it ignores them.
+Instructs the decoder to throw an error if it encounters whitespace characters.
+Otherwise it ignores them.
.RE
.TP
\fBuuencode\fR
@@ -117,8 +120,8 @@ During decoding, the following options are supported:
.TP
\fB\-strict\fR
.
-Instructs the decoder to throw an error if it encounters unexpected whitespace
-characters. Otherwise it ignores them.
+Instructs the decoder to throw an error if it encounters unexpected
+whitespace characters. Otherwise it ignores them.
.PP
Note that neither the encoder nor the decoder handle the header and footer of
the uuencode format.
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index a050122..ce816d9 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -3173,7 +3173,7 @@ BinaryDecode64(
if (c == '=' && i > 1) {
value <<= 6;
cut++;
- } else if (!strict && TclIsSpaceProc(c)) {
+ } else if (!strict) {
i--;
} else {
goto bad64;
@@ -3197,7 +3197,7 @@ BinaryDecode64(
if (i) {
cut++;
}
- } else if (strict || !TclIsSpaceProc(c)) {
+ } else if (strict) {
goto bad64;
} else {
i--;
@@ -3217,11 +3217,6 @@ BinaryDecode64(
if (strict) {
goto bad64;
}
- for (; data < dataend; data++) {
- if (!TclIsSpaceProc(*data)) {
- goto bad64;
- }
- }
}
}
Tcl_SetByteArrayLength(resultObj, cursor - begin - cut);
@@ -3229,11 +3224,21 @@ BinaryDecode64(
return TCL_OK;
bad64:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "invalid base64 character \"%c\" at position %d",
- (char) c, (int) (data - datastart - 1)));
- TclDecrRefCount(resultObj);
- return TCL_ERROR;
+ {
+ /* The decoder is byte-oriented. If we saw a byte that's not a
+ * valid member of the base64 alphabet, it could be the lead byte
+ * of a multi-byte character. */
+ Tcl_UniChar ch;
+
+ /* Safe because we know data is NUL-terminated */
+ TclUtfToUniChar((const char *)(data - 1), &ch);
+
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "invalid base64 character \"%c\" at position %d", ch,
+ (int) (data - datastart - 1)));
+ TclDecrRefCount(resultObj);
+ return TCL_ERROR;
+ }
}
/*
diff --git a/tests/binary.test b/tests/binary.test
index 4b1791d..ae94ab4 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -2718,7 +2718,7 @@ test binary-73.30 {binary decode base64} -body {
list [string length [set r [binary decode base64 -strict WFla\n]]] $r
} -returnCodes error -match glob -result {invalid base64 character *}
test binary-73.31 {binary decode base64} -body {
- list [string length [set r [binary decode base64 WA==WFla]]] $r
+ list [string length [set r [binary decode base64 -strict WA==WFla]]] $r
} -returnCodes error -match glob -result {invalid base64 character *}
test binary-73.32 {binary decode base64, bug [00d04c4f12]} -body {
list \
@@ -2760,6 +2760,9 @@ test binary-73.36 {binary decode base64: check encoded & decoded equals original
}
join $r \n
} -result {}
+test binary-73.37 {binary decode base64: Bug ffeb2097af} {
+ binary decode base64 [binary encode base64 -maxlen 3 -wrapchar : abc]
+} abc
test binary-74.1 {binary encode uuencode} -body {
binary encode uuencode