php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54485 extractTo reports success even in case of write error
Submitted: 2011-04-07 15:02 UTC Modified: 2013-02-18 00:34 UTC
From: arno at renevier dot net Assigned: pajoye (profile)
Status: No Feedback Package: Zip Related
PHP Version: 5.3SVN-2011-04-07 (snap) OS: linux
Private report: No CVE-ID: None
 [2011-04-07 15:02 UTC] arno at renevier dot net
Description:
------------
Hi,
I've encountered the bug when trying to unzip a file into a full disk.

ZipArchive::extractTo reported true, but the extracted file had a 0 size.
It would be nice if extractTo had reported false, so I could have known something was wrong.

I've experienced the bug with debian php 5.3.6-7 and with php build from php5.3-201104071030.tar.bz2 with ./configure --enable-zip && make

May be php_zip_extract_file could return 0 if php_stream_write returns 0 in the n=zip_fread loop

PS: this bug may be the same as #53893 but as I'm unsure, I prefer to open a new one.

Test script:
---------------
function unzip ($file) {
    $za = new \ZipArchive();
    if ($za->open($file) === FALSE) {
        throw new Exception ("invalid zip file " . $file);
    }
    if ($za->numFiles != 1) {
        throw new Exception ("invalid zip file " . $file);
    }
    if (($archive = $za->getNameIndex(0)) === FALSE) {
        throw new Exception ("invalid zip file " . $file);
    }
    if ($za->extractTo('target', $archive) === FALSE) {
        throw new Exception ("could not extract archive " . $archive);
    }
    if ($za->close() === FALSE) {
        throw new Exception ("could not extract archive " . $archive);
    }
}

unzip('somefile.zip');

Expected result:
----------------
the script should throw an exception.

Actual result:
--------------
no exception is thrown.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-07 15:05 UTC] pajoye@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: pajoye
 [2011-04-07 15:05 UTC] pajoye@php.net
Please provide a standalone reproduce case. Is the error due to the zip archive or 
the destination directory (not writable, etc.)?
 [2011-04-07 15:15 UTC] arno at renevier dot net
> Is the error due to the zip archive or the destination directory (not writable, etc.)?

As I told in the bug report, the bug appears when the destination directory is a full device (no space left).

> Please provide a standalone reproduce case.

the script I paste triggers the bug for any zip file named somefile.zip when target is directory on a full disk. Here are instructions to create a zip file:

$ echo "something" > readme.txt
$ zip readme.txt somefile.zip

Here are the instructions to make target look like a full device (you may need root permissions at some point):

$ dd if=/dev/zero of=file bs=4M count=1
$ mkdir target
$ losetup /dev/loop0 file
$ mkfs.ext3 /dev/loop0
$ mkdir target
$ mount /dev/loop0 target
$ cd target/
$ dd if=/dev/zero of=full bs=4M count=1
 [2013-02-18 00:34 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 "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC