Bug #66445 [Csd]: ZipArchive doesn't set external file attributes

From: Date: Fri, 17 Jan 2014 07:44:47 +0000
Subject: Bug #66445 [Csd]: ZipArchive doesn't set external file attributes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183857@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66445&edit=1

 ID:                 66445
 Updated by:         ab@php.net
 Reported by:        cmbecker69 at gmx dot de
 Summary:            ZipArchive doesn't set external file attributes
 Status:             Closed
 Type:               Bug
 Package:            Zip Related
 Operating System:   Windows
 PHP Version:        5.5.7
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

Ah, and check this commit https://github.com/pierrejoye/php_zip/commit/54a2044f2beab17de77446958fdb11d683f4e61a
, external attributes can be now manipulated in PHP.


Previous Comments:
------------------------------------------------------------------------
[2014-01-17 07:41:23] ab@php.net

Hi, thanks for investing so much time in this. libzip 0.11.2 is the base also for the latest zip ext
released on PECL. It could be used with PHP <= 5.6, too.

------------------------------------------------------------------------
[2014-01-16 18:57:29] cmbecker69 at gmx dot de

I had a look at libzip.  Apparently, the respective member ext_attrib
of struct zip_dirent is always set to 0 (unless read from an already
existing archive).  This happens in _zip_dirent_init()[1] and a few
other places in the same file.

I have compared that with the latest release of libzip[2] (0.11.2),
and there the member is initialized to ZIP_EXT_ATTRIB_DEFAULT, which
doesn't set the low byte (neither does ZIP_EXT_ATTRIB_DEFAULT_DIR).
However, there is a new function zip_file_set_external_attributes()[3]
which might do so.

Then I noticed that libzip in the PHP 5.6 branch was updated.
Running the test script above showed that the "version made by" is
now 0x0314, what means UNIX.  This change was introduced in libzip
0.11.2.[4]  AFAICT this is conforming to the PKWARE specification,
but newly created archives have the same issues in Windows XP's
explorer---apparently, this is a bug in XP's explorer, so I closed
the bug report.

[1] <http://lxr.php.net/xref/PHP_5_5/ext/zip/lib/zip_dirent.c#184>
[2] <http://nih.at/libzip/index.html>
[3] <http://hg.nih.at/libzip/file/5e14f593fbdd/lib/zip_file_set_external_attributes.c>
[4] <http://hg.nih.at/libzip/rev/2cb9b3e21031>

------------------------------------------------------------------------
[2014-01-10 12:14:45] cmbecker69 at gmx dot de

For automated testing it might be sufficient to scan the zip file
for central file header signatures (section 4.3.12 of the PKWARE
specification) and inspect the first byte of the external file 
attributes.  Telling files and directories apart seems to be harder
in the general case.  Assuming there are no empty files in the 
archive, it would suffice to check for the (un)compressed size.
Alternatively, one might check the last character of the file name,
assuming all directory names are stored with a trailing slash.

------------------------------------------------------------------------
[2014-01-10 07:42:05] ab@php.net

libzip is the one responsible for that.

Btw. how do you check that programmatically? Looks impossible, as one would need to reparse the
whole file manually.

------------------------------------------------------------------------
[2014-01-08 21:00:37] cmbecker69 at gmx dot de

Description:
------------
The ZipArchive class doesn't set the external file attributes,
what is a particular problem regarding directories which are 
displayed as files in Windows XP's explorer (works fine in Win 7,
though; can't tests other Windows versions).

According to the PKWARE Zip specification[1], section 4.4.15:

| The mapping of the external attributes is
| host-system dependent (see 'version made by').  For
| MS-DOS, the low order byte is the MS-DOS directory
| attribute byte.

The "version made by" field in the created ZIP file is 0, what 
signals MSDOS, but the low order byte of the "external file 
attributes" field is always 0 (should be 0x10 for directories). 

[1] <http://www.pkware.com/documents/casestudies/APPNOTE.TXT>

Test script:
---------------
$zip = new ZipArchive();
$zip->open('foo.zip', ZipArchive::CREATE);
$zip->addEmptyDir('bar');
$zip->close();


Expected result:
----------------
A ZIP file conforming to the PKWARE specification is created.

Actual result:
--------------
The created ZIP file doesn't conform to the PKWARE specification.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=66445&edit=1


Thread (7 messages)

« previous php.bugs (#183857) next »