[php-src] Issue #11044: php-pecl-zip fread(): Zip stream error: Containing zip archive was closed
| From: | bobxiaoxiong | Date: | Mon, 10 Apr 2023 02:02:44 +0000 |
| Subject: | [php-src] Issue #11044: php-pecl-zip fread(): Zip stream error: Containing zip archive was closed | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244159@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11044
Author: bobxiaoxiong
### Description
no problem version php-pecl-zip-1.19.3
static ZIPARCHIVE_METHOD(getStream)
{
struct zip *intern;
zval *self = getThis();
struct zip_stat sb;
char *mode = "rb";
zend_string *filename;
php_stream *stream;
ze_zip_object *obj;
if (!self) {
RETURN_FALSE;
}
ZIP_FROM_OBJECT(intern, self);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
return;
}
if (zip_stat(intern, ZSTR_VAL(filename), 0, &sb) != 0) {
RETURN_FALSE;
}
obj = Z_ZIP_P(self);
stream = php_stream_zip_open(obj->filename, ZSTR_VAL(filename), mode STREAMS_CC);
if (stream) {
php_stream_to_zval(stream, return_value);
} else {
RETURN_FALSE;
}
}
php_stream *php_stream_zip_open(const char *filename, const char *path, const char *mode STREAMS_DC)
{
struct zip_file *zf = NULL;
int err = 0;
php_stream *stream = NULL;
struct php_zip_stream_data_t *self;
struct zip *stream_za;
if (strncmp(mode,"r", strlen("r")) != 0) {
return NULL;
}
if (filename) {
if (ZIP_OPENBASEDIR_CHECKPATH(filename)) {
return NULL;
}
/* duplicate to make the stream za independent (esp. for MSHUTDOWN) */
stream_za = zip_open(filename, ZIP_CREATE, &err);
if (!stream_za) {
return NULL;
}
zf = zip_fopen(stream_za, path, 0);
if (zf) {
self = emalloc(sizeof(*self));
self->za = stream_za;
self->zf = zf;
self->stream = NULL;
self->cursor = 0;
stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode);
stream->orig_path = estrdup(path);
} else {
zip_close(stream_za);
}
}
if (!stream) {
return NULL;
} else {
return stream;
}
}
problem version php-pecl-zip-1.19.4
static ZIPARCHIVE_METHOD(getStream)
{
struct zip *intern;
zval *self = getThis();
struct zip_stat sb;
char *mode = "rb";
zend_string *filename;
php_stream *stream;
if (!self) {
RETURN_FALSE;
}
ZIP_FROM_OBJECT(intern, self);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
return;
}
if (zip_stat(intern, ZSTR_VAL(filename), 0, &sb) != 0) {
RETURN_FALSE;
}
stream = php_stream_zip_open(intern, ZSTR_VAL(filename), mode STREAMS_CC);
if (stream) {
php_stream_to_zval(stream, return_value);
} else {
RETURN_FALSE;
}
}
php_stream *php_stream_zip_open(struct zip *arch, const char *path, const char *mode STREAMS_DC)
{
struct zip_file *zf = NULL;
php_stream *stream = NULL;
struct php_zip_stream_data_t *self;
if (strncmp(mode,"r", strlen("r")) != 0) {
return NULL;
}
if (arch) {
zf = zip_fopen(arch, path, 0);
if (zf) {
self = emalloc(sizeof(*self));
self->za = NULL; /* to keep it open on stream close */
self->zf = zf;
self->stream = NULL;
self->cursor = 0;
stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode);
stream->orig_path = estrdup(path);
}
}
if (!stream) {
return NULL;
} else {
return stream;
}
}
After multiple method encapsulation calls in version 1.91.4, resources were lost. I think it may be
due to the release of resources.
### PHP Version
php7.1.33
### Operating System
_No response_