php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53587 "Seek error: Invalid argument" when creating ZIP larger than 2GB on 32bit arch
Submitted: 2010-12-21 11:23 UTC Modified: 2021-07-19 13:29 UTC
Votes:7
Avg. Score:4.0 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:2 (40.0%)
From: jerome dot auge at anakeen dot com Assigned: cmb (profile)
Status: Not a bug Package: Zip Related
PHP Version: 5.6.9 OS: Linux, Mac OS X (x86)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
41 - 24 = ?
Subscribe to this entry?

 
 [2010-12-21 11:23 UTC] jerome dot auge at anakeen dot com
Description:
------------
On 32bit system, you can't generate ZIP files larger than 2GB.

I reproduce this with :
- PHP 5.3.4 on Mac OS 10.5 i686

Also observed with :
- PHP 5.2.4 on Ubuntu 8.04 i686
- PHP 5.3.2 on Ubuntu 10.04 i686

I tested with 3 files of 1GB random data. After adding the 3 files, the $zip-
>close() returns the error "Seek error: Invalid argument" and there is no zip 
output file.

After looking into ext/zip, it seems that the problem is in the use of "unsigned 
long" types instead of the "off_t" type in zip_cdir struct, and the fact that 
the HAVE_FSEEKO and HAVE_FTELLO are not detected/defined by the ./configure 
script.

On OS X (PHP 5.3.4), if I recompile the ext/zip extension by hand with the patch 
below (force HAVE_FSEEKO/HAVE_FTELLO and adjust the "unsigned long" to "off_t" 
in zip_cdir struct), then I can create my ZIP archive larger than 2GB.


Test script:
---------------
#!/bin/bash

# -- Create 3 files of 1GB random data

for I in 1 2 3; do dd if=/dev/urandom of=f$I bs=1M count=1024; done

# -- Create a 'out.zip' archive containing these 3 files

php -r '$zip = new ZipArchive(); $zip->open("out.zip", ZIPARCHIVE::CREATE); $zip->addFile("f1"); $zip->addFile("f2"); $zip->addFile("f3"); $ret = $zip->close(); if( $ret === false ) { print sprintf("Error: %s", $zip->getStatusString()); };'

zip -T out.zip
if [ $? -ne 0 ]; then
  echo "ERROR"
  exit 1
fi

echo "OK"
exit 0

Expected result:
----------------
A ZIP archive with a size around 3GB that passes the `zip -T' verification.

Actual result:
--------------
$zip->close() returns false with error "Seek error: Invalid argument", and the ZIP 
output file is not produced.

Patches

php-5.3-zip_fseeko.patch (last revision 2010-12-21 10:27 UTC by jerome dot auge at anakeen dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-21 16:16 UTC] jerome dot auge at anakeen dot com
-Package: *Compression related +Package: Zip Related
 [2010-12-21 16:16 UTC] jerome dot auge at anakeen dot com
Package: "Zip Related"
 [2015-05-18 18:34 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2015-05-18 18:34 UTC] cmb@php.net
Zip64 support is supposed to be available since libzip 0.11. As of
PHP 5.6.8 libzip 0.11.2 or newer are bundled. For older PHP
versions PECL provides up-to-date zip extension packages (use
1.12.4 or newer): <https://pecl.php.net/package/zip>

Can you confirm that the issue is solved with latest PHP resp.
PECL zip versions?
 [2015-05-31 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2015-05-31 09:35 UTC] jerome dot auge at anakeen dot com
I compiled php-5.6.9 on Debian 8 i686 with `./configure --enable-zip`, and my test fails: the output Zip file is not created and no error is reported (neither from Zip::addFile() nor Zip::close()).
 [2015-05-31 14:44 UTC] cmb@php.net
-Status: No Feedback +Status: Open
 [2015-05-31 21:48 UTC] cmb@php.net
-Status: Assigned +Status: Verified -Operating System: Linux, Mac OS X +Operating System: Linux, Mac OS X (x86) -PHP Version: 5.3.4 +PHP Version: 5.6.9 -Assigned To: cmb +Assigned To:
 [2015-05-31 21:48 UTC] cmb@php.net
I can confirm this issue for Debian 8 i386 (no problems on Xubuntu
15.04 x64, though). Even if creating Zip64s is not supposed to work
on x86 platforms, at least the error should be indicated.
 [2021-07-19 13:29 UTC] cmb@php.net
-Status: Verified +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-07-19 13:29 UTC] cmb@php.net
libzip is unbundled as of PHP 7.4.0, so this is no longer a PHP
issue.  If you still experience this problem, please report
upstream: <https://github.com/nih-at/libzip/issues>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC