summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclZlib.c47
-rw-r--r--tests/zlib.test48
2 files changed, 86 insertions, 9 deletions
diff --git a/generic/tclZlib.c b/generic/tclZlib.c
index 63a25fa..cbff7b7 100644
--- a/generic/tclZlib.c
+++ b/generic/tclZlib.c
@@ -441,10 +441,21 @@ GenerateHeader(
if (GetValue(interp, dictObj, "comment", &value) != TCL_OK) {
goto error;
} else if (value != NULL) {
+ Tcl_EncodingState state;
valueStr = Tcl_GetStringFromObj(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) {
@@ -462,9 +473,21 @@ GenerateHeader(
if (GetValue(interp, dictObj, "filename", &value) != TCL_OK) {
goto error;
} else if (value != NULL) {
+ Tcl_EncodingState state;
valueStr = Tcl_GetStringFromObj(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) {
@@ -1189,7 +1212,8 @@ Tcl_ZlibStreamPut(
{
ZlibStreamHandle *zshPtr = (ZlibStreamHandle *) zshandle;
char *dataTmp = NULL;
- int e, size, outSize, toStore;
+ int e;
+ int size, outSize, toStore;
if (zshPtr->streamEnd) {
if (zshPtr->interp) {
@@ -1312,7 +1336,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;
@@ -1561,7 +1586,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;
@@ -1711,7 +1737,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;
@@ -2365,7 +2392,8 @@ ZlibPushSubcmd(
const char *const *pushOptions = pushDecompressOptions;
enum pushOptions {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...?");
@@ -2897,7 +2925,8 @@ ZlibTransformClose(
Tcl_Interp *interp)
{
ZlibChannelData *cd = (ZlibChannelData *)instanceData;
- int e, written, result = TCL_OK;
+ int e, result = TCL_OK;
+ int written;
/*
* Delete the support timer.
diff --git a/tests/zlib.test b/tests/zlib.test
index 7ddf1d7..c3e344c 100644
--- a/tests/zlib.test
+++ b/tests/zlib.test
@@ -486,6 +486,54 @@ 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 XXXXXXXXXX} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list comment [string repeat A 500]]]
+ puts $f "ok"
+ close $f
+ set f [zlib push gunzip [open $file]]
+ list [gets $f] [dict get [chan configure $f -header] comment]
+} -cleanup {
+ close $f
+ removeFile $file
+} -returnCodes 1 -result {Comment too large for zip}
+test zlib-8.20 {zlib transformation, bug XXXXXXXXXX} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list filename [string repeat A 5000]]]
+ puts $f "ok"
+ close $f
+ set f [zlib push gunzip [open $file]]
+ list [gets $f] [dict get [chan configure $f -header] filename]
+} -cleanup {
+ close $f
+ removeFile $file
+} -returnCodes 1 -result {Filename too large for zip}
+test zlib-8.21 {zlib transformation, bug XXXXXXXXXX} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list comment \u100]]
+ puts $f "ok"
+ close $f
+ set f [zlib push gunzip [open $file]]
+ list [gets $f] [dict get [chan configure $f -header] comment]
+} -cleanup {
+ close $f
+ removeFile $file
+} -returnCodes 1 -result {Comment contains characters > 0xFF}
+test zlib-8.22 {zlib transformation, bug XXXXXXXXXX} -constraints zlib -setup {
+ set file [makeFile {} test.gz]
+} -body {
+ set f [zlib push gzip [open $file w] -header [list filename \u100]]
+ puts $f "ok"
+ close $f
+ set f [zlib push gunzip [open $file]]
+ list [gets $f] [dict get [chan configure $f -header] comment]
+} -cleanup {
+ 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]