summaryrefslogtreecommitdiffstats
path: root/generic/tclZlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclZlib.c')
-rw-r--r--generic/tclZlib.c47
1 files changed, 38 insertions, 9 deletions
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;