ID:               48763
 User updated by:  dani dot church at gmail dot com
 Reported By:      dani dot church at gmail dot com
 Status:           Open
 Bug Type:         Zip Related
 Operating System: CentOS 5
 PHP Version:      5.2CVS-2009-07-01 (snap)
 New Comment:

I sampled the compressed file using statName() three times: once before
updating it, once after the addFromString() call, and once after closing
the ZIP and reopening it from another object.  The results:

Original file: Array
(
    [name] => content.xml
    [index] => 11
    [crc] => 2790848447
    [size] => 16096
    [mtime] => 1246486396
    [comp_size] => 2379
    [comp_method] => 8
)
Compressed, not saved: Array
(
    [name] => content.xml
    [index] => 20
    [crc] => 0
    [size] => 16096
    [mtime] => 1246493476
    [comp_size] => -1
    [comp_method] => 0
)
Compressed and reopened: Array
(
    [name] => content.xml
    [index] => 19
    [crc] => 2790848447
    [size] => 16096
    [mtime] => 1246493476
    [comp_size] => 2355
    [comp_method] => 8
)

Notably, the compression method is the same, which means that PHP is
not trying to use a compression method that OpenOffice.org does not
support.


Previous Comments:
------------------------------------------------------------------------

[2009-07-01 23:48:05] dani dot church at gmail dot com

Description:
------------
When PHP writes a .od* file using ZipArchive, the resulting archive
cannot be opened by OpenOffice.org.  The error it gives is "The file
'filename' is corrupt and therefore cannot be opened.  Should
OpenOffice.org repair the file?"

Repairing the file in OO.o does not work.  However, unzipping the file
from the command line (using unzip in OSX) works without error, and
unzip -t (test integrity) reports no errors.  Furthermore, the extracted
files are byte-correct, and zipping the extracted files into a new .od*
file results in a valid OpenOffice.org file.

This bug is a regression since 5.2.6.  Using zip.so from 5.2.6 results
in a valid file.  Using zip.so from 5.2CVS-2009-07-01 results in a
corrupt file.

Reproduce code:
---------------
<?php
if (isset($_FILES['od'])) {
  $odfile = $_FILES['od']['tmp_name'];
  $zip = new ZipArchive();
  $zip->open($odfile);
  $xml = $zip->getFromName('content.xml');
  $zip->addFromString('content.xml', $xml);
  $zip->close();
  header('content-type:
application/vnd.oasis.opendocument.spreadsheet');
  header('content-disposition: attachment;filename=test.ods');
  readfile($odfile);
  unlink($odfile);
  return;
}
?>
<form method="POST" enctype="multipart/form-data">
<input type='file' name='od'
<input type='submit'>
</form>

Expected result:
----------------
Using the above testbed (for ODS spreadsheets) to update content.xml
with its own data should result in a valid ODS spreadsheet.

Actual result:
--------------
The resulting spreadsheet is corrupt and cannot be opened.


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


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

Reply via email to