Skip to content

Commit 8ad0c6d

Browse files
committed
- MFH:
- fix possible leak in statName and statIndex - add addEmptyDir() method - add zip_stat_init,zip_clear_error and zip_file_clear_error - add tests - Fix protos (Hannes) - setComment return value on success (Hannes)
1 parent c002606 commit 8ad0c6d

25 files changed

Lines changed: 681 additions & 78 deletions

‎ext/zip/TODO‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
- fix _zip_replace (add two entries with the same name segfaults)
21
- add pattern support to extract or add files
32
- stream to add or modify entries
43
- crypt support for zip (read and write)

‎ext/zip/config.m4‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ if test "$PHP_ZIP" != "no"; then
5959
lib/zip_entry_new.c lib/zip_err_str.c lib/zip_fopen_index.c \
6060
lib/zip_new.c lib/zip_source_file.c lib/zip_stat_index.c lib/zip_get_archive_comment.c \
6161
lib/zip_get_file_comment.c lib/zip_set_archive_comment.c lib/zip_set_file_comment.c \
62-
lib/zip_unchange_archive.c lib/zip_memdup.c"
62+
lib/zip_unchange_archive.c lib/zip_memdup.c lib/zip_stat_init.c lib/zip_add_dir.c \
63+
lib/zip_error_clear.c lib/zip_file_error_clear.c"
6364

6465
AC_DEFINE(HAVE_ZIP,1,[ ])
6566
PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared)

‎ext/zip/config.w32‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ if (PHP_ZIP != "no") {
2626
zip_new.c zip_source_file.c zip_stat_index.c \
2727
zip_get_archive_comment.c zip_get_file_comment.c \
2828
zip_set_archive_comment.c zip_set_file_comment.c \
29-
zip_unchange_archive.c zip_memdup.c", "zip");
29+
zip_unchange_archive.c zip_memdup.c zip_stat_init.c \
30+
zip_add_dir.c zip_file_error_clear.c zip_error_clear.c", "zip");
3031

3132
AC_DEFINE('HAVE_ZLIB', 1);
3233
AC_DEFINE('HAVE_ZIP', 1);

‎ext/zip/lib/zip.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,15 @@ struct zip_source;
163163

164164

165165
int zip_add(struct zip *, const char *, struct zip_source *);
166+
int zip_add_dir(struct zip *, const char *);
166167
int zip_close(struct zip *);
167168
int zip_delete(struct zip *, int);
169+
void zip_error_clear(struct zip *);
168170
void zip_error_get(struct zip *, int *, int *);
169171
int zip_error_get_sys_type(int);
170172
int zip_error_to_str(char *, size_t, int, int);
171173
int zip_fclose(struct zip_file *);
174+
void zip_file_error_clear(struct zip_file *);
172175
void zip_file_error_get(struct zip_file *, int *, int *);
173176
const char *zip_file_strerror(struct zip_file *);
174177
struct zip_file *zip_fopen(struct zip *, const char *, int);
@@ -194,6 +197,7 @@ struct zip_source *zip_source_zip(struct zip *, struct zip *, int, int,
194197
off_t, off_t);
195198
int zip_stat(struct zip *, const char *, int, struct zip_stat *);
196199
int zip_stat_index(struct zip *, int, int, struct zip_stat *);
200+
void zip_stat_init(struct zip_stat *);
197201
const char *zip_strerror(struct zip *);
198202
int zip_unchange(struct zip *, int);
199203
int zip_unchange_all(struct zip *);

‎ext/zip/lib/zip_add_dir.c‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
$NiH: zip_add_dir.c,v 1.1 2006/10/03 12:23:13 dillo Exp $
3+
4+
zip_add_dir.c -- add directory
5+
Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
6+
7+
This file is part of libzip, a library to manipulate ZIP archives.
8+
The authors can be contacted at <nih@giga.or.at>
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions
12+
are met:
13+
1. Redistributions of source code must retain the above copyright
14+
notice, this list of conditions and the following disclaimer.
15+
2. Redistributions in binary form must reproduce the above copyright
16+
notice, this list of conditions and the following disclaimer in
17+
the documentation and/or other materials provided with the
18+
distribution.
19+
3. The names of the authors may not be used to endorse or promote
20+
products derived from this software without specific prior
21+
written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
24+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
37+
38+
#include <stdlib.h>
39+
#include <string.h>
40+
41+
#include "zip.h"
42+
#include "zipint.h"
43+
44+
45+
46+
int
47+
zip_add_dir(struct zip *za, const char *name)
48+
{
49+
int len, ret;
50+
char *s;
51+
struct zip_source *source;
52+
53+
if (name == NULL) {
54+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
55+
return -1;
56+
}
57+
58+
s = NULL;
59+
len = strlen(name);
60+
61+
if (name[len-1] != '/') {
62+
if ((s=(char *)malloc(len+2)) == NULL) {
63+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
64+
return -1;
65+
}
66+
strcpy(s, name);
67+
s[len] = '/';
68+
s[len+1] = '\0';
69+
}
70+
71+
if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) {
72+
free(s);
73+
return -1;
74+
}
75+
76+
ret = _zip_replace(za, -1, s ? s : name, source);
77+
78+
free(s);
79+
if (ret < 0)
80+
zip_source_free(source);
81+
82+
return ret;
83+
}

