php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16232 remalloc FAIL on CURLOPT_HEADERFUNCTION callback
Submitted: 2002-03-23 10:11 UTC Modified: 2002-03-24 05:42 UTC
From: alan at akbkhome dot com Assigned:
Status: Closed Package: cURL related
PHP Version: 4.0CVS-2002-03-23 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alan at akbkhome dot com
New email:
PHP Version: OS:

 

 [2002-03-23 10:11 UTC] alan at akbkhome dot com
Fixes:
callback to curl_setopt(CURLOPT_HEADERFUNCTION..) always causes this.
FATAL:  erealloc():  Unable to allocate 1075529781 bytes

Fix:
Basically a copy of the curl_write to curl_write_header

Affects: 
all versions (that I know of - including 4.2.0rc1 & 4.2.0-dev)

test code at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpmole-ide/phpmole/tools/web_get.php?rev=1.2&content-type=text/vnd.viewcvs-markup

usage:
php web_get.php http://www.php.net
 




Index: curl.c
===================================================================
RCS file: /repository/php4/ext/curl/curl.c,v
retrieving revision 1.103
diff -u -r1.103 curl.c
--- curl.c	24 Dec 2001 13:58:03 -0000	1.103
+++ curl.c	23 Mar 2002 14:57:05 -0000
@@ -319,7 +319,7 @@
 
 		ZVAL_RESOURCE(argv[0], ch->id);
 		zend_list_addref(ch->id);
-		ZVAL_STRINGL(argv[1], data, (int) length, 1);
+		ZVAL_STRINGL(argv[1], data, length, 1);
 
 		error = call_user_function(EG(function_table),
 		                           NULL,
@@ -373,7 +373,7 @@
 		zend_list_addref(ch->id);
 		ZVAL_RESOURCE(argv[1], t->fd);
 		zend_list_addref(t->fd);
-		ZVAL_LONG(argv[2], size * nmemb);
+		ZVAL_LONG(argv[2], (int) size * nmemb);
 
 		error = call_user_function(EG(function_table),
 		                           NULL,
@@ -406,8 +406,7 @@
 {
 	php_curl       *ch  = (php_curl *) ctx;
 	php_curl_write *t   = ch->handlers->write_header;
-	int             error;
-	int             length;
+	size_t          length = size * nmemb;
 	TSRMLS_FETCH();
 	
 	switch (t->method) {
@@ -415,33 +414,30 @@
 		/* Handle special case write when we're returning the entire transfer
 		 */
 		if (ch->handlers->write->method == PHP_CURL_RETURN)
-			smart_str_appendl(&ch->handlers->write->buf, data, size * nmemb);
+			smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
 		else
 			PUTS(data);
-
-		length = size * nmemb;
-
 		break;
 	case PHP_CURL_FILE:
-		length = fwrite(data, size, nmemb, t->fp);
-		break;
+		return fwrite(data, size, nmemb, t->fp);
 	case PHP_CURL_USER: {
 		zval *argv[2];
 		zval *retval;
+		int   error;
 		TSRMLS_FETCH();
-	
+
 		MAKE_STD_ZVAL(argv[0]);
 		MAKE_STD_ZVAL(argv[1]);
 		MAKE_STD_ZVAL(retval);
 
 		ZVAL_RESOURCE(argv[0], ch->id);
 		zend_list_addref(ch->id);
-		ZVAL_STRINGL(argv[0], data, size * nmemb, 1);
+		ZVAL_STRINGL(argv[1], data, length, 1);
 
-		error = call_user_function(EG(function_table), 
-	    	                       NULL,
+		error = call_user_function(EG(function_table),
+		                           NULL,
 		                           t->func,
-	        	                   retval, 2, argv TSRMLS_CC);
+		                           retval, 2, argv TSRMLS_CC);
 		if (error == FAILURE) {
 			php_error(E_WARNING, "Couldn't call the CURLOPT_HEADERFUNCTION");
 			length = -1;
@@ -449,17 +445,14 @@
 		else {
 			length = Z_LVAL_P(retval);
 		}
-
 		zval_ptr_dtor(&argv[0]);
 		zval_ptr_dtor(&argv[1]);
 		zval_ptr_dtor(&retval);
 		break;
 	}
 	case PHP_CURL_IGNORE:
-		length = size * nmemb;
-		break;
-	}
-	
+		return length;
+    	}
 	return length;
 }
 /* }}} */

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-23 18:16 UTC] derick@php.net
Hey Alan,

can you please mail this patch to php-dev?

regards,
Derick
 [2002-03-24 05:42 UTC] derick@php.net
Fixed in CVS. Thanks!

Derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 10:01:28 2025 UTC