diff options
| -rw-r--r-- | gzlib.c | 1 | ||||
| -rw-r--r-- | gzwrite.c | 44 | ||||
| -rw-r--r-- | zlib.h | 26 |
3 files changed, 37 insertions, 34 deletions
| @@ -615,7 +615,6 @@ void ZLIB_INTERNAL gz_error(state, err, msg) | |||
| 615 | strcat(state->msg, ": "); | 615 | strcat(state->msg, ": "); |
| 616 | strcat(state->msg, msg); | 616 | strcat(state->msg, msg); |
| 617 | #endif | 617 | #endif |
| 618 | return; | ||
| 619 | } | 618 | } |
| 620 | 619 | ||
| 621 | #ifndef INT_MAX | 620 | #ifndef INT_MAX |
| @@ -11,7 +11,8 @@ local int gz_comp OF((gz_statep, int)); | |||
| 11 | local int gz_zero OF((gz_statep, z_off64_t)); | 11 | local int gz_zero OF((gz_statep, z_off64_t)); |
| 12 | 12 | ||
| 13 | /* Initialize state for writing a gzip file. Mark initialization by setting | 13 | /* Initialize state for writing a gzip file. Mark initialization by setting |
| 14 | state->size to non-zero. Return -1 on failure or 0 on success. */ | 14 | state->size to non-zero. Return -1 on a memory allocation failure, or 0 on |
| 15 | success. */ | ||
| 15 | local int gz_init(state) | 16 | local int gz_init(state) |
| 16 | gz_statep state; | 17 | gz_statep state; |
| 17 | { | 18 | { |
| @@ -63,11 +64,11 @@ local int gz_init(state) | |||
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | /* Compress whatever is at avail_in and next_in and write to the output file. | 66 | /* Compress whatever is at avail_in and next_in and write to the output file. |
| 66 | Return -1 if there is an error writing to the output file, otherwise 0. | 67 | Return -1 if there is an error writing to the output file or if gz_init() |
| 67 | flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, | 68 | fails to allocate memory, otherwise 0. flush is assumed to be a valid |
| 68 | then the deflate() state is reset to start a new gzip stream. If gz->direct | 69 | deflate() flush value. If flush is Z_FINISH, then the deflate() state is |
| 69 | is true, then simply write to the output file without compressing, and | 70 | reset to start a new gzip stream. If gz->direct is true, then simply write |
| 70 | ignore flush. */ | 71 | to the output file without compressing, and ignore flush. */ |
| 71 | local int gz_comp(state, flush) | 72 | local int gz_comp(state, flush) |
| 72 | gz_statep state; | 73 | gz_statep state; |
| 73 | int flush; | 74 | int flush; |
| @@ -136,7 +137,8 @@ local int gz_comp(state, flush) | |||
| 136 | return 0; | 137 | return 0; |
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | /* Compress len zeros to output. Return -1 on error, 0 on success. */ | 140 | /* Compress len zeros to output. Return -1 on a write error or memory |
| 141 | allocation failure by gz_comp(), or 0 on success. */ | ||
| 140 | local int gz_zero(state, len) | 142 | local int gz_zero(state, len) |
| 141 | gz_statep state; | 143 | gz_statep state; |
| 142 | z_off64_t len; | 144 | z_off64_t len; |
| @@ -324,23 +326,23 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) | |||
| 324 | 326 | ||
| 325 | /* get internal structure */ | 327 | /* get internal structure */ |
| 326 | if (file == NULL) | 328 | if (file == NULL) |
| 327 | return -1; | 329 | return Z_STREAM_ERROR; |
| 328 | state = (gz_statep)file; | 330 | state = (gz_statep)file; |
| 329 | strm = &(state->strm); | 331 | strm = &(state->strm); |
| 330 | 332 | ||
| 331 | /* check that we're writing and that there's no error */ | 333 | /* check that we're writing and that there's no error */ |
| 332 | if (state->mode != GZ_WRITE || state->err != Z_OK) | 334 | if (state->mode != GZ_WRITE || state->err != Z_OK) |
| 333 | return 0; | 335 | return Z_STREAM_ERROR; |
| 334 | 336 | ||
| 335 | /* make sure we have some buffer space */ | 337 | /* make sure we have some buffer space */ |
| 336 | if (state->size == 0 && gz_init(state) == -1) | 338 | if (state->size == 0 && gz_init(state) == -1) |
| 337 | return 0; | 339 | return state->err; |
| 338 | 340 | ||
| 339 | /* check for seek request */ | 341 | /* check for seek request */ |
| 340 | if (state->seek) { | 342 | if (state->seek) { |
| 341 | state->seek = 0; | 343 | state->seek = 0; |
| 342 | if (gz_zero(state, state->skip) == -1) | 344 | if (gz_zero(state, state->skip) == -1) |
| 343 | return 0; | 345 | return state->err; |
| 344 | } | 346 | } |
| 345 | 347 | ||
| 346 | /* do the printf() into the input buffer, put length in len -- the input | 348 | /* do the printf() into the input buffer, put length in len -- the input |
| @@ -378,7 +380,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) | |||
| 378 | left = strm->avail_in - state->size; | 380 | left = strm->avail_in - state->size; |
| 379 | strm->avail_in = state->size; | 381 | strm->avail_in = state->size; |
| 380 | if (gz_comp(state, Z_NO_FLUSH) == -1) | 382 | if (gz_comp(state, Z_NO_FLUSH) == -1) |
| 381 | return 0; | 383 | return state->err; |
| 382 | memcpy(state->in, state->in + state->size, left); | 384 | memcpy(state->in, state->in + state->size, left); |
| 383 | strm->next_in = state->in; | 385 | strm->next_in = state->in; |
| 384 | strm->avail_in = left; | 386 | strm->avail_in = left; |
| @@ -414,27 +416,27 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | |||
| 414 | 416 | ||
| 415 | /* get internal structure */ | 417 | /* get internal structure */ |
| 416 | if (file == NULL) | 418 | if (file == NULL) |
| 417 | return -1; | 419 | return Z_STREAM_ERROR; |
| 418 | state = (gz_statep)file; | 420 | state = (gz_statep)file; |
| 419 | strm = &(state->strm); | 421 | strm = &(state->strm); |
| 420 | 422 | ||
| 421 | /* check that can really pass pointer in ints */ | 423 | /* check that can really pass pointer in ints */ |
| 422 | if (sizeof(int) != sizeof(void *)) | 424 | if (sizeof(int) != sizeof(void *)) |
| 423 | return 0; | 425 | return Z_STREAM_ERROR; |
| 424 | 426 | ||
| 425 | /* check that we're writing and that there's no error */ | 427 | /* check that we're writing and that there's no error */ |
| 426 | if (state->mode != GZ_WRITE || state->err != Z_OK) | 428 | if (state->mode != GZ_WRITE || state->err != Z_OK) |
| 427 | return 0; | 429 | return Z_STREAM_ERROR; |
| 428 | 430 | ||
| 429 | /* make sure we have some buffer space */ | 431 | /* make sure we have some buffer space */ |
| 430 | if (state->size == 0 && gz_init(state) == -1) | 432 | if (state->size == 0 && gz_init(state) == -1) |
| 431 | return 0; | 433 | return state->error; |
| 432 | 434 | ||
| 433 | /* check for seek request */ | 435 | /* check for seek request */ |
| 434 | if (state->seek) { | 436 | if (state->seek) { |
| 435 | state->seek = 0; | 437 | state->seek = 0; |
| 436 | if (gz_zero(state, state->skip) == -1) | 438 | if (gz_zero(state, state->skip) == -1) |
| 437 | return 0; | 439 | return state->error; |
| 438 | } | 440 | } |
| 439 | 441 | ||
| 440 | /* do the printf() into the input buffer, put length in len -- the input | 442 | /* do the printf() into the input buffer, put length in len -- the input |
| @@ -477,7 +479,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | |||
| 477 | left = strm->avail_in - state->size; | 479 | left = strm->avail_in - state->size; |
| 478 | strm->avail_in = state->size; | 480 | strm->avail_in = state->size; |
| 479 | if (gz_comp(state, Z_NO_FLUSH) == -1) | 481 | if (gz_comp(state, Z_NO_FLUSH) == -1) |
| 480 | return 0; | 482 | return state->err; |
| 481 | memcpy(state->in, state->in + state->size, left); | 483 | memcpy(state->in, state->in + state->size, left); |
| 482 | strm->next_in = state->in; | 484 | strm->next_in = state->in; |
| 483 | strm->avail_in = left; | 485 | strm->avail_in = left; |
| @@ -496,7 +498,7 @@ int ZEXPORT gzflush(file, flush) | |||
| 496 | 498 | ||
| 497 | /* get internal structure */ | 499 | /* get internal structure */ |
| 498 | if (file == NULL) | 500 | if (file == NULL) |
| 499 | return -1; | 501 | return Z_STREAM_ERROR; |
| 500 | state = (gz_statep)file; | 502 | state = (gz_statep)file; |
| 501 | 503 | ||
| 502 | /* check that we're writing and that there's no error */ | 504 | /* check that we're writing and that there's no error */ |
| @@ -511,7 +513,7 @@ int ZEXPORT gzflush(file, flush) | |||
| 511 | if (state->seek) { | 513 | if (state->seek) { |
| 512 | state->seek = 0; | 514 | state->seek = 0; |
| 513 | if (gz_zero(state, state->skip) == -1) | 515 | if (gz_zero(state, state->skip) == -1) |
| 514 | return -1; | 516 | return state->err; |
| 515 | } | 517 | } |
| 516 | 518 | ||
| 517 | /* compress remaining data with requested flush */ | 519 | /* compress remaining data with requested flush */ |
| @@ -546,7 +548,7 @@ int ZEXPORT gzsetparams(file, level, strategy) | |||
| 546 | if (state->seek) { | 548 | if (state->seek) { |
| 547 | state->seek = 0; | 549 | state->seek = 0; |
| 548 | if (gz_zero(state, state->skip) == -1) | 550 | if (gz_zero(state, state->skip) == -1) |
| 549 | return -1; | 551 | return state->err; |
| 550 | } | 552 | } |
| 551 | 553 | ||
| 552 | /* change compression parameters for subsequent input */ | 554 | /* change compression parameters for subsequent input */ |
| @@ -1355,10 +1355,12 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); | |||
| 1355 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); | 1355 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); |
| 1356 | /* | 1356 | /* |
| 1357 | Dynamically update the compression level or strategy. See the description | 1357 | Dynamically update the compression level or strategy. See the description |
| 1358 | of deflateInit2 for the meaning of these parameters. | 1358 | of deflateInit2 for the meaning of these parameters. Previously provided |
| 1359 | data is flushed before the parameter change. | ||
| 1359 | 1360 | ||
| 1360 | gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not | 1361 | gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not |
| 1361 | opened for writing. | 1362 | opened for writing, Z_ERRNO if there is an error writing the flushed data, |
| 1363 | or Z_MEM_ERROR if there is a memory allocation error. | ||
| 1362 | */ | 1364 | */ |
| 1363 | 1365 | ||
| 1364 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | 1366 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); |
| @@ -1401,15 +1403,15 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); | |||
| 1401 | /* | 1403 | /* |
| 1402 | Converts, formats, and writes the arguments to the compressed file under | 1404 | Converts, formats, and writes the arguments to the compressed file under |
| 1403 | control of the format string, as in fprintf. gzprintf returns the number of | 1405 | control of the format string, as in fprintf. gzprintf returns the number of |
| 1404 | uncompressed bytes actually written, or 0 in case of error. The number of | 1406 | uncompressed bytes actually written, or a negative zlib error code in case |
| 1405 | uncompressed bytes written is limited to 8191, or one less than the buffer | 1407 | of error. The number of uncompressed bytes written is limited to 8191, or |
| 1406 | size given to gzbuffer(). The caller should assure that this limit is not | 1408 | one less than the buffer size given to gzbuffer(). The caller should assure |
| 1407 | exceeded. If it is exceeded, then gzprintf() will return an error (0) with | 1409 | that this limit is not exceeded. If it is exceeded, then gzprintf() will |
| 1408 | nothing written. In this case, there may also be a buffer overflow with | 1410 | return an error (0) with nothing written. In this case, there may also be a |
| 1409 | unpredictable consequences, which is possible only if zlib was compiled with | 1411 | buffer overflow with unpredictable consequences, which is possible only if |
| 1410 | the insecure functions sprintf() or vsprintf() because the secure snprintf() | 1412 | zlib was compiled with the insecure functions sprintf() or vsprintf() |
| 1411 | or vsnprintf() functions were not available. This can be determined using | 1413 | because the secure snprintf() or vsnprintf() functions were not available. |
| 1412 | zlibCompileFlags(). | 1414 | This can be determined using zlibCompileFlags(). |
| 1413 | */ | 1415 | */ |
| 1414 | 1416 | ||
| 1415 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); | 1417 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); |
