cvs: php4 /ext/zlib zlib.c /ext/zlib/tests 001.phpt 002.phpt 003.phpt
| From: | Thies C. Arntzen | Date: | Fri, 13 Jul 2001 15:48:37 +0000 |
| Subject: | cvs: php4 /ext/zlib zlib.c /ext/zlib/tests 001.phpt 002.phpt 003.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-6210@lists.php.net to get a copy of this message | ||
thies Fri Jul 13 11:48:37 2001 EDT
Added files:
/php4/ext/zlib/tests 001.phpt 002.phpt 003.phpt
Modified files:
/php4/ext/zlib zlib.c
Log:
make sure all string from zlib are \0 terminated.
change one realloc to erealloc (though this code is never reached IMHO)
add regression tests
Index: php4/ext/zlib/zlib.c
diff -u php4/ext/zlib/zlib.c:1.82 php4/ext/zlib/zlib.c:1.83
--- php4/ext/zlib/zlib.c:1.82 Fri Jul 13 11:19:17 2001
+++ php4/ext/zlib/zlib.c Fri Jul 13 11:48:37 2001
@@ -16,7 +16,7 @@
| Stefan Röhrich <sr@linux.de> |
+----------------------------------------------------------------------+
*/
-/* $Id: zlib.c,v 1.82 2001/07/13 15:19:17 thies Exp $ */
+/* $Id: zlib.c,v 1.83 2001/07/13 15:48:37 thies Exp $ */
#define IS_EXT_MODULE
#ifdef HAVE_CONFIG_H
@@ -760,7 +760,7 @@
}
convert_to_string_ex(data);
- l2 = (*data)->value.str.len + ((*data)->value.str.len/1000) + 15;
+ l2 = (*data)->value.str.len + ((*data)->value.str.len/1000) + 15 + 1; /* room for \0 */
s2 = (char *) emalloc(l2);
if(! s2) RETURN_FALSE;
@@ -770,7 +770,9 @@
status = compress(s2,&l2,(*data)->value.str.val, (*data)->value.str.len);
}
- if(status==Z_OK) {
+ if (status==Z_OK) {
+ s2 = erealloc(s2,l2 + 1);
+ s2[l2] = '\0';
RETURN_STRINGL(s2, l2, 0);
} else {
efree(s2);
@@ -785,7 +787,7 @@
PHP_FUNCTION(gzuncompress)
{
zval **data, **zlimit = NULL;
- int status,factor=1,maxfactor=8;
+ int status,factor=1,maxfactor=16;
unsigned long plength=0,length;
char *s1=NULL,*s2=NULL;
@@ -825,8 +827,9 @@
s1=s2;
} while((status==Z_BUF_ERROR)&&(!plength)&&(factor<maxfactor));
- if(status==Z_OK) {
- s2 = erealloc(s2, length);
+ if (status==Z_OK) {
+ s2 = erealloc(s2, length + 1); /* space for \0 */
+ s2[ length ] = '\0';
RETURN_STRINGL(s2, length, 0);
} else {
efree(s2);
@@ -1014,7 +1017,7 @@
prev_outlen = outlen;
outlen *= 3;
if ((outlen+start_offset+end_offset) > *p_buffer_len) {
- buffer = realloc(buffer, outlen+start_offset+end_offset);
+ buffer = erealloc(buffer, outlen+start_offset+end_offset);
}
ZLIBG(stream).next_out = buffer+start_offset + prev_outlen;
Index: php4/ext/zlib/tests/001.phpt
+++ php4/ext/zlib/tests/001.phpt
--TEST--
gzdeflate()/gzinflate()
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--POST--
--GET--
--FILE--
<?php
$original = str_repeat("hallo php",4096);
$packed=gzdeflate($original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzinflate($packed);
if (strcmp($original,$unpacked)==0) echo "Strings are equal";
?>
--EXPECT--
100 36864
Strings are equal
Index: php4/ext/zlib/tests/002.phpt
+++ php4/ext/zlib/tests/002.phpt
--TEST--
gzcompress()/gzuncompress()
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--POST--
--GET--
--FILE--
<?php
$original = str_repeat("hallo php",4096);
$packed=gzcompress($original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzuncompress($packed);
if (strcmp($original,$unpacked)==0) echo "Strings are equal";
?>
--EXPECT--
106 36864
Strings are equal
Index: php4/ext/zlib/tests/003.phpt
+++ php4/ext/zlib/tests/003.phpt
--TEST--
gzdeflate()/gzinflate()
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--POST--
--GET--
--FILE--
<?php
$original = str_repeat("hallo php",4096);
$packed=gzencode($original);
echo strlen($packed)." ".strlen($original)."\n";
if
(strcmp(base64_encode($packed),"H4sIAAAAAAAAA+zGoQ0AQAgEsFV+NdwJEthf/R6kVU11z9tsRERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERETu5gMAAP//AwDlQAe9AJAAAA==")==0)
echo "Strings are equal";
?>
--EXPECT--
124 36864
Strings are equal