Re: [PHP] gzuncompress() Not Working.

2007-11-07 Thread Per Jessen
[EMAIL PROTECTED] wrote:

 The documentation for zlib says that it expects an Adler-32 checksum
 at the end of the file.
 
 PHP follows this [largely outdated] standard.

Uh, nothing to do with PHP, the code is in zlib. 

 Python, on the other hand, doesn't, and uses a different checksum,
 CRC-32.

There's something crooked going here. No-one should have to write up
work-arounds for weird incompatibilities in the gzip format.  The
problem is - why is Python using an incorrect checksum?  And is Python
not using the zlib library?

http://www.python.org/doc/lib/module-zlib.html

From this page:

There are known incompatibilities between the Python module and
versions of the zlib library earlier than 1.1.3; 1.1.3 has a security
vulnerability, so we recommend using 1.1.4 or later.

Do you have the right zlib version?  Mine is 1.2.3. 

If your work-around works, well, fine.  Personally I'd dig a little
deeper.  I would positively hate having that kind of crud in my
production code.


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-07 Thread heavyccasey
They're exactly the same, except of the last 4 bytes. Python
calculates them differently than PHP. PHP follows the standards,
Python does not :]

This would be more concise if PHP included the gzdecode
(http://us2.php.net/gzdecode) function.

On Nov 7, 2007 12:12 AM, Per Jessen [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

  The documentation for zlib says that it expects an Adler-32 checksum
  at the end of the file.
 
  PHP follows this [largely outdated] standard.

 Uh, nothing to do with PHP, the code is in zlib.

  Python, on the other hand, doesn't, and uses a different checksum,
  CRC-32.

 There's something crooked going here. No-one should have to write up
 work-arounds for weird incompatibilities in the gzip format.  The
 problem is - why is Python using an incorrect checksum?  And is Python
 not using the zlib library?

 http://www.python.org/doc/lib/module-zlib.html

 From this page:

 There are known incompatibilities between the Python module and
 versions of the zlib library earlier than 1.1.3; 1.1.3 has a security
 vulnerability, so we recommend using 1.1.4 or later.

 Do you have the right zlib version?  Mine is 1.2.3.

 If your work-around works, well, fine.  Personally I'd dig a little
 deeper.  I would positively hate having that kind of crud in my
 production code.



 /Per Jessen, Zürich

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-07 Thread Per Jessen
[EMAIL PROTECTED] wrote:

 They're exactly the same, except of the last 4 bytes. Python
 calculates them differently than PHP. PHP follows the standards,
 Python does not :]

That is exactly what is so weird - does Python maybe have its own
implementation of the gzip compression algorithm?   I would have
thought they both used the same zlib. 


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-07 Thread heavyccasey
In my tests, Python can parse both Adler-32 and CRC32, while PHP can
only do Adler-32.

Anyways, I shortened my function:
function fixAdler32($data) {
static $f;
if (!isset($f)) $f = tempnam('/tmp', 'gz_fix');
file_put_contents($f, \x1f\x8b\x08\x00\x00\x00\x00\x00 . 
$data);
return file_get_contents('compress.zlib://' . $f);
}
On Nov 7, 2007 7:42 AM, Per Jessen [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

  They're exactly the same, except of the last 4 bytes. Python
  calculates them differently than PHP. PHP follows the standards,
  Python does not :]

 That is exactly what is so weird - does Python maybe have its own
 implementation of the gzip compression algorithm?   I would have
 thought they both used the same zlib.



 /Per Jessen, Zürich

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-06 Thread Per Jessen
Casey wrote:

 When I try gzuncompress() on the same data (I checked), it returns a
 Data error. I also tried gzinflate() and many user-created gzdecode
 () functions, with no luck.

Did you specify a correct length for gzuncompress() ?

From the manpage:

The function will return an error if the uncompressed data is more than
the optional parameter length.


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-06 Thread heavyccasey
I left that empty. The decompressed string is about 224 KB, so it
shouldn't throw an error. Thanks for the reply!



On Nov 6, 2007 12:25 AM, Per Jessen [EMAIL PROTECTED] wrote:
 Casey wrote:

  When I try gzuncompress() on the same data (I checked), it returns a
  Data error. I also tried gzinflate() and many user-created gzdecode
  () functions, with no luck.

 Did you specify a correct length for gzuncompress() ?

 From the manpage:

 The function will return an error if the uncompressed data is more than
 the optional parameter length.


 /Per Jessen, Zürich

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-06 Thread heavyccasey
Alright, I think I know the problem.

PHP's gzuncompress uses the Adler-32 checksum at the end of the zlib,
while Python uses CRC32.

Why must you follow the standards, PHP!?

Does anyone know of any workaround?

On Nov 6, 2007 7:03 AM,  [EMAIL PROTECTED] wrote:
 I left that empty. The decompressed string is about 224 KB, so it
 shouldn't throw an error. Thanks for the reply!




 On Nov 6, 2007 12:25 AM, Per Jessen [EMAIL PROTECTED] wrote:
  Casey wrote:
 
   When I try gzuncompress() on the same data (I checked), it returns a
   Data error. I also tried gzinflate() and many user-created gzdecode
   () functions, with no luck.
 
  Did you specify a correct length for gzuncompress() ?
 
  From the manpage:
 
  The function will return an error if the uncompressed data is more than
  the optional parameter length.
 
 
  /Per Jessen, Zürich
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-06 Thread Per Jessen
[EMAIL PROTECTED] wrote:

 Alright, I think I know the problem.
 
 PHP's gzuncompress uses the Adler-32 checksum at the end of the zlib,
 while Python uses CRC32.
 
 Why must you follow the standards, PHP!?
 
 Does anyone know of any workaround?

Are you saying that you've got compressed data in one format by Python
that cannot be uncompressed by PHP because it expects another format?   


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gzuncompress() Not Working.

2007-11-06 Thread heavyccasey
The documentation for zlib says that it expects an Adler-32 checksum
at the end of the file.

PHP follows this [largely outdated] standard.

Python, on the other hand, doesn't, and uses a different checksum, CRC-32.

That's why it won't decompress. But I've written my own function and
it's working now. :)
function fixAdler32($data) {
$tempnam = tempnam('/tmp', 'gzfix');
$fh = fopen($tempnam, 'wb');

fwrite($fh, \x1f\x8b\x08\x00\x00\x00\x00\x00 . $data);
fclose($fh);

$dat = '';
$gz = gzopen($tempnam, 'rb');
if ($gz == false) die('Error opening temporary GZ file.');

do {
$dat .= gzread($gz, 10);
} while (!feof($gz));
gzclose($gz);
unlink($tempnam);
return $dat;
}


On Nov 6, 2007 11:07 PM, Per Jessen [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

  Alright, I think I know the problem.
 
  PHP's gzuncompress uses the Adler-32 checksum at the end of the zlib,
  while Python uses CRC32.
 
  Why must you follow the standards, PHP!?
 
  Does anyone know of any workaround?

 Are you saying that you've got compressed data in one format by Python
 that cannot be uncompressed by PHP because it expects another format?



 /Per Jessen, Zürich

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] gzuncompress() Not Working.

2007-11-05 Thread Casey


Hello, list!

I'm trying to translate some code from Python to PHP so it will work  
on my server.


The Python code is:
x = zlib.decompressobj()
x.decompress(blah) # blah is a 100KB string

When I try gzuncompress() on the same data (I checked), it returns a  
Data error. I also tried gzinflate() and many user-created gzdecode 
() functions, with no luck.


After many hours of Googling and test scripts, I have found little  
information.


I think the problem could be a memory problem. When I try to  
decompress a shorter string, it works perfectly.


The data fed to the decompression function is the same and therefore  
should be valid.


When I looked at the user comments for gzuncompress(), it says that it  
might not decompress some zlib data.


Any ideas to how to fix this problem?

Thanks,
Casey

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php