summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2022-01-01 12:09:30 -0800
committerMark Adler <madler@alumni.caltech.edu>2022-01-01 12:09:30 -0800
commit58ca4e57ce7d76734d8b5afa03d205f694419b17 (patch)
tree985010c20c77684e9825fd1e134b602800d28773
parentb135d46eaf5ba36b549be9db857c580f00b6182a (diff)
downloadzlib-58ca4e57ce7d76734d8b5afa03d205f694419b17.tar.gz
zlib-58ca4e57ce7d76734d8b5afa03d205f694419b17.tar.bz2
zlib-58ca4e57ce7d76734d8b5afa03d205f694419b17.zip
Fix unztell64() in minizip to work past 4GB. (Daniël Hörchner)
The issue is that unztell64() does not return the correct value if the position in the current file (in the ZIP archive) is beyond 4 GB. The cause is that unzReadCurrentFile() does not account for pfile_in_zip_read_info->stream.total_out at line 1854 of unzip.c wrapping around (it is a 32-bit variable). So, on line 1860 uTotalOutAfter can be *less* than uTotalOutBefore, propagating the wraparound to uOutThis, which in turn is added to pfile_in_zip_read_info->total_out_64. That has the effect of subtracting 4 GB.
-rw-r--r--contrib/minizip/unzip.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index bcfb941..b16a75e 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -1857,6 +1857,9 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1857 err = Z_DATA_ERROR; 1857 err = Z_DATA_ERROR;
1858 1858
1859 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1859 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1860 /* Detect overflow, because z_stream.total_out is uLong (32 bits) */
1861 if (uTotalOutAfter<uTotalOutBefore)
1862 uTotalOutAfter += 1LL << 32; /* Add maximum value of uLong + 1 */
1860 uOutThis = uTotalOutAfter-uTotalOutBefore; 1863 uOutThis = uTotalOutAfter-uTotalOutBefore;
1861 1864
1862 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; 1865 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;