‎ext/zip/lib/zip_error.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$NiH: zip_error.c,v 1.7 2005/06/09 19:57:09 dillo Exp $
33
44
zip_error.c -- struct zip_error helper functions
5-
Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
5+
Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
66
77
This file is part of libzip, a library to manipulate ZIP archives.
88
The authors can be contacted at <nih@giga.or.at>
@@ -42,6 +42,15 @@
4242

4343

4444

45+
void
46+
_zip_error_clear(struct zip_error *err)
47+
{
48+
err->zip_err = ZIP_ER_OK;
49+
err->sys_err = 0;
50+
}
51+
52+
53+
4554
void
4655
_zip_error_copy(struct zip_error *dst, struct zip_error *src)
4756
{
@@ -78,7 +87,7 @@ _zip_error_get(struct zip_error *err, int *zep, int *sep)
7887
void
7988
_zip_error_init(struct zip_error *err)
8089
{
81-
err->zip_err = 0;
90+
err->zip_err = ZIP_ER_OK;
8291
err->sys_err = 0;
8392
err->str = NULL;
8493
}

‎ext/zip/lib/zip_error_clear.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
$NiH: zip_error_clear.c,v 1.1 2006/10/04 15:21:09 dillo Exp $
3+
4+
zip_error_clear.c -- clear zip error
5+
Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
6+
7+
This file is part of libzip, a library to manipulate ZIP archives.
8+
The authors can be contacted at <nih@giga.or.at>
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions
12+
are met:
13+
1. Redistributions of source code must retain the above copyright
14+
notice, this list of conditions and the following disclaimer.
15+
2. Redistributions in binary form must reproduce the above copyright
16+
notice, this list of conditions and the following disclaimer in
17+
the documentation and/or other materials provided with the
18+
distribution.
19+
3. The names of the authors may not be used to endorse or promote
20+
products derived from this software without specific prior
21+
written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
24+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
37+
38+
#include "zip.h"
39+
#include "zipint.h"
40+
41+
42+
43+
void
44+
zip_error_clear(struct zip *za)
45+
{
46+
_zip_error_clear(&za->error);
47+
}

‎ext/zip/lib/zip_file_error_clear.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
$NiH: zip_file_error_clear.c,v 1.4 2006/10/04 18:37:54 wiz Exp $
3+
4+
zip_file_error_clear.c -- clear zip file error
5+
Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
6+
7+
This file is part of libzip, a library to manipulate ZIP archives.
8+
The authors can be contacted at <nih@giga.or.at>
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions
12+
are met:
13+
1. Redistributions of source code must retain the above copyright
14+
notice, this list of conditions and the following disclaimer.
15+
2. Redistributions in binary form must reproduce the above copyright
16+
notice, this list of conditions and the following disclaimer in
17+
the documentation and/or other materials provided with the
18+
distribution.
19+
3. The names of the authors may not be used to endorse or promote
20+
products derived from this software without specific prior
21+
written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
24+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
37+
38+
#include "zip.h"
39+
#include "zipint.h"
40+
41+
42+
43+
void
44+
zip_file_error_clear(struct zip_file *zf)
45+
{
46+
_zip_error_clear(&zf->error);
47+
}

‎ext/zip/lib/zip_get_archive_comment.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ zip_get_archive_comment(struct zip *za, int *lenp, int flags)
4747
|| (za->ch_comment_len == -1)) {
4848
if (za->cdir) {
4949
if (lenp != NULL)
50-
*lenp = za->cdir->comment_len;
50+
*lenp = za->cdir->comment_len;
5151
return za->cdir->comment;
5252
}
5353
}

‎ext/zip/lib/zip_source_buffer.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$NiH: zip_source_buffer.c,v 1.8 2006/04/23 14:50:49 wiz Exp $
33
44
zip_source_buffer.c -- create zip data source from buffer
5-
Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
5+
Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
66
77
This file is part of libzip, a library to manipulate ZIP archives.
88
The authors can be contacted at <nih@giga.or.at>
@@ -125,11 +125,9 @@ read_data(void *state, void *data, size_t len, enum zip_source_cmd cmd)
125125

126126
st = (struct zip_stat *)data;
127127

128+
zip_stat_init(st);
128129
st->mtime = z->mtime;
129-
st->crc = 0;
130130
st->size = z->end - z->data;
131-
st->comp_size = -1;
132-
st->comp_method = ZIP_CM_STORE;
133131

134132
return sizeof(*st);
135133
}

0 commit comments

Comments
 (0)