Skip to content

Commit 8ca457f

Browse files
committed
fixed bc break related to #57905
1 parent e883892 commit 8ca457f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ext/zip/lib/zip_open.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ _zip_readcdir(FILE *fp, off_t buf_offset, unsigned char *buf, unsigned char *eoc
206206
cd->comment = NULL;
207207
cd->comment_len = _zip_read2(&cdp);
208208

209-
if (((zip_uint64_t)cd->offset)+cd->size > buf_offset + (eocd-buf)) {
209+
/* without checking the ZIP_CHECKCONS flag we'll not able even to open inconsistent
210+
archives at this place, which would break bc in PHP */
211+
if ((ZIP_CHECKCONS == (flags & ZIP_CHECKCONS)) && ((zip_uint64_t)cd->offset)+cd->size > buf_offset + (eocd-buf)) {
210212
/* cdir spans past EOCD record */
211213
_zip_error_set(error, ZIP_ER_INCONS, 0);
212214
cd->nentry = 0;
@@ -237,7 +239,13 @@ _zip_readcdir(FILE *fp, off_t buf_offset, unsigned char *buf, unsigned char *eoc
237239
}
238240
}
239241

240-
if (cd->offset >= buf_offset) {
242+
/* the first if branch goes the old way of libzip 0.9 so we don't loose
243+
the bc for reading inconsistent files */
244+
if ((ZIP_CHECKCONS != (flags & ZIP_CHECKCONS)) && cd->size < (unsigned int)(eocd-buf)) {
245+
cdp = eocd - cd->size;
246+
bufp = &cdp;
247+
}
248+
else if (cd->offset >= buf_offset) {
241249
/* if buffer already read in, use it */
242250
cdp = buf + (cd->offset - buf_offset);
243251
bufp = &cdp;

0 commit comments

Comments
 (0)