summaryrefslogtreecommitdiff
path: root/ext/zip/lib/zip_source_crc.c
diff options
context:
space:
mode:
authorStanley Sufficool <ssufficool@php.net>2014-10-20 21:33:32 -0700
committerStanley Sufficool <ssufficool@php.net>2014-10-20 21:33:32 -0700
commit8defcb855ab01d9c8ab4759cb793d80149b55a8c (patch)
treeed51eb30a2cbc92b102557498fb3e4113da1bb07 /ext/zip/lib/zip_source_crc.c
parent9c7dbb0487f5991fde03873ea8f5e66d6688415f (diff)
parentbaddb1c73a170ef1d2c31bd54cddbc6e1ab596b9 (diff)
downloadphp-git-8defcb855ab01d9c8ab4759cb793d80149b55a8c.tar.gz
Merge branch 'master' of https://git.php.net/push/php-src
* 'master' of https://git.php.net/push/php-src: (6215 commits) Extra comma Moved proxy object support in ASSIGN_ADD (and family) from VM to slow paths of corresponding operators Simplification zend_get_property_info_quick() cleanup and optimization initialize lineno before calling compile file file in phar Use ADDREF instead of DUP, it must be enough. Removed old irrelevant comment fixed compilation error Fix bug #68262: Broken reference across cloned objects export functions needed for phpdbg Fixed compilation Optimized property access handlers. Removed EG(std_property_info). Fixed bug #68199 (PDO::pgsqlGetNotify doesn't support NOTIFY payloads) Don't make difference between undefined and unaccessible properies when call __get() and family Don't make useless CSE array_pop/array_shift optimization check for zlib headers as well as lib for mysqlnd a realpath cache key can be int or float, catching this News entry for new curl constants News entry for new curl constants ...
Diffstat (limited to 'ext/zip/lib/zip_source_crc.c')
-rw-r--r--ext/zip/lib/zip_source_crc.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/ext/zip/lib/zip_source_crc.c b/ext/zip/lib/zip_source_crc.c
index 7fd78f5697..7d6df6a385 100644
--- a/ext/zip/lib/zip_source_crc.c
+++ b/ext/zip/lib/zip_source_crc.c
@@ -38,7 +38,7 @@
#include "zipint.h"
-struct crc {
+struct crc_context {
int eof;
int validate;
int e[2];
@@ -51,23 +51,27 @@ static zip_int64_t crc_read(struct zip_source *, void *, void *
-ZIP_EXTERN(struct zip_source *)
+struct zip_source *
zip_source_crc(struct zip *za, struct zip_source *src, int validate)
{
- struct crc *ctx;
+ struct crc_context *ctx;
if (src == NULL) {
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
}
- if ((ctx=(struct crc *)malloc(sizeof(*ctx))) == NULL) {
+ if ((ctx=(struct crc_context *)malloc(sizeof(*ctx))) == NULL) {
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL;
}
+ ctx->eof = 0;
ctx->validate = validate;
-
+ ctx->e[0] = ctx->e[1] = 0;
+ ctx->size = 0;
+ ctx->crc = 0;
+
return zip_source_layered(za, src, crc_read, ctx);
}
@@ -77,15 +81,15 @@ static zip_int64_t
crc_read(struct zip_source *src, void *_ctx, void *data,
zip_uint64_t len, enum zip_source_cmd cmd)
{
- struct crc *ctx;
+ struct crc_context *ctx;
zip_int64_t n;
- ctx = (struct crc *)_ctx;
+ ctx = (struct crc_context *)_ctx;
switch (cmd) {
case ZIP_SOURCE_OPEN:
ctx->eof = 0;
- ctx->crc = crc32(0, NULL, 0);
+ ctx->crc = (zip_uint32_t)crc32(0, NULL, 0);
ctx->size = 0;
return 0;
@@ -120,8 +124,8 @@ crc_read(struct zip_source *src, void *_ctx, void *data,
}
}
else {
- ctx->size += n;
- ctx->crc = crc32(ctx->crc, data, n);
+ ctx->size += (zip_uint64_t)n;
+ ctx->crc = (zip_uint32_t)crc32(ctx->crc, (const Bytef *)data, (uInt)n); /* TODO: check for overflow, use multiple crc calls if needed */
}
return n;
@@ -135,11 +139,14 @@ crc_read(struct zip_source *src, void *_ctx, void *data,
st = (struct zip_stat *)data;
if (ctx->eof) {
- /* XXX: Set comp_size, comp_method, encryption_method?
+ /* TODO: Set comp_size, comp_method, encryption_method?
After all, this only works for uncompressed data. */
st->size = ctx->size;
st->crc = ctx->crc;
- st->valid |= ZIP_STAT_SIZE|ZIP_STAT_CRC;
+ st->comp_size = ctx->size;
+ st->comp_method = ZIP_CM_STORE;
+ st->encryption_method = ZIP_EM_NONE;
+ st->valid |= ZIP_STAT_SIZE|ZIP_STAT_CRC|ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD|ZIP_STAT_ENCRYPTION_METHOD;;
}
}
return 0;