diff options
Diffstat (limited to 'ext/zip/lib/zip_open.c')
-rw-r--r-- | ext/zip/lib/zip_open.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/ext/zip/lib/zip_open.c b/ext/zip/lib/zip_open.c index 7247b7b8d6..cb3e66d2ca 100644 --- a/ext/zip/lib/zip_open.c +++ b/ext/zip/lib/zip_open.c @@ -310,9 +310,8 @@ static void _zip_check_torrentzip(struct zip *za) { uLong crc_got, crc_should; + char buf[8+1]; char *end; - Bytef buf[BUFSIZE]; - unsigned int n, remain; if (za->zp == NULL || za->cdir == NULL) return; @@ -321,27 +320,17 @@ _zip_check_torrentzip(struct zip *za) || strncmp(za->cdir->comment, TORRENT_SIG, TORRENT_SIG_LEN) != 0) return; + memcpy(buf, za->cdir->comment+TORRENT_SIG_LEN, 8); + buf[8] = '\0'; errno = 0; - crc_should = strtoul(za->cdir->comment+TORRENT_SIG_LEN, &end, 16); + crc_should = strtoul(buf, &end, 16); if ((crc_should == UINT_MAX && errno != 0) || (end && *end)) return; - crc_got = crc32(0L, Z_NULL, 0); - - if (fseek(za->zp, za->cdir->offset, SEEK_SET) != 0) - return; - remain = za->cdir->size; - - while (remain > 0) { - n = remain > BUFSIZE ? BUFSIZE : remain; - if ((n=fread(buf, 1, n, za->zp)) <= 0) + if (_zip_filerange_crc(za->zp, za->cdir->offset, za->cdir->size, + &crc_got, NULL) < 0) return; - crc_got = crc32(crc_got, buf, n); - - remain -= n; - } - if (crc_got == crc_should) za->flags |= ZIP_AFL_TORRENT; } |