summaryrefslogtreecommitdiff
path: root/ext/zip/lib/zip_fread.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zip/lib/zip_fread.c')
-rw-r--r--ext/zip/lib/zip_fread.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/ext/zip/lib/zip_fread.c b/ext/zip/lib/zip_fread.c
index c0b71b861..00a6bdc4e 100644
--- a/ext/zip/lib/zip_fread.c
+++ b/ext/zip/lib/zip_fread.c
@@ -63,7 +63,7 @@ zip_fread(struct zip_file *zf, void *outbuf, size_t toread)
}
return 0;
}
-
+
if ((zf->flags & ZIP_ZF_DECOMP) == 0) {
ret = _zip_file_fillbuf(outbuf, toread, zf);
if (ret > 0) {
@@ -84,25 +84,22 @@ zip_fread(struct zip_file *zf, void *outbuf, size_t toread)
switch (ret) {
case Z_STREAM_END:
- zf->flags |= ZIP_ZF_EOF;
+ if (zf->zstr->total_out == out_before) {
+ if (zf->crc != zf->crc_orig) {
+ _zip_error_set(&zf->error, ZIP_ER_CRC, 0);
+ return -1;
+ }
+ else
+ return 0;
+ }
- case Z_OK:
+ /* fallthrough */
- /* all ok */
- /* Z_STREAM_END probably won't happen, since we didn't
- have a header */
+ case Z_OK:
len = zf->zstr->total_out - out_before;
if (len >= zf->bytes_left || len >= toread) {
- if (zf->flags & ZIP_ZF_CRC) {
- zf->crc = crc32(zf->crc, (Bytef *)outbuf, len);
- if (zf->flags & ZIP_ZF_EOF == 1) {
- if (zf->crc != zf->crc_orig) {
- _zip_error_set(&zf->error, ZIP_ER_CRC, 0);
- return -1;
- }
-
- }
- }
+ if (zf->flags & ZIP_ZF_CRC)
+ zf->crc = crc32(zf->crc, (Bytef *)outbuf, len);
zf->bytes_left -= len;
return len;
}