summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-28 10:36:25 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-28 10:36:25 (GMT)
commit5d8ae9bf171d1047032458977316799f24130a48 (patch)
tree9e39a5a058c0d4deea7e9c21d367650be21c75c1
parentd29598480f1b3c0d0eb205d03af3cabe01156124 (diff)
parentda55e192bada61cba9efadb0058ef921f548c5ed (diff)
downloadtcl-5d8ae9bf171d1047032458977316799f24130a48.zip
tcl-5d8ae9bf171d1047032458977316799f24130a48.tar.gz
tcl-5d8ae9bf171d1047032458977316799f24130a48.tar.bz2
Merge 8.6
-rw-r--r--doc/Tcl.n2
-rw-r--r--generic/tclZlib.c47
-rw-r--r--tests/zlib.test32
3 files changed, 71 insertions, 10 deletions
diff --git a/doc/Tcl.n b/doc/Tcl.n
index d13f3ea..99af4df 100644
--- a/doc/Tcl.n
+++ b/doc/Tcl.n
@@ -92,7 +92,7 @@ result of the script.
.IP "[8] \fBCommand substitution.\fR"
Each pair of brackets
.PQ [
-and
+and
.PQ ] ""
encloses a script and is replaced by the result of that script.
.IP "[9] \fBVariable substitution.\fR"
diff --git a/generic/tclZlib.c b/generic/tclZlib.c
index 61dc0ee..ce8da3c 100644
--- a/generic/tclZlib.c
+++ b/generic/tclZlib.c
@@ -442,10 +442,21 @@ GenerateHeader(
if (GetValue(interp, dictObj, "comment", &value) != TCL_OK) {
goto error;
} else if (value != NULL) {
+ Tcl_EncodingState state;
valueStr = TclGetStringFromObj(value, &len);
- Tcl_UtfToExternal(NULL, latin1enc, valueStr, len, 0, NULL,
+ result = Tcl_UtfToExternal(NULL, latin1enc, valueStr, len,
+ TCL_ENCODING_START|TCL_ENCODING_END|TCL_ENCODING_STOPONERROR, &state,
headerPtr->nativeCommentBuf, MAX_COMMENT_LEN-1, NULL, &len,
NULL);
+ if (result != TCL_OK) {
+ if (result == TCL_CONVERT_UNKNOWN) {
+ Tcl_AppendResult(interp, "Comment contains characters > 0xFF", NULL);
+ } else {
+ Tcl_AppendResult(interp, "Comment too large for zip", NULL);
+ }
+ result = TCL_ERROR;
+ goto error;
+ }
headerPtr->nativeCommentBuf[len] = '\0';
headerPtr->header.comment = (Bytef *) headerPtr->nativeCommentBuf;
if (extraSizePtr != NULL) {
@@ -463,9 +474,21 @@ GenerateHeader(
if (GetValue(interp, dictObj, "filename", &value) != TCL_OK) {
goto error;
} else if (value != NULL) {
+ Tcl_EncodingState state;
valueStr = TclGetStringFromObj(value, &len);
- Tcl_UtfToExternal(NULL, latin1enc, valueStr, len, 0, NULL,
- headerPtr->nativeFilenameBuf, MAXPATHLEN-1, NULL, &len, NULL);
+ result = Tcl_UtfToExternal(NULL, latin1enc, valueStr, len,
+ TCL_ENCODING_START|TCL_ENCODING_END|TCL_ENCODING_STOPONERROR, &state,
+ headerPtr->nativeFilenameBuf, MAXPATHLEN-1, NULL, &len,
+ NULL);
+ if (result != TCL_OK) {
+ if (result == TCL_CONVERT_UNKNOWN) {
+ Tcl_AppendResult(interp, "Filename contains characters > 0xFF", NULL);
+ } else {
+ Tcl_AppendResult(interp, "Filename too large for zip", NULL);
+ }
+ result = TCL_ERROR;
+ goto error;
+ }
headerPtr->nativeFilenameBuf[len] = '\0';
headerPtr->header.name = (Bytef *) headerPtr->nativeFilenameBuf;
if (extraSizePtr != NULL) {
@@ -1196,7 +1219,8 @@ Tcl_ZlibStreamPut(
{
ZlibStreamHandle *zshPtr = (ZlibStreamHandle *) zshandle;
char *dataTmp = NULL;
- int e, size, outSize, toStore;
+ int e;
+ int size, outSize, toStore;
unsigned char *bytes;
if (zshPtr->streamEnd) {
@@ -1325,7 +1349,8 @@ Tcl_ZlibStreamGet(
* may get less! */
{
ZlibStreamHandle *zshPtr = (ZlibStreamHandle *) zshandle;
- int e, i, listLen, itemLen, dataPos = 0;
+ int e;
+ int i, listLen, itemLen, dataPos = 0;
Tcl_Obj *itemObj;
unsigned char *dataPtr, *itemPtr;
int existing;
@@ -1576,7 +1601,8 @@ Tcl_ZlibDeflate(
int level,
Tcl_Obj *gzipHeaderDictObj)
{
- int wbits = 0, inLen = 0, e = 0, extraSize = 0;
+ int wbits = 0, e = 0, extraSize = 0;
+ int inLen = 0;
Byte *inData = NULL;
z_stream stream;
GzipHeader header;
@@ -1730,7 +1756,8 @@ Tcl_ZlibInflate(
int bufferSize,
Tcl_Obj *gzipHeaderDictObj)
{
- int wbits = 0, inLen = 0, e = 0, newBufferSize;
+ int wbits = 0, e = 0;
+ int inLen = 0, newBufferSize;
Byte *inData = NULL, *outData = NULL, *newOutData = NULL;
z_stream stream;
gz_header header, *headerPtr = NULL;
@@ -2400,7 +2427,8 @@ ZlibPushSubcmd(
const char *const *pushOptions = pushDecompressOptions;
enum pushOptionsEnum {poDictionary, poHeader, poLevel, poLimit};
Tcl_Obj *headerObj = NULL, *compDictObj = NULL;
- int limit = DEFAULT_BUFFER_SIZE, dummy;
+ int limit = DEFAULT_BUFFER_SIZE;
+ int dummy;
if (objc < 4) {
Tcl_WrongNumArgs(interp, 2, objv, "mode channel ?options...?");
@@ -2942,7 +2970,8 @@ ZlibTransformClose(
int flags)
{
ZlibChannelData *cd = (ZlibChannelData *)instanceData;
- int e, written, result = TCL_OK;
+ int e, result = TCL_OK;
+ int written;
if ((flags & (TCL_CLOSE_READ | TCL_CLOSE_WRITE)) != 0) {
return EINVAL;
diff --git a/tests/zlib.test b/tests/zlib.test
index ebbdd50..ad1baa6 100644
--- a/tests/zlib.test
+++ b/tests/zlib.test
@@ -486,6 +486,38 @@ test zlib-8.18 {Bug dd260aaf: fconfigure} -setup {
catch {close $inSide}
catch {close $outSide}
} -result {{one two} {one two}}
+test zlib-8.19 {zlib transformation, bug f9eafc3886} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list comment [string repeat A 500]]]
+} -cleanup {
+ catch {close $f}
+ removeFile $file
+} -returnCodes 1 -result {Comment too large for zip}
+test zlib-8.20 {zlib transformation, bug f9eafc3886} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list filename [string repeat A 5000]]]
+} -cleanup {
+ catch {close $f}
+ removeFile $file
+} -returnCodes 1 -result {Filename too large for zip}
+test zlib-8.21 {zlib transformation, bug f9eafc3886} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list comment \u100]]
+} -cleanup {
+ catch {close $f}
+ removeFile $file
+} -returnCodes 1 -result {Comment contains characters > 0xFF}
+test zlib-8.22 {zlib transformation, bug f9eafc3886} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list filename \u100]]
+} -cleanup {
+ catch {close $f}
+ removeFile $file
+} -returnCodes 1 -result {Filename contains characters > 0xFF}
test zlib-9.1 "check fcopy with push" -constraints zlib -setup {
set sfile [makeFile {} testsrc.gz